Skip to content

luxe API (2025.1.2)


luxe: math module


Math

import "luxe: math" for Math

Utility class with static math functions.


Math.add(a: Vec, b: Vec) returns unknown

Add two 3D vectors together componentwise, returning the result

Math.add2D(a: Vec, b: Vec) returns unknown

Add two vector2s together componentwise, returning the result

Math.add_to(a: Vec, b: Vec) returns unknown

Add two 3D vectors together componentwise, updating the first vector

Math.add2D_to(a: Vec, b: Vec) returns unknown

Add two 2D vectors together componentwise, updating the first vector

Math.sub(a: Vec, b: Vec) returns unknown

Subtract two 3D vectors together componentwise, returning the result

Math.sub2D(a: Vec, b: Vec) returns unknown

Subtract two 2D vectors together componentwise, returning the result

Math.sub_to(a: Vec, b: Vec) returns unknown

Subtract two 3D vectors together componentwise, updating the first vector

Math.sub2D_to(a: Vec, b: Vec) returns unknown

Subtract two 2D vectors together componentwise, updating the first vector

Math.mults(a: Vec, b: Num) returns unknown

Multiply a 3D vector by a scalar, returning the result

Math.mult(a: Vec, b: Vec) returns unknown

Multiply two 3D vectors together componentwise, returning the result

Math.mult2D(a: Vec, b: Vec) returns unknown

Multiply two 2D vectors together componentwise, returning the result

Math.mult_to(a: Vec, b: Vec) returns unknown

Multiply two 3D vectors together componentwise, updating the first vector

Math.mults_to(a: Vec, b: Num) returns unknown

Multiply a 3D vector by a scalar, updating the vector

Math.mult2D_to(a: Vec, b: Vec) returns unknown

Multiply two 2D vectors together componentwise, updating the first vector

Math.scale(a: Vec, s: Num) returns unknown

Multiply a 3D vector by a scalar, returning the result

Math.scale2D(a: Vec, s: Num) returns unknown

Multiply a 2D vector by a scalar, returning the result

Math.scale_to(a: Vec, s: Num) returns unknown

Multiply a 3D vector by a scalar, updating the vector

Math.scale2D_to(a: Vec, s: Num) returns unknown

Multiply a 2D vector by a scalar, updating the vector

Math.divide(a: Vec, b: Vec) returns unknown

Divide a 3D vector by another, returning the result

Math.divide_to(vec: Vec, other: Vec) returns unknown

Divide a 3D vector by another, updating the vector

Math.div(a: Vec, s: Num) returns unknown

Divide a 3D vector by a scalar, returning the result

Math.div2D(a: Vec, s: Num) returns unknown

Divide a 2D vector by a scalar, returning the result

Math.div_to(a: Vec, s: Num) returns unknown

Divide a 3D vector by a scalar, updating the vector

Math.div2D_to(a: Vec, s: Num) returns unknown

Divide a 2D vector by a scalar, updating the vector

Math.equal(a: Vec, b: Vec) returns Bool

Checks if two vectors are equal. Vectors of different dimensions (e.g. 2D and 3D) are considered unequal

Math.length(x: Num, y: Num) returns Num

Length of a 2d vector.

Math.length(x: Num, y: Num, z: Num) returns Num

Length of a 3d vector.

Math.length(vec: Vec) returns Num

Length of a 3d vector.

Math.length2D(vec: Vec) returns Num

Length of a 2d vector.

Math.length_sq(x: Num, y: Num) returns Num

Squared length of a 2d vector (slightly cheaper than length).

Math.length_sq(x: Num, y: Num, z: Num) returns Num

Squared length of a 3d vector (slightly cheaper than length).

Math.length_sq(vec: Vec) returns Num

Squared length of a 3d vector.

Math.length_sq2D(vec: Vec) returns Num

Squared length of a 2d vector.

Math.dot(x: Num, y: Num, z: Num, other_x: Num, other_y: Num, other_z: Num) returns Num

Dot product (or scalar product) of two 3d vectors.

Math.dot(x: Num, y: Num, other_x: Num, other_y: Num) returns Num

Dot product (or scalar product) of two 2d vectors.

Math.dot(vec: Vec, other: Vec) returns Num

Dot product (or scalar product) of two 3d vectors.

Math.dot2D(vec: Vec, other: Vec) returns Num

Dot product (or scalar product) of two 2d vectors.

Math.cross(a: Vec, b: Vec) returns Vec

