Skip to content

Math API (hyperion.math.*)

Constructors and helpers

Function Return Throws Description
hyperion.math.vec2(x, y) Vec2 No Create a 2D vector.
hyperion.math.vec3(x, y, z) Vec3 No Create a 3D vector.
hyperion.math.degToRad(deg) number No Convert degrees to radians.
hyperion.math.radToDeg(rad) number No Convert radians to degrees.
hyperion.math.lerp(a, b, t) number No Linear interpolation.
hyperion.math.clamp(val, min, max) number No Clamp a value to a range.
hyperion.math.distance(v1, v2) number No Distance between two Vec3.
hyperion.math.distance2D(v1, v2) number No 2D distance between two Vec3.

Vec2 methods and fields

Method or field Return Throws Description
vec2.x, vec2.y number No Components (read/write).
vec2:length() number No Vector length.
vec2:squaredLength() number No Squared length.
vec2:normalize() void No Normalize in place.
vec2:normalized() Vec2 No Return normalized copy.
vec2:distance(other) number No Distance to another Vec2.
vec2:dot(other) number No Dot product.

Supported operators: vec2 + vec2, vec2 - vec2, vec2 * scalar.

Vec3 methods and fields

Method or field Return Throws Description
vec3.x, vec3.y, vec3.z number No Components (read/write).
vec3:length() number No Vector length.
vec3:length2D() number No 2D length (x, y).
vec3:squaredLength() number No Squared length.
vec3:normalize() void No Normalize in place.
vec3:normalized() Vec3 No Return normalized copy.
vec3:distance(other) number No Distance to another Vec3.
vec3:dot(other) number No Dot product.
vec3:cross(other) Vec3 No Cross product.

Supported operators: vec3 + vec3, vec3 - vec3, vec3 * scalar.