Pure maths on plain tables. A vec2 is any table with numeric x, y; a vec3 adds z; a rect is { origin = vec2, size = vec2 }. Most functions take vec2 or vec3 and return the matching shape.
| Function |
Signature |
Returns |
vector.deg_to_rad |
(degrees: number) |
radians |
vector.rad_to_deg |
(radians: number) |
degrees |
vector.wrap_pi |
(radians: number) |
radians folded to [-pi, pi] |
vector.angle_delta |
(from: number, to: number) |
signed shortest angle |
vector.round4 |
(value: number) |
value rounded to 4 dp |
vector.abs |
(value) |
absolute value (number, vec2 or vec3) |
| Function |
Signature |
Returns |
vector.length |
(value) |
magnitude |
vector.length_squared |
(value) |
magnitude squared |
vector.distance |
(a, b) |
distance between two points |
vector.distance_squared |
(a, b) |
distance squared |
vector.dot |
(a, b) |
dot product |
vector.cross |
(a, b) |
cross product (number for vec2, vec3 for vec3) |
| Function |
Signature |
Returns |
vector.normalize |
(value) |
unit vector |
vector.perpendicular |
(value: vec2) |
perpendicular vec2 |
vector.rotated |
(value: vec2, radians: number) |
rotated vec2 |
vector.angle_of |
(value: vec2) |
angle of a vec2 |
vector.from_angle |
(radians[, magnitude]) |
vec2 from an angle |
vector.lerp |
(from, to, ratio: number) |
interpolated point |
vector.reflect |
(value, unit_normal) |
reflected vector |
vector.project |
(value, onto) |
projection |
vector.min / vector.max |
(a, b) |
component-wise min / max |
| Function |
Signature |
Returns |
vector.is_zero |
(value[, tolerance]) |
boolean |
vector.approx_equal |
(a, b[, tolerance]) |
boolean |
vector.intersection |
(first: rect, second: rect) |
overlapping rect |
vector.inset |
(value: rect, by: number) |
shrunk rect |