Cross product of two 3d vectors. Result will always be orthogonal to both input vectors (and [0, 0, 0] if the arguments are parallel)

Math.angle(from: Vec, to: Vec) returns Num

Unsigned angle between two 3d vectors.

Math.angle(v1: Vec, v2: Vec, up: Vec) returns Num

Signed angle between two 3d vectors.

Math.angle2D(from: Vec, to: Vec) returns Num

Signed angle between two 2d vectors.

Math.angle2D(from_x: Num, from_y: Num, to_x: Num, to_y: Num) returns Num

Signed angle between two 2d vectors.

Math.normalize2D(vec: Vec) returns None

Normalize 2d vector. Changes input vector and doesnt return anything. 0 length vectors remain untouched.

Math.normalized(vec: Vec) returns None

Normalize 3d vector. Returns the result.

Math.normalized2D(vec: Vec) returns None

Normalize 2d vector. Returns the result.

Math.normalize(vec: Vec) returns None

Normalize 3d vector. Changes input vector and doesnt return anything. 0 length vectors remain untouched.

Math.dist(x: Num, y: Num, z: Num, other_x: Num, other_y: Num, other_z: Num) returns Num

Distance between two 3d vectors.

Math.dist(vec: Vec, other: Vec) returns Num

Distance between two 3d vectors.

Math.dist2D(vec: Vec, other: Vec) returns Num

Distance between two 2d vectors.

Math.dist2D(x: Num, y: Num, other_x: Num, other_y: Num) returns Num

Distance between two 2d vectors.

Math.dir2D(pos: Vec, target: Vec) returns Vec

Directional vector (length 1 unless the arguments are the same) between two 2d vectors.

Math.dir(pos: Vec, target: Vec) returns Vec

Directional vector (length 1 unless the arguments are the same) between two 3d vectors.

Math.rotate(vec: Vec, axis: Vec, angle: Num) returns Vec

Rotate a 3d vector around the given axis by angle degrees

Math.rotate_by_quat(vec: Vec, quat: Float4) returns Vec

Rotate a 3d vector using the given quaternion

Math.quat_from_euler(vec: Vec) returns Float4

Create a quaternion from float3 euler (radians)

Math.rotate(vec: Vec, ox: Num, oy: Num, angle: Num) returns None

Rotate 2d vector around another 2d vector. This rotates the input vector and doesnt return anything.

Math.ray_intersect_plane(plane_x: Num, plane_y: Num, plane_z: Num, normal_x: Num, normal_y: Num, normal_z: Num, ray_x: Num, ray_y: Num, ray_z: Num, ray_dir_x: Num, ray_dir_y: Num, ray_dir_z: Num) returns Vec

Intersection point between an infinitely long ray and a infinitely big plane. Returns null if parallel.

Math.closest_point_on_plane(plane_x: Num, plane_y: Num, plane_z: Num, normal_x: Num, normal_y: Num, normal_z: Num, point_x: Num, point_y: Num, point_z: Num) returns Vec

Closest point on an infinite plane to a point.

Math.closest_point_on_line(line_x: Num, line_y: Num, line_z: Num, line_end_x: Num, line_end_y: Num, line_end_z: Num, point_x: Num, point_y: Num, point_z: Num) returns Vec

Closest point on an infinite line to a point. The progress from line start to line end in 4th component of return value. Line is constructed by 2 points on the line, but the closest point can also be before the start of after the end (in that case the 4th component of the return value wont be in the 0-1 range).

Math.closest_point_on_line(line: Vec, line_end: Vec, point: Vec) returns Vec

Closest point on an infinite line to a point. The progress from line start to line end in 4th component of return value. Line is constructed by 2 points on the line, but the closest point can also be before the start of after the end (in that case the 4th component of the return value wont be in the 0-1 range).

Math.in_rect(x: Num, y: Num, rx: Num, ry: Num, rw: Num, rh: Num) returns Bool

Checks if a 2d point is inside a rectangle. Only works for positive rectangle sizes.

Math.wrap(value: Num, modulus: Num) returns Num

no docs found

Math.overlaps(x0: Num, y0: Num, w0: Num, h0: Num, x1: Num, y1: Num, w1: Num, h1: Num) returns Bool

Checks if two rectangles overlap. Only works for positive rectangle sizes.

Math.sign(x: Num) returns Num

The sign of the number, expressed as a -1, 1 or 0, for negative and positive numbers, and zero.

