¶
luxe
API (2025.1.2
)¶
luxe: math
module¶
Math¶
import "luxe: math" for Math
Utility class with static math functions.
- add(a:
Vec
, b:Vec
) - add2D(a:
Vec
, b:Vec
) - add_to(a:
Vec
, b:Vec
) - add2D_to(a:
Vec
, b:Vec
) - sub(a:
Vec
, b:Vec
) - sub2D(a:
Vec
, b:Vec
) - sub_to(a:
Vec
, b:Vec
) - sub2D_to(a:
Vec
, b:Vec
) - mults(a:
Vec
, b:Num
) - mult(a:
Vec
, b:Vec
) - mult2D(a:
Vec
, b:Vec
) - mult_to(a:
Vec
, b:Vec
) - mults_to(a:
Vec
, b:Num
) - mult2D_to(a:
Vec
, b:Vec
) - scale(a:
Vec
, s:Num
) - scale2D(a:
Vec
, s:Num
) - scale_to(a:
Vec
, s:Num
) - scale2D_to(a:
Vec
, s:Num
) - divide(a:
Vec
, b:Vec
) - divide_to(vec:
Vec
, other:Vec
) - div(a:
Vec
, s:Num
) - div2D(a:
Vec
, s:Num
) - div_to(a:
Vec
, s:Num
) - div2D_to(a:
Vec
, s:Num
) - equal(a:
Vec
, b:Vec
) - length(x:
Num
, y:Num
) - length(x:
Num
, y:Num
, z:Num
) - length(vec:
Vec
) - length2D(vec:
Vec
) - length_sq(x:
Num
, y:Num
) - length_sq(x:
Num
, y:Num
, z:Num
) - length_sq(vec:
Vec
) - length_sq2D(vec:
Vec
) - dot(x:
Num
, y:Num
, z:Num
, other_x:Num
, other_y:Num
, other_z:Num
) - dot(x:
Num
, y:Num
, other_x:Num
, other_y:Num
) - dot(vec:
Vec
, other:Vec
) - dot2D(vec:
Vec
, other:Vec
) - cross(a:
Vec
, b:Vec
) - angle(from:
Vec
, to:Vec
) - angle(v1:
Vec
, v2:Vec
, up:Vec
) - angle2D(from:
Vec
, to:Vec
) - angle2D(from_x:
Num
, from_y:Num
, to_x:Num
, to_y:Num
) - normalize2D(vec:
Vec
) - normalized(vec:
Vec
) - normalized2D(vec:
Vec
) - normalize(vec:
Vec
) - dist(x:
Num
, y:Num
, z:Num
, other_x:Num
, other_y:Num
, other_z:Num
) - dist(vec:
Vec
, other:Vec
) - dist2D(vec:
Vec
, other:Vec
) - dist2D(x:
Num
, y:Num
, other_x:Num
, other_y:Num
) - dir2D(pos:
Vec
, target:Vec
) - dir(pos:
Vec
, target:Vec
) - rotate(vec:
Vec
, axis:Vec
, angle:Num
) - rotate_by_quat(vec:
Vec
, quat:Float4
) - quat_from_euler(vec:
Vec
) - rotate(vec:
Vec
, ox:Num
, oy:Num
, angle:Num
) - 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
) - 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
) - 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
) - closest_point_on_line(line:
Vec
, line_end:Vec
, point:Vec
) - in_rect(x:
Num
, y:Num
, rx:Num
, ry:Num
, rw:Num
, rh:Num
) - wrap(value:
Num
, modulus:Num
) - overlaps(x0:
Num
, y0:Num
, w0:Num
, h0:Num
, x1:Num
, y1:Num
, w1:Num
, h1:Num
) - sign(x:
Num
) - sign0(x:
Num
) - atan2(y:
Num
, x:Num
) - degrees(radians:
Num
) - radians(degrees:
Num
) - clamp(value:
Num
, a:Num
, b:Num
) - min(a:
Num
, b:Num
) - max(a:
Num
, b:Num
) - floor_around_zero(a:
Num
) - ceil_around_zero(a:
Num
) - fixed(value:
Num
) - fixed(value:
Num
, precision:Num
) - angle_delta(from:
Num
, to:Num
) - lerp2D(a:
Vec
, b:Vec
, t:Num
) - lerp3D(a:
Vec
, b:Vec
, t:Num
) - smooth_t(t:
Num
, smoothness:Num
) - smoother_t(t:
Num
, smoothness:Num
) - lerp(a:
Num
, b:Num
, t:Num
) - lerp_angle(a:
Num
, b:Num
, t:Num
) - weighted_avg(value:
Num
, target:Num
, slowness:Num
) - within_range(value:
Num
, start_range:Num
, end_range:Num
) - approx(one:
Num
, other:Num
) - approx(one:
Num
, other:Num
, epsilon:Num
) - wrap_angle(degrees:
Num
) - wrap_angle(degrees:
Num
, lower:Num
, upper:Num
) - wrap_radians(radians:
Num
, lower:Num
, upper:Num
) - nearest_power_of_two(value:
Num
) - map_linear(value:
Num
, a1:Num
, a2:Num
, b1:Num
, b2:Num
) - smoothstep(x:
Num
, min:Num
, max:Num
) - smootherstep(x:
Num
, min:Num
, max:Num
) - smoothstepx(x:
Num
, round:Num
, steep:Num
) - random_point_in_unit_circle(rng:
Random
) - slerp(a:
Quat
, b:Quat
, t:Num
)
Vec
, b: Vec
)
¶unknown
Add two 3D vectors together componentwise, returning the result
Vec
, b: Vec
)
¶unknown
Add two vector2s together componentwise, returning the result
Vec
, b: Vec
)
¶unknown
Add two 3D vectors together componentwise, updating the first vector
Vec
, b: Vec
)
¶unknown
Add two 2D vectors together componentwise, updating the first vector
Vec
, b: Vec
)
¶unknown
Subtract two 3D vectors together componentwise, returning the result
Vec
, b: Vec
)
¶unknown
Subtract two 2D vectors together componentwise, returning the result
Vec
, b: Vec
)
¶unknown
Subtract two 3D vectors together componentwise, updating the first vector
Vec
, b: Vec
)
¶unknown
Subtract two 2D vectors together componentwise, updating the first vector
Vec
, b: Num
)
¶unknown
Multiply a 3D vector by a scalar, returning the result
Vec
, b: Vec
)
¶unknown
Multiply two 3D vectors together componentwise, returning the result
Vec
, b: Vec
)
¶unknown
Multiply two 2D vectors together componentwise, returning the result
Vec
, b: Vec
)
¶unknown
Multiply two 3D vectors together componentwise, updating the first vector
Vec
, b: Num
)
¶unknown
Multiply a 3D vector by a scalar, updating the vector
Vec
, b: Vec
)
¶unknown
Multiply two 2D vectors together componentwise, updating the first vector
Vec
, s: Num
)
¶unknown
Multiply a 3D vector by a scalar, returning the result
Vec
, s: Num
)
¶unknown
Multiply a 2D vector by a scalar, returning the result
Vec
, s: Num
)
¶unknown
Multiply a 3D vector by a scalar, updating the vector
Vec
, s: Num
)
¶unknown
Multiply a 2D vector by a scalar, updating the vector
Vec
, b: Vec
)
¶unknown
Divide a 3D vector by another, returning the result
Vec
, other: Vec
)
¶unknown
Divide a 3D vector by another, updating the vector
Vec
, s: Num
)
¶unknown
Divide a 3D vector by a scalar, returning the result
Vec
, s: Num
)
¶unknown
Divide a 2D vector by a scalar, returning the result
Vec
, s: Num
)
¶unknown
Divide a 3D vector by a scalar, updating the vector
Vec
, s: Num
)
¶unknown
Divide a 2D vector by a scalar, updating the vector
Vec
, b: Vec
)
¶Bool
Checks if two vectors are equal. Vectors of different dimensions (e.g. 2D and 3D) are considered unequal
Num
, y: Num
)
¶Num
Length of a 2d vector.
Num
, y: Num
, z: Num
)
¶Num
Length of a 3d vector.
Vec
)
¶Num
Length of a 3d vector.
Vec
)
¶Num
Length of a 2d vector.
Num
, y: Num
)
¶Num
Squared length of a 2d vector (slightly cheaper than length).
Num
, y: Num
, z: Num
)
¶Num
Squared length of a 3d vector (slightly cheaper than length).
Vec
)
¶Num
Squared length of a 3d vector.
Vec
)
¶Num
Squared length of a 2d vector.
Num
, y: Num
, z: Num
, other_x: Num
, other_y: Num
, other_z: Num
)
¶Num
Dot product (or scalar product) of two 3d vectors.
Num
, y: Num
, other_x: Num
, other_y: Num
)
¶Num
Dot product (or scalar product) of two 2d vectors.
Vec
, other: Vec
)
¶Num
Dot product (or scalar product) of two 3d vectors.
Vec
, other: Vec
)
¶Num
Dot product (or scalar product) of two 2d vectors.
Vec
, b: Vec
)
¶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)
Vec
, to: Vec
)
¶Num
Unsigned angle between two 3d vectors.
Vec
, v2: Vec
, up: Vec
)
¶Num
Signed angle between two 3d vectors.
Vec
, to: Vec
)
¶Num
Signed angle between two 2d vectors.
Num
, from_y: Num
, to_x: Num
, to_y: Num
)
¶Num
Signed angle between two 2d vectors.
Vec
)
¶None
Normalize 2d vector. Changes input vector and doesnt return anything. 0 length vectors remain untouched.
Vec
)
¶None
Normalize 3d vector. Returns the result.
Vec
)
¶None
Normalize 2d vector. Returns the result.
Vec
)
¶None
Normalize 3d vector. Changes input vector and doesnt return anything. 0 length vectors remain untouched.
Num
, y: Num
, z: Num
, other_x: Num
, other_y: Num
, other_z: Num
)
¶Num
Distance between two 3d vectors.
Vec
, other: Vec
)
¶Num
Distance between two 3d vectors.
Vec
, other: Vec
)
¶Num
Distance between two 2d vectors.
Num
, y: Num
, other_x: Num
, other_y: Num
)
¶Num
Distance between two 2d vectors.
Vec
, target: Vec
)
¶Vec
Directional vector (length 1 unless the arguments are the same) between two 2d vectors.
Vec
, target: Vec
)
¶Vec
Directional vector (length 1 unless the arguments are the same) between two 3d vectors.
Vec
, axis: Vec
, angle: Num
)
¶Vec
Rotate a 3d vector around the given axis by angle degrees
Vec
, quat: Float4
)
¶Vec
Rotate a 3d vector using the given quaternion
Vec
)
¶Float4
Create a quaternion from float3 euler (radians)
Vec
, ox: Num
, oy: Num
, angle: Num
)
¶None
Rotate 2d vector around another 2d vector. This rotates the input vector and doesnt return anything.
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
)
¶Vec
Intersection point between an infinitely long ray and a infinitely big plane. Returns
null
if parallel.
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
)
¶Vec
Closest point on an infinite plane to a point.
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
)
¶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).
Vec
, line_end: Vec
, point: Vec
)
¶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).
Num
, y: Num
, rx: Num
, ry: Num
, rw: Num
, rh: Num
)
¶Bool
Checks if a 2d point is inside a rectangle. Only works for positive rectangle sizes.
Num
, modulus: Num
)
¶Num
no docs found
Num
, y0: Num
, w0: Num
, h0: Num
, x1: Num
, y1: Num
, w1: Num
, h1: Num
)
¶Bool
Checks if two rectangles overlap. Only works for positive rectangle sizes.
Num
)
¶Num
The sign of the number, expressed as a -1, 1 or 0, for negative and positive numbers, and zero.
Num
)
¶Num
The sign of the number, expressed as a -1 0r 1, for negative and positive numbers, zero is positive.
Num
, x: Num
)
¶Num
The arc tangent of
y
when divided byx
, using the signs of the two numbers to determine the quadrant of the result. (equivalient toy.atan(x)
)
Num
)
¶Num
Convert radians (0...2*PI) to degree (0...360).
Num
)
¶Num
Convert degree (0...360) to radians (0...2*PI).
Num
, a: Num
, b: Num
)
¶Num
Clamp
value
betweena
andb
(result will never be smaller than a or bigger than b). Equivalent tovalue.clamp(a, b)
.
Num
, b: Num
)
¶Num
The smaller of two numbers. Eqivalent to
a.min(b)
.
Num
, b: Num
)
¶Num
The larger of two numbers. Eqivalent to
a.max(b)
.
Num
)
¶Num
Round towards zero. (floor when positive, ceil when negative)
Num
)
¶Num
Round away from zero. (ceil when positive, floor when negative)
Num
)
¶Num
Round number to 3 digits after comma precision.
Num
, precision: Num
)
¶Num
Round number to
precision
digits after comma precision.
Num
, to: Num
)
¶Num
Signed difference between two (degree) angles. Always in -180...180 range.
Vec
, b: Vec
, t: Num
)
¶Vec
Linearly interpolate between two vectors. Returns
a
whent
is0
andb
whent
is1
, with values inbetween interpolating inbetween. Ift
is outside 0-1 range, the output will be extrapolated.
Vec
, b: Vec
, t: Num
)
¶Vec
Linearly interpolate between two vectors. Returns
a
whent
is0
andb
whent
is1
, with values inbetween interpolating inbetween. Ift
is outside 0-1 range, the output will be extrapolated.
Num
, smoothness: Num
)
¶Num
Get a smooth time t for lerping, based on a smoothness value. e.g t = smooth_t(delta, 1.25). exponential decay
Num
, smoothness: Num
)
¶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
Num
, b: Num
, t: Num
)
¶Num
Linearly interpolate between two numbers. Returns
a
whent
is0
andb
whent
is1
, with values inbetween interpolating inbetween. Ift
is outside 0-1 range, the output will be extrapolated.
Num
, b: Num
, t: Num
)
¶Num
Interpolates between angles. Always in 0...360 range.
Num
, target: Num
, slowness: Num
)
¶unknown
no docs found
Num
, start_range: Num
, end_range: Num
)
¶unknown
Checks whether
value
is inbetweenstart_range
andend_range
(inclusive).
Num
, other: Num
)
¶Bool
Checks whether two values are approximately the same (with a max difference of 0.001).
Num
, other: Num
, epsilon: Num
)
¶Bool
Checks whether two values are approximately the same (with a max difference of
epsilon
).
Num
)
¶Num
Bring angle into 0...360 degree space.
Num
, lower: Num
, upper: Num
)
¶Num
Bring angle into lower...upper degree space.
Num
, lower: Num
, upper: Num
)
¶Num
no docs found
Num
)
¶Num
no docs found
Num
, a1: Num
, a2: Num
, b1: Num
, b2: Num
)
¶Num
Remap value from
a1...a2
space tob1...b2
space (unclamped).
Num
, min: Num
, max: Num
)
¶Num
Smoothed inverse lerp using cubic hermite interpolation. Output is clamped between 0 and 1.
Num
, min: Num
, max: Num
)
¶Num
Alternate smooth inverse interpolation with derivative of 0 at min and max points. Output is clamped between 0 and 1.
Num
, round: Num
, steep: Num
)
¶unknown
no docs found
Random
)
¶Num
Random 2d point in circle of radius 1. Has uniform distribution.
Quat
, b: Quat
, t: Num
)
¶unknown
no docs found