On this page
tecs.math
Angle math and the two-dimensional geometry beneath it.
wrapAngle and deltaAngle operate on angles rather than vectors, so they remain directly on tecs.math. Vector and point operations live under tecs.math.vec2; native procedural fields live under tecs.math.noise.
local correction <const> = tecs.math.deltaAngle(
rotation, targetRotation
)
rotation = tecs.math.wrapAngle(rotation + correction * response)
local directionX, directionY = tecs.math.vec2.normalize(
targetX - x, targetY - y
)Every angle uses radians. Both functions return a value in [-pi, pi), so an exact positive half-turn becomes negative pi.
Naming tecs.math does not load either subordinate module. Reading vec2 or noise loads that child once and returns its module table.
Module contents
Submodules
| Submodule | Description |
|---|---|
tecs.math.noise |
Native procedural scalar fields with configurable algorithms and fractal composition |
tecs.math.vec2 |
Allocation-free two-dimensional vector and point operations over separate coordinates |
Functions
| Function | Kind | Description |
|---|---|---|
deltaAngle |
Static | Computes the shortest signed turn from one angle to another. |
wrapAngle |
Static | Wraps an angle to one turn centered on zero. |
Functions
tecs.math.deltaAngle Static
Computes the shortest signed turn from one angle to another.
function tecs.math.deltaAngle(from: number, to: number): numberArguments
| Name | Type | Description |
|---|---|---|
from |
number |
Starting angle in radians. |
to |
number |
Destination angle in radians. |
Returns
| Type | Description |
|---|---|
number |
to - from wrapped to [-pi, pi). An exact half-turn is negative pi. |
Examples
Finds the shortest turn toward a target rotation.
assert(tecs.math.deltaAngle(0, math.pi) == -math.pi)tecs.math.wrapAngle Static
Wraps an angle to one turn centered on zero.
function tecs.math.wrapAngle(radians: number): numberArguments
| Name | Type | Description |
|---|---|---|
radians |
number |
A finite angle in radians. |
Returns
| Type | Description |
|---|---|
number |
The equivalent angle in [-pi, pi), so positive pi becomes negative pi. |
Examples
Keeps a rotation within one turn before storing it.
assert(tecs.math.wrapAngle(math.pi) == -math.pi)