Math.sign0(x: Num) returns Num

The sign of the number, expressed as a -1 0r 1, for negative and positive numbers, zero is positive.

Math.atan2(y: Num, x: Num) returns Num

The arc tangent of y when divided by x, using the signs of the two numbers to determine the quadrant of the result. (equivalient to y.atan(x))

Math.degrees(radians: Num) returns Num

Convert radians (0...2*PI) to degree (0...360).

Math.radians(degrees: Num) returns Num

Convert degree (0...360) to radians (0...2*PI).

Math.clamp(value: Num, a: Num, b: Num) returns Num

Clamp value between a and b (result will never be smaller than a or bigger than b). Equivalent to value.clamp(a, b).

Math.min(a: Num, b: Num) returns Num

The smaller of two numbers. Eqivalent to a.min(b).

Math.max(a: Num, b: Num) returns Num

The larger of two numbers. Eqivalent to a.max(b).

Math.floor_around_zero(a: Num) returns Num

Round towards zero. (floor when positive, ceil when negative)

Math.ceil_around_zero(a: Num) returns Num

Round away from zero. (ceil when positive, floor when negative)

Math.fixed(value: Num) returns Num

Round number to 3 digits after comma precision.

Math.fixed(value: Num, precision: Num) returns Num

Round number to precision digits after comma precision.

Math.angle_delta(from: Num, to: Num) returns Num

Signed difference between two (degree) angles. Always in -180...180 range.

Math.lerp2D(a: Vec, b: Vec, t: Num) returns Vec

Linearly interpolate between two vectors. Returns a when t is 0 and b when t is 1, with values inbetween interpolating inbetween. If t is outside 0-1 range, the output will be extrapolated.

Math.lerp3D(a: Vec, b: Vec, t: Num) returns Vec

Linearly interpolate between two vectors. Returns a when t is 0 and b when t is 1, with values inbetween interpolating inbetween. If t is outside 0-1 range, the output will be extrapolated.

Math.smooth_t(t: Num, smoothness: Num) returns Num

Get a smooth time t for lerping, based on a smoothness value. e.g t = smooth_t(delta, 1.25). exponential decay

Math.smoother_t(t: Num, smoothness: Num) returns Num

Get a smooth time t for lerping, based on a smoothness value. e.g t = smoother_t(delta, 1.25). s curve like shape

Math.lerp(a: Num, b: Num, t: Num) returns Num

Linearly interpolate between two numbers. Returns a when t is 0 and b when t is 1, with values inbetween interpolating inbetween. If t is outside 0-1 range, the output will be extrapolated.

Math.lerp_angle(a: Num, b: Num, t: Num) returns Num

Interpolates between angles. Always in 0...360 range.

Math.weighted_avg(value: Num, target: Num, slowness: Num) returns unknown

no docs found

Math.within_range(value: Num, start_range: Num, end_range: Num) returns unknown

Checks whether value is inbetween start_range and end_range (inclusive).

Math.approx(one: Num, other: Num) returns Bool

Checks whether two values are approximately the same (with a max difference of 0.001).

Math.approx(one: Num, other: Num, epsilon: Num) returns Bool

Checks whether two values are approximately the same (with a max difference of epsilon).

Math.wrap_angle(degrees: Num) returns Num

Bring angle into 0...360 degree space.

Math.wrap_angle(degrees: Num, lower: Num, upper: Num) returns Num

Bring angle into lower...upper degree space.

Math.wrap_radians(radians: Num, lower: Num, upper: Num) returns Num

no docs found

Math.nearest_power_of_two(value: Num) returns Num

no docs found

Math.map_linear(value: Num, a1: Num, a2: Num, b1: Num, b2: Num) returns Num

Remap value from a1...a2 space to b1...b2 space (unclamped).

Math.smoothstep(x: Num, min: Num, max: Num) returns Num

Smoothed inverse lerp using cubic hermite interpolation. Output is clamped between 0 and 1.

Math.smootherstep(x: Num, min: Num, max: Num) returns Num

Alternate smooth inverse interpolation with derivative of 0 at min and max points. Output is clamped between 0 and 1.

Math.smoothstepx(x: Num, round: Num, steep: Num) returns unknown

no docs found

Math.random_point_in_unit_circle(rng: Random) returns Num

Random 2d point in circle of radius 1. Has uniform distribution.

Math.slerp(a: Quat, b: Quat, t: Num) returns unknown

no docs found