IS
isaac-mason/mathcat
a collection of math helpers for 3D graphics and simulations
> npm install mathcatmathcat
mathcat is a collection of math helpers for 3D graphics and simulations.
Features:
- Vector, Quaternion, Euler, and Matrix math
- Easing functions
- Randomness utilities
- Noise utilities
- Simple JSON-serializable data structures (no classes or typed arrays)
- TypeScript-first, great DX for both JavaScript and TypeScript projects
- Excellent tree-shaking support
Acknowledgements:
- The vec*, quat*, mat* code started as a typescript port of glMatrix (https://glmatrix.net/). This library doesn't aim to stay in sync with glMatrix however.
- Simplex noise functions are adapted from https://github.com/pmndrs/maath, which were adapted from https://github.com/josephg/noisejs :)
API Documentation
types
Vec2 | Vec3 | Vec4 | Quat |
Quat2 | Mat2 | Mat3 | Mat4 |
Mat2d | Box3 | OBB3 | EulerOrder |
Euler | Plane3 | Sphere | Circle |
Ray3 | Raycast3 | MutableArrayLike |
vec2
vec3
vec4
euler
euler.create | euler.fromValues | euler.set |
euler.fromDegrees | euler.fromRotationMat4 | euler.exactEquals |
euler.equals | euler.fromQuat | euler.reorder |
quat
quat2
mat2
mat2d
mat3
mat4
circle
circle.create |
segment2
segment2.closestPoint |
box3
obb3
obb3.create | obb3.clone |
obb3.copy | obb3.set |
obb3.setFromCenterHalfExtentsQuaternion | obb3.setFromBox3 |
obb3.containsPoint | obb3.clampPoint |
obb3.intersectsOBB3 | obb3.intersectsBox3 |
obb3.applyMatrix4 |
plane3
sphere
sphere.create |
triangle3
triangle3.bounds | triangle3.normal | triangle3.centroid |
raycast3
quickhull3
quickhull3 |
quickhull2
quickhull2 |
circumcircle
circumcircle |
easing
noise
NoiseGenerator2D | NoiseGenerator3D | createSimplex2D | createSimplex3D |
createPerlin2D | createPerlin3D |
random
createMulberry32Generator | generateMulberry32Seed |
randomInt | randomFloat |
randomBool | randomSign |
randomChoice | randomVec2 |
randomVec3 | randomVec4 |
randomQuat |
common
EPSILON | round | degreesToRadians | radiansToDegrees |
equals | fade | lerp | clamp |
remap | remapClamp |
Reference
types
Vec2
/** A 2D vector */
export type Vec2 = [
x: number,
y: number
];Vec3
/** A 3D vector */
export type Vec3 = [
x: number,
y: number,
z: number
];Vec4
/** A 4D vector */
export type Vec4 = [
x: number,
y: number,
z: number,
w: number
];Quat
/** A quaternion that represents rotation */
export type Quat = [
x: number,
y: number,
z: number,
w: number
];Quat2
/** A dual quaternion that represents both rotation and translation */
export type Quat2 = [
x: number,
y: number,
z: number,
w: number,
x2: number,
y2: number,
z2: number,
w2: number
];Mat2
/** A 2x2 matrix */
export type Mat2 = [
e1: number,
e2: number,
e3: number,
e4: number
];Mat3
/** A 3x3 matrix */
export type Mat3 = [
e1: number,
e2: number,
e3: number,
e4: number,
e5: number,
e6: number,
e7: number,
e8: number,
e9: number
];Mat4
/** A 4x4 matrix */
export type Mat4 = [
e1: number,
e2: number,
e3: number,
e4: number,
e5: number,
e6: number,
e7: number,
e8: number,
e9: number,
e10: number,
e11: number,
e12: number,
e13: number,
e14: number,
e15: number,
e16: number
];Mat2d
/** A 2D affine transform matrix */
export type Mat2d = [
e1: number,
e2: number,
e3: number,
e4: number,
e5: number,
e6: number
];Box3
/** A box in 3D space */
export type Box3 = [
minX: number,
minY: number,
minZ: number,
maxX: number,
maxY: number,
maxZ: number
];OBB3
/** A oriented bounding box in 3D space */
export type OBB3 = {
center: Vec3;
halfExtents: Vec3;
rotation: Mat3;
};EulerOrder
/** Euler orders */
export type EulerOrder = 'xyz' | 'xzy' | 'yxz' | 'yzx' | 'zxy' | 'zyx';Euler
/** A Euler in 3D space, with an optional order (default is 'xyz') */
export type Euler = [
x: number,
y: number,
z: number,
order?: EulerOrder
];Plane3
/**
* A plane in 3D space
* normal - a unit length vector defining the normal of the plane.
* constant - the signed distance from the origin to the plane.
*/
export type Plane3 = {
normal: Vec3;
constant: number;
};Sphere
/** A sphere in 3D space */
export type Sphere = {
center: Vec3;
radius: number;
};Circle
/** A circle in 2D space */
export type Circle = {
center: Vec2;
radius: number;
};Ray3
/** A ray in 3D space */
export type Ray3 = {
origin: Vec3;
direction: Vec3;
};Raycast3
/** A raycast in 3D space */
export type Raycast3 = {
origin: Vec3;
direction: Vec3;
length: number;
};MutableArrayLike
export type MutableArrayLike<T> = {
[index: number]: T;
length: number;
};vec2
vec2.create
/**
* Creates a new, empty vec2
*
* @returns a new 2D vector
*/
export function create(): Vec2;vec2.clone
/**
* Creates a new vec2 initialized with values from an existing vector
*
* @param a vector to clone
* @returns a new 2D vector
*/
export function clone(a: Vec2): Vec2;vec2.fromValues
/**
* Creates a new vec2 initialized with the given values
*
* @param x X component
* @param y Y component
* @returns a new 2D vector
*/
export function fromValues(x: number, y: number): Vec2;vec2.copy
/**
* Copy the values from one vec2 to another
*
* @param out the receiving vector
* @param a the source vector
* @returns out
*/
export function copy(out: Vec2, a: Vec2): Vec2;vec2.set
/**
* Set the components of a vec2 to the given values
*
* @param out the receiving vector
* @param x X component
* @param y Y component
* @returns out
*/
export function set(out: Vec2, x: number, y: number): Vec2;vec2.add
/**
* Adds two vec2's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function add(out: Vec2, a: Vec2, b: Vec2): Vec2;vec2.addScalar
/**
* Adds a scalar value to all components of a vec2
*
* @param out the receiving vector
* @param a the source vector
* @param b the scalar value to add
* @returns out
*/
export function addScalar(out: Vec2, a: Vec2, b: number): Vec2;vec2.subtract
/**
* Subtracts vector b from vector a
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function subtract(out: Vec2, a: Vec2, b: Vec2): Vec2;vec2.subtractScalar
/**
* Subtracts a scalar value from all components of a vec2
*
* @param out the receiving vector
* @param a the source vector
* @param b the scalar value to subtract
* @returns out
*/
export function subtractScalar(out: Vec2, a: Vec2, b: number): Vec2;vec2.multiply
/**
* Multiplies two vec2's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function multiply(out: Vec2, a: Vec2, b: Vec2): Vec2;vec2.divide
/**
* Divides two vec2's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function divide(out: Vec2, a: Vec2, b: Vec2): Vec2;vec2.ceil
/**
* Math.ceil the components of a vec2
*
* @param out the receiving vector
* @param a vector to ceil
* @returns out
*/
export function ceil(out: Vec2, a: Vec2): Vec2;vec2.floor
/**
* Math.floor the components of a vec2
*
* @param out the receiving vector
* @param a vector to floor
* @returns out
*/
export function floor(out: Vec2, a: Vec2): Vec2;vec2.min
/**
* Returns the minimum of two vec2's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function min(out: Vec2, a: Vec2, b: Vec2): Vec2;vec2.max
/**
* Returns the maximum of two vec2's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function max(out: Vec2, a: Vec2, b: Vec2): Vec2;vec2.round
/**
* symmetric round the components of a vec2
*
* @param out the receiving vector
* @param a vector to round
* @returns out
*/
export function round(out: Vec2, a: Vec2): Vec2;vec2.scale
/**
* Scales a vec2 by a scalar number
*
* @param out the receiving vector
* @param a the vector to scale
* @param b amount to scale the vector by
* @returns out
*/
export function scale(out: Vec2, a: Vec2, b: number): Vec2;vec2.scaleAndAdd
/**
* Adds two vec2's after scaling the second operand by a scalar value
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param scale the amount to scale b by before adding
* @returns out
*/
export function scaleAndAdd(out: Vec2, a: Vec2, b: Vec2, scale: number): Vec2;vec2.distance
/**
* Calculates the euclidian distance between two vec2's
*
* @param a the first operand
* @param b the second operand
* @returns distance between a and b
*/
export function distance(a: Vec2, b: Vec2): number;vec2.squaredDistance
/**
* Calculates the squared euclidian distance between two vec2's
*
* @param a the first operand
* @param b the second operand
* @returns squared distance between a and b
*/
export function squaredDistance(a: Vec2, b: Vec2): number;vec2.length
/**
* Calculates the length of a vec2
*
* @param a vector to calculate length of
* @returns length of a
*/
export function length(a: Vec2): number;vec2.squaredLength
/**
* Calculates the squared length of a vec2
*
* @param a vector to calculate squared length of
* @returns squared length of a
*/
export function squaredLength(a: Vec2): number;vec2.negate
/**
* Negates the components of a vec2
*
* @param out the receiving vector
* @param a vector to negate
* @returns out
*/
export function negate(out: Vec2, a: Vec2): Vec2;vec2.inverse
/**
* Returns the inverse of the components of a vec2
*
* @param out the receiving vector
* @param a vector to invert
* @returns out
*/
export function inverse(out: Vec2, a: Vec2): Vec2;vec2.normalize
/**
* Normalize a vec2
*
* @param out the receiving vector
* @param a vector to normalize
* @returns out
*/
export function normalize(out: Vec2, a: Vec2): Vec2;vec2.dot
/**
* Calculates the dot product of two vec2's
*
* @param a the first operand
* @param b the second operand
* @returns dot product of a and b
*/
export function dot(a: Vec2, b: Vec2): number;vec2.cross
/**
* Computes the cross product of two vec2's
* Note that the cross product must by definition produce a 3D vector
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function cross(out: Vec3, a: Vec2, b: Vec2): Vec3;vec2.lerp
/**
* Performs a linear interpolation between two vec2's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param t interpolation amount, in the range [0-1], between the two inputs
* @returns out
*/
export function lerp(out: Vec2, a: Vec2, b: Vec2, t: number): Vec2;vec2.transformMat2
/**
* Transforms the vec2 with a mat2
*
* @param out the receiving vector
* @param a the vector to transform
* @param m matrix to transform with
* @returns out
*/
export function transformMat2(out: Vec2, a: Vec2, m: Mat2): Vec2;vec2.transformMat2d
/**
* Transforms the vec2 with a mat2d
*
* @param out the receiving vector
* @param a the vector to transform
* @param m matrix to transform with
* @returns out
*/
export function transformMat2d(out: Vec2, a: Vec2, m: Mat2d): Vec2;vec2.transformMat3
/**
* Transforms the vec2 with a mat3
* 3rd vector component is implicitly '1'
*
* @param out the receiving vector
* @param a the vector to transform
* @param m matrix to transform with
* @returns out
*/
export function transformMat3(out: Vec2, a: Vec2, m: Mat3): Vec2;vec2.transformMat4
/**
* Transforms the vec2 with a mat4
* 3rd vector component is implicitly '0'
* 4th vector component is implicitly '1'
*
* @param out the receiving vector
* @param a the vector to transform
* @param m matrix to transform with
* @returns out
*/
export function transformMat4(out: Vec2, a: Vec2, m: Mat4): Vec2;vec2.rotate
/**
* Rotate a 2D vector
* @param out The receiving vec2
* @param a The vec2 point to rotate
* @param b The origin of the rotation
* @param rad The angle of rotation in radians
* @returns out
*/
export function rotate(out: Vec2, a: Vec2, b: Vec2, rad: number): Vec2;vec2.angle
/**
* Get the angle between two 2D vectors
* @param a The first operand
* @param b The second operand
* @returns The angle in radians
*/
export function angle(a: Vec2, b: Vec2): number;vec2.zero
/**
* Set the components of a vec2 to zero
*
* @param out the receiving vector
* @returns out
*/
export function zero(out: Vec2): Vec2;vec2.str
/**
* Returns a string representation of a vector
*
* @param a vector to represent as a string
* @returns string representation of the vector
*/
export function str(a: Vec2): string;vec2.exactEquals
/**
* Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)
*
* @param a The first vector.
* @param b The second vector.
* @returns True if the vectors are equal, false otherwise.
*/
export function exactEquals(a: Vec2, b: Vec2): boolean;vec2.equals
/**
* Returns whether or not the vectors have approximately the same elements in the same position.
*
* @param a The first vector.
* @param b The second vector.
* @returns True if the vectors are equal, false otherwise.
*/
export function equals(a: Vec2, b: Vec2): boolean;vec2.finite
/**
* Returns whether or not the vector is finite
* @param a vector to test
* @returns whether or not the vector is finite
*/
export function finite(a: Vec2): boolean;vec2.len
/**
* Alias for {@link length}
*/
export const len = length;vec2.sub
/**
* Alias for {@link subtract}
*/
export const sub = subtract;vec2.mul
/**
* Alias for {@link multiply}
*/
export const mul = multiply;vec2.div
/**
* Alias for {@link divide}
*/
export const div = divide;vec2.dist
/**
* Alias for {@link distance}
*/
export const dist = distance;vec2.sqrDist
/**
* Alias for {@link squaredDistance}
*/
export const sqrDist = squaredDistance;vec2.sqrLen
/**
* Alias for {@link squaredLength}
*/
export const sqrLen = squaredLength;vec3
vec3.create
/**
* Creates a new, empty vec3
*
* @returns a new 3D vector
*/
export function create(): Vec3;vec3.clone
/**
* Creates a new vec3 initialized with values from an existing vector
*
* @param a vector to clone
* @returns a new 3D vector
*/
export function clone(a: Vec3): Vec3;vec3.length
/**
* Calculates the length of a vec3
*
* @param a vector to calculate length of
* @returns length of a
*/
export function length(a: Vec3): number;vec3.fromValues
/**
* Creates a new vec3 initialized with the given values
*
* @param x X component
* @param y Y component
* @param z Z component
* @returns a new 3D vector
*/
export function fromValues(x: number, y: number, z: number): Vec3;vec3.copy
/**
* Copy the values from one vec3 to another
*
* @param out the receiving vector
* @param a the source vector
* @returns out
*/
export function copy(out: Vec3, a: Vec3): Vec3;vec3.set
/**
* Set the components of a vec3 to the given values
*
* @param out the receiving vector
* @param x X component
* @param y Y component
* @param z Z component
* @returns out
*/
export function set(out: Vec3, x: number, y: number, z: number): Vec3;vec3.setScalar
/**
* Sets all components of a vec3 to the given scalar value
*
* @param out the receiving vector
* @param s scalar value to set
* @returns out
*/
export function setScalar(out: Vec3, s: number): Vec3;vec3.fromBuffer
/**
* Sets the components of a vec3 from a buffer
* @param out the receiving vector
* @param buffer the source buffer
* @param startIndex the starting index in the buffer
* @returns out
*/
export function fromBuffer(out: Vec3, buffer: ArrayLike<number>, startIndex: number): Vec3;vec3.toBuffer
/**
* Writes the components of a vec3 to a buffer
* @param outBuffer The output buffer
* @param vec The source vector
* @param startIndex The starting index in the buffer
* @returns The output buffer
*/
export function toBuffer(outBuffer: MutableArrayLike<number>, vec: Vec3, startIndex: number): ArrayLike<number>;vec3.add
/**
* Adds two vec3's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function add(out: Vec3, a: Vec3, b: Vec3): Vec3;vec3.addScalar
/**
* Adds a scalar value to all components of a vec3
*
* @param out the receiving vector
* @param a the source vector
* @param b the scalar value to add
* @returns out
*/
export function addScalar(out: Vec3, a: Vec3, b: number): Vec3;vec3.subtract
/**
* Subtracts vector b from vector a
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function subtract(out: Vec3, a: Vec3, b: Vec3): Vec3;vec3.subtractScalar
/**
* Subtracts a scalar value from all components of a vec3
*
* @param out the receiving vector
* @param a the source vector
* @param b the scalar value to subtract
* @returns out
*/
export function subtractScalar(out: Vec3, a: Vec3, b: number): Vec3;vec3.multiply
/**
* Multiplies two vec3's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function multiply(out: Vec3, a: Vec3, b: Vec3): Vec3;vec3.divide
/**
* Divides two vec3's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function divide(out: Vec3, a: Vec3, b: Vec3): Vec3;vec3.ceil
/**
* Math.ceil the components of a vec3
*
* @param out the receiving vector
* @param a vector to ceil
* @returns out
*/
export function ceil(out: Vec3, a: Vec3): Vec3;vec3.floor
/**
* Math.floor the components of a vec3
*
* @param out the receiving vector
* @param a vector to floor
* @returns out
*/
export function floor(out: Vec3, a: Vec3): Vec3;vec3.min
/**
* Returns the minimum of two vec3's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function min(out: Vec3, a: Vec3, b: Vec3): Vec3;vec3.max
/**
* Returns the maximum of two vec3's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function max(out: Vec3, a: Vec3, b: Vec3): Vec3;vec3.round
/**
* symmetric round the components of a vec3
*
* @param out the receiving vector
* @param a vector to round
* @returns out
*/
export function round(out: Vec3, a: Vec3): Vec3;vec3.scale
/**
* Scales a vec3 by a scalar number
*
* @param out the receiving vector
* @param a the vector to scale
* @param b amount to scale the vector by
* @returns out
*/
export function scale(out: Vec3, a: Vec3, b: number): Vec3;vec3.scaleAndAdd
/**
* Adds two vec3's after scaling the second operand by a scalar value
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param scale the amount to scale b by before adding
* @returns out
*/
export function scaleAndAdd(out: Vec3, a: Vec3, b: Vec3, scale: number): Vec3;vec3.distance
/**
* Calculates the euclidian distance between two vec3's
*
* @param a the first operand
* @param b the second operand
* @returns distance between a and b
*/
export function distance(a: Vec3, b: Vec3): number;vec3.squaredDistance
/**
* Calculates the squared euclidian distance between two vec3's
*
* @param a the first operand
* @param b the second operand
* @returns squared distance between a and b
*/
export function squaredDistance(a: Vec3, b: Vec3): number;vec3.squaredLength
/**
* Calculates the squared length of a vec3
*
* @param a vector to calculate squared length of
* @returns squared length of a
*/
export function squaredLength(a: Vec3): number;vec3.negate
/**
* Negates the components of a vec3
*
* @param out the receiving vector
* @param a vector to negate
* @returns out
*/
export function negate(out: Vec3, a: Vec3): Vec3;vec3.inverse
/**
* Returns the inverse of the components of a vec3
*
* @param out the receiving vector
* @param a vector to invert
* @returns out
*/
export function inverse(out: Vec3, a: Vec3): Vec3;vec3.normalize
/**
* Normalize a vec3
*
* @param out the receiving vector
* @param a vector to normalize
* @returns out
*/
export function normalize(out: Vec3, a: Vec3): Vec3;vec3.dot
/**
* Calculates the dot product of two vec3's
*
* @param a the first operand
* @param b the second operand
* @returns dot product of a and b
*/
export function dot(a: Vec3, b: Vec3): number;vec3.cross
/**
* Computes the cross product of two vec3's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function cross(out: Vec3, a: Vec3, b: Vec3): Vec3;vec3.perpendicular
/**
* Calculates a normalized perpendicular vector to the given vector.
* Useful for finding an arbitrary orthogonal basis vector.
*
* @param out the receiving vector
* @param a the source vector
* @returns the out vector
*/
export function perpendicular(out: Vec3, a: Vec3): Vec3;vec3.lerp
/**
* Performs a linear interpolation between two vec3's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param t interpolation amount, in the range [0-1], between the two inputs
* @returns out
*/
export function lerp(out: Vec3, a: Vec3, b: Vec3, t: number): Vec3;vec3.slerp
/**
* Performs a spherical linear interpolation between two vec3's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param t interpolation amount, in the range [0-1], between the two inputs
* @returns out
*/
export function slerp(out: Vec3, a: Vec3, b: Vec3, t: number): Vec3;vec3.hermite
/**
* Performs a hermite interpolation with two control points
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param c the third operand
* @param d the fourth operand
* @param t interpolation amount, in the range [0-1], between the two inputs
* @returns out
*/
export function hermite(out: Vec3, a: Vec3, b: Vec3, c: Vec3, d: Vec3, t: number): Vec3;vec3.bezier
/**
* Performs a bezier interpolation with two control points
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param c the third operand
* @param d the fourth operand
* @param t interpolation amount, in the range [0-1], between the two inputs
* @returns out
*/
export function bezier(out: Vec3, a: Vec3, b: Vec3, c: Vec3, d: Vec3, t: number): Vec3;vec3.transformMat4
/**
* Transforms the vec3 with a mat4.
* 4th vector component is implicitly '1'
*
* @param out the receiving vector
* @param a the vector to transform
* @param m matrix to transform with
* @returns out
*/
export function transformMat4(out: Vec3, a: Vec3, m: Mat4): Vec3;vec3.transformMat3
/**
* Transforms the vec3 with a mat3.
*
* @param out the receiving vector
* @param a the vector to transform
* @param m the 3x3 matrix to transform with
* @returns out
*/
export function transformMat3(out: Vec3, a: Vec3, m: Mat3): Vec3;vec3.transformQuat
/**
* Transforms the vec3 with a quat
* Can also be used for dual quaternions. (Multiply it with the real part)
*
* @param out the receiving vector
* @param a the vector to transform
* @param q quaternion to transform with
* @returns out
*/
export function transformQuat(out: Vec3, a: Vec3, q: Quat): Vec3;vec3.rotateX
/**
* Rotate a 3D vector around the x-axis
* @param out The receiving vec3
* @param a The vec3 point to rotate
* @param b The origin of the rotation
* @param rad The angle of rotation in radians
* @returns out
*/
export function rotateX(out: Vec3, a: Vec3, b: Vec3, rad: number): Vec3;vec3.rotateY
/**
* Rotate a 3D vector around the y-axis
* @param out The receiving vec3
* @param a The vec3 point to rotate
* @param b The origin of the rotation
* @param rad The angle of rotation in radians
* @returns out
*/
export function rotateY(out: Vec3, a: Vec3, b: Vec3, rad: number): Vec3;vec3.rotateZ
/**
* Rotate a 3D vector around the z-axis
* @param out The receiving vec3
* @param a The vec3 point to rotate
* @param b The origin of the rotation
* @param rad The angle of rotation in radians
* @returns out
*/
export function rotateZ(out: Vec3, a: Vec3, b: Vec3, rad: number): Vec3;vec3.angle
/**
* Get the angle between two 3D vectors
* @param a The first operand
* @param b The second operand
* @returns The angle in radians
*/
export function angle(a: Vec3, b: Vec3): number;vec3.zero
/**
* Set the components of a vec3 to zero
*
* @param out the receiving vector
* @returns out
*/
export function zero(out: Vec3): Vec3;vec3.str
/**
* Returns a string representation of a vector
*
* @param a vector to represent as a string
* @returns string representation of the vector
*/
export function str(a: Vec3): string;vec3.exactEquals
/**
* Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)
*
* @param a The first vector.
* @param b The second vector.
* @returns True if the vectors are equal, false otherwise.
*/
export function exactEquals(a: Vec3, b: Vec3): boolean;vec3.equals
/**
* Returns whether or not the vectors have approximately the same elements in the same position.
*
* @param a The first vector.
* @param b The second vector.
* @returns True if the vectors are equal, false otherwise.
*/
export function equals(a: Vec3, b: Vec3): boolean;vec3.finite
/**
* Returns whether or not the vector is finite
* @param a vector to test
* @returns whether or not the vector is finite
*/
export function finite(a: Vec3): boolean;vec3.isScaleInsideOut
/**
* Determines if a scale vector represents an inside-out transformation (reflection)
* Returns true if an odd number of scale components are negative
*
* @param scale The scale vector to test
* @returns true if the scale represents a reflection (odd number of negative components)
*/
export function isScaleInsideOut(scale: Vec3): boolean;vec3.sub
/**
* Alias for {@link subtract}
*/
export const sub = subtract;vec3.mul
/**
* Alias for {@link multiply}
*/
export const mul = multiply;vec3.div
/**
* Alias for {@link divide}
*/
export const div = divide;vec3.dist
/**
* Alias for {@link distance}
*/
export const dist = distance;vec3.sqrDist
/**
* Alias for {@link squaredDistance}
*/
export const sqrDist = squaredDistance;vec3.len
/**
* Alias for {@link length}
*/
export const len = length;vec3.sqrLen
/**
* Alias for {@link squaredLength}
*/
export const sqrLen = squaredLength;vec4
vec4.create
/**
* Creates a new, empty vec4
*
* @returns a new 4D vector
*/
export function create(): Vec4;vec4.clone
/**
* Creates a new vec4 initialized with values from an existing vector
*
* @param a vector to clone
* @returns a new 4D vector
*/
export function clone(a: Vec4): Vec4;vec4.fromValues
/**
* Creates a new vec4 initialized with the given values
*
* @param x X component
* @param y Y component
* @param z Z component
* @param w W component
* @returns a new 4D vector
*/
export function fromValues(x: number, y: number, z: number, w: number): Vec4;vec4.copy
/**
* Copy the values from one vec4 to another
*
* @param out the receiving vector
* @param a the source vector
* @returns out
*/
export function copy(out: Vec4, a: Vec4): Vec4;vec4.set
/**
* Set the components of a vec4 to the given values
*
* @param out the receiving vector
* @param x X component
* @param y Y component
* @param z Z component
* @param w W component
* @returns out
*/
export function set(out: Vec4, x: number, y: number, z: number, w: number): Vec4;vec4.add
/**
* Adds two vec4's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function add(out: Vec4, a: Vec4, b: Vec4): Vec4;vec4.subtract
/**
* Subtracts vector b from vector a
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function subtract(out: Vec4, a: Vec4, b: Vec4): Vec4;vec4.multiply
/**
* Multiplies two vec4's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function multiply(out: Vec4, a: Vec4, b: Vec4): Vec4;vec4.divide
/**
* Divides two vec4's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function divide(out: Vec4, a: Vec4, b: Vec4): Vec4;vec4.ceil
/**
* Math.ceil the components of a vec4
*
* @param out the receiving vector
* @param a vector to ceil
* @returns out
*/
export function ceil(out: Vec4, a: Vec4): Vec4;vec4.floor
/**
* Math.floor the components of a vec4
*
* @param out the receiving vector
* @param a vector to floor
* @returns out
*/
export function floor(out: Vec4, a: Vec4): Vec4;vec4.min
/**
* Returns the minimum of two vec4's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function min(out: Vec4, a: Vec4, b: Vec4): Vec4;vec4.max
/**
* Returns the maximum of two vec4's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function max(out: Vec4, a: Vec4, b: Vec4): Vec4;vec4.round
/**
* symmetric round the components of a vec4
*
* @param out the receiving vector
* @param a vector to round
* @returns out
*/
export function round(out: Vec4, a: Vec4): Vec4;vec4.scale
/**
* Scales a vec4 by a scalar number
*
* @param out the receiving vector
* @param a the vector to scale
* @param b amount to scale the vector by
* @returns out
*/
export function scale(out: Vec4, a: Vec4, b: number): Vec4;vec4.scaleAndAdd
/**
* Adds two vec4's after scaling the second operand by a scalar value
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param scale the amount to scale b by before adding
* @returns out
*/
export function scaleAndAdd(out: Vec4, a: Vec4, b: Vec4, scale: number): Vec4;vec4.distance
/**
* Calculates the euclidian distance between two vec4's
*
* @param a the first operand
* @param b the second operand
* @returns distance between a and b
*/
export function distance(a: Vec4, b: Vec4): number;vec4.squaredDistance
/**
* Calculates the squared euclidian distance between two vec4's
*
* @param a the first operand
* @param b the second operand
* @returns squared distance between a and b
*/
export function squaredDistance(a: Vec4, b: Vec4): number;vec4.length
/**
* Calculates the length of a vec4
*
* @param a vector to calculate length of
* @returns length of a
*/
export function length(a: Vec4): number;vec4.squaredLength
/**
* Calculates the squared length of a vec4
*
* @param a vector to calculate squared length of
* @returns squared length of a
*/
export function squaredLength(a: Vec4): number;vec4.negate
/**
* Negates the components of a vec4
*
* @param out the receiving vector
* @param a vector to negate
* @returns out
*/
export function negate(out: Vec4, a: Vec4): Vec4;vec4.inverse
/**
* Returns the inverse of the components of a vec4
*
* @param out the receiving vector
* @param a vector to invert
* @returns out
*/
export function inverse(out: Vec4, a: Vec4): Vec4;vec4.normalize
/**
* Normalize a vec4
*
* @param out the receiving vector
* @param a vector to normalize
* @returns out
*/
export function normalize(out: Vec4, a: Vec4): Vec4;vec4.dot
/**
* Calculates the dot product of two vec4's
*
* @param a the first operand
* @param b the second operand
* @returns dot product of a and b
*/
export function dot(a: Vec4, b: Vec4): number;vec4.cross
/**
* Returns the cross-product of three vectors in a 4-dimensional space
*
* @param out the receiving vector
* @param u the first vector
* @param v the second vector
* @param w the third vector
* @returns result
*/
export function cross(out: Vec4, u: Vec4, v: Vec4, w: Vec4): Vec4;vec4.lerp
/**
* Performs a linear interpolation between two vec4's
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param t interpolation amount, in the range [0-1], between the two inputs
* @returns out
*/
export function lerp(out: Vec4, a: Vec4, b: Vec4, t: number): Vec4;vec4.transformMat4
/**
* Transforms the vec4 with a mat4.
*
* @param out the receiving vector
* @param a the vector to transform
* @param m matrix to transform with
* @returns out
*/
export function transformMat4(out: Vec4, a: Vec4, m: Mat4): Vec4;vec4.transformQuat
/**
* Transforms the vec4 with a quat
*
* @param out the receiving vector
* @param a the vector to transform
* @param q quaternion to transform with
* @returns out
*/
export function transformQuat(out: Vec4, a: Vec4, q: Quat): Vec4;vec4.zero
/**
* Set the components of a vec4 to zero
*
* @param out the receiving vector
* @returns out
*/
export function zero(out: Vec4): Vec4;vec4.str
/**
* Returns a string representation of a vector
*
* @param a vector to represent as a string
* @returns string representation of the vector
*/
export function str(a: Vec4): string;vec4.exactEquals
/**
* Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)
*
* @param a The first vector.
* @param b The second vector.
* @returns True if the vectors are equal, false otherwise.
*/
export function exactEquals(a: Vec4, b: Vec4): boolean;vec4.equals
/**
* Returns whether or not the vectors have approximately the same elements in the same position.
*
* @param a The first vector.
* @param b The second vector.
* @returns True if the vectors are equal, false otherwise.
*/
export function equals(a: Vec4, b: Vec4): boolean;vec4.finite
/**
* Returns whether or not the vector is finite
* @param a vector to test
* @returns whether or not the vector is finite
*/
export function finite(a: Vec4): boolean;vec4.sub
/**
* Alias for {@link subtract}
*/
export const sub = subtract;vec4.mul
/**
* Alias for {@link multiply}
*/
export const mul = multiply;vec4.div
/**
* Alias for {@link divide}
*/
export const div = divide;vec4.dist
/**
* Alias for {@link distance}
*/
export const dist = distance;vec4.sqrDist
/**
* Alias for {@link squaredDistance}
*/
export const sqrDist = squaredDistance;vec4.len
/**
* Alias for {@link length}
*/
export const len = length;vec4.sqrLen
/**
* Alias for {@link squaredLength}
*/
export const sqrLen = squaredLength;euler
euler.create
/**
* Creates a new Euler with default values (0, 0, 0, 'xyz').
*/
export function create(): Euler;euler.fromValues
/**
* Creates a new Euler from the given values.
* @param x The x rotation in radians.
* @param y The y rotation in radians.
* @param z The z rotation in radians.
* @param order The order of rotation.
* @returns A new Euler.
*/
export function fromValues(x: number, y: number, z: number, order: EulerOrder): Euler;euler.set
/**
* Sets a given Euler from the given values.
* @param x The x rotation in radians.
* @param y The y rotation in radians.
* @param z The z rotation in radians.
* @param order The order of rotation.
* @returns The output Euler.
*/
export function set(out: Euler, x: number, y: number, z: number, order: EulerOrder): Euler;euler.fromDegrees
/**
* Sets Euler angle radians from given degrees
* @param out The output Euler.
* @param x The x rotation in degrees.
* @param y The y rotation in degrees.
* @param z The z rotation in degrees.
* @param order The order of rotation.
* @returns The output Euler.
*/
export function fromDegrees(out: Euler, x: number, y: number, z: number, order: EulerOrder): Euler;euler.fromRotationMat4
/**
* Sets the Euler angles from a rotation matrix.
* @param out The output Euler.
* @param rotationMatrix The input rotation matrix.
* @param order The order of the Euler angles.
* @returns The output Euler.
*/
export function fromRotationMat4(out: Euler, rotationMatrix: Mat4, order: EulerOrder = out[3] || 'xyz'): Euler;euler.exactEquals
/**
* Returns whether or not the euler angles have exactly the same elements in the same position (when compared with ===)
*
* @param a The first euler.
* @param b The second euler.
* @returns True if the euler angles are equal, false otherwise.
*/
export function exactEquals(a: Euler, b: Euler): boolean;euler.equals
/**
* Returns whether or not the euler angles have approximately the same elements in the same position.
*
* @param a The first euler.
* @param b The second euler.
* @returns True if the euler angles are equal, false otherwise.
*/
export function equals(a: Euler, b: Euler): boolean;euler.fromQuat
/**
* Sets the Euler angles from a quaternion.
* @param out The output Euler.
* @param q The input quaternion.
* @param order The order of the Euler.
* @returns The output Euler
*/
export function fromQuat(out: Euler, q: Quat, order: EulerOrder): Euler;euler.reorder
/**
* Reorders the Euler based on the specified order.
* @param out The output Euler.
* @param a The input Euler.
* @param order The order of the Euler.
* @returns The output Euler.
*/
export function reorder(out: Euler, a: Euler, order: EulerOrder): Euler;quat
quat.create
/**
* Creates a new identity quat
*
* @returns a new quaternion
*/
export function create(): Quat;quat.identity
/**
* Set a quat to the identity quaternion
*
* @param out the receiving quaternion
* @returns out
*/
export function identity(out: Quat): Quat;quat.setAxisAngle
/**
* Sets a quat from the given angle and rotation axis,
* then returns it.
*
* @param out the receiving quaternion
* @param axis the axis around which to rotate
* @param rad the angle in radians
* @returns out
**/
export function setAxisAngle(out: Quat, axis: Vec3, rad: number): Quat;quat.getAxisAngle
/**
* Gets the rotation axis and angle for a given
* quaternion. If a quaternion is created with
* setAxisAngle, this method will return the same
* values as providied in the original parameter list
* OR functionally equivalent values.
* Example: The quaternion formed by axis [0, 0, 1] and
* angle -90 is the same as the quaternion formed by
* [0, 0, 1] and 270. This method favors the latter.
* @param out_axis Vector receiving the axis of rotation
* @param q Quaternion to be decomposed
* @return Angle, in radians, of the rotation
*/
export function getAxisAngle(out_axis: Vec3, q: Quat): number;quat.getAngle
/**
* Gets the angular distance between two unit quaternions
*
* @param a Origin unit quaternion
* @param b Destination unit quaternion
* @return Angle, in radians, between the two quaternions
*/
export function getAngle(a: Quat, b: Quat): number;quat.multiply
/**
* Multiplies two quat's
*
* @param out the receiving quaternion
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function multiply(out: Quat, a: Quat, b: Quat): Quat;quat.rotateX
/**
* Rotates a quaternion by the given angle about the X axis
*
* @param out quat receiving operation result
* @param a quat to rotate
* @param rad angle (in radians) to rotate
* @returns out
*/
export function rotateX(out: Quat, a: Quat, rad: number): Quat;quat.rotateY
/**
* Rotates a quaternion by the given angle about the Y axis
*
* @param out quat receiving operation result
* @param a quat to rotate
* @param rad angle (in radians) to rotate
* @returns out
*/
export function rotateY(out: Quat, a: Quat, rad: number): Quat;quat.rotateZ
/**
* Rotates a quaternion by the given angle about the Z axis
*
* @param out quat receiving operation result
* @param a quat to rotate
* @param rad angle (in radians) to rotate
* @returns out
*/
export function rotateZ(out: Quat, a: Quat, rad: number): Quat;quat.calculateW
/**
* Calculates the W component of a quat from the X, Y, and Z components.
* Assumes that quaternion is 1 unit in length.
* Any existing W component will be ignored.
*
* @param out the receiving quaternion
* @param a quat to calculate W component of
* @returns out
*/
export function calculateW(out: Quat, a: Quat): Quat;quat.exp
/**
* Calculate the exponential of a unit quaternion.
*
* @param out the receiving quaternion
* @param a quat to calculate the exponential of
* @returns out
*/
export function exp(out: Quat, a: Quat): Quat;quat.ln
/**
* Calculate the natural logarithm of a unit quaternion.
*
* @param out the receiving quaternion
* @param a quat to calculate the exponential of
* @returns out
*/
export function ln(out: Quat, a: Quat): Quat;quat.pow
/**
* Calculate the scalar power of a unit quaternion.
*
* @param out the receiving quaternion
* @param a quat to calculate the exponential of
* @param b amount to scale the quaternion by
* @returns out
*/
export function pow(out: Quat, a: Quat, b: number): Quat;quat.slerp
/**
* Performs a spherical linear interpolation between two quat
*
* @param out the receiving quaternion
* @param a the first operand
* @param b the second operand
* @param t interpolation amount, in the range [0-1], between the two inputs
* @returns out
*/
export function slerp(out: Quat, a: Quat, b: Quat, t: number): Quat;quat.invert
/**
* Calculates the inverse of a quat
*
* @param out the receiving quaternion
* @param a quat to calculate inverse of
* @returns out
*/
export function invert(out: Quat, a: Quat): Quat;quat.conjugate
/**
* Calculates the conjugate of a quat
* If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.
*
* @param out the receiving quaternion
* @param a quat to calculate conjugate of
* @returns out
*/
export function conjugate(out: Quat, a: Quat): Quat;quat.fromMat3
/**
* Creates a quaternion from the given 3x3 rotation matrix.
*
* NOTE: The resultant quaternion is not normalized, so you should be sure
* to renormalize the quaternion yourself where necessary.
*
* @param out the receiving quaternion
* @param m rotation matrix
* @returns out
*/
export function fromMat3(out: Quat, m: Mat3): Quat;quat.fromMat4
/**
* Calculates a quaternion from a 4x4 rotation matrix
* Extracts the 3x3 rotation part and calls fromMat3
*
* @param out the receiving quaternion
* @param m rotation matrix
* @returns out
*/
export function fromMat4(out: Quat, m: Mat4): Quat;quat.fromEuler
/**
* Creates a quaternion from the given euler
* @param out the receiving quaternion
* @param euler the euler to create the quaternion from
* @returns out
*/
export function fromEuler(out: Quat, euler: Euler): Quat;quat.fromDegrees
/**
* Creates a quaternion from euler angles specified in degrees.
* Shorthand for converting degrees to radians and then creating a quaternion from euler.
*
* @param out the receiving quaternion
* @param x The x euler rotation in degrees
* @param y The y euler rotation in degrees
* @param z The z euler rotation in degrees
* @param order The order of rotation
* @returns out
*/
export function fromDegrees(out: Quat, x: number, y: number, z: number, order: EulerOrder): Quat;quat.str
/**
* Returns a string representation of a quaternion
*
* @param a vector to represent as a string
* @returns string representation of the vector
*/
export function str(a: Quat): string;quat.clone
/**
* Creates a new quat initialized with values from an existing quaternion
*
* @param a quaternion to clone
* @returns a new quaternion
*/
export const clone = vec4.clone;quat.fromValues
/**
* Creates a new quat initialized with the given values
*
* @param x X component
* @param y Y component
* @param z Z component
* @param w W component
* @returns a new quaternion
*/
export const fromValues = vec4.fromValues;quat.copy
/**
* Copy the values from one quat to another
*
* @param out the receiving quaternion
* @param a the source quaternion
* @returns out
*/
export const copy = vec4.copy;quat.set
/**
* Set the components of a quat to the given values
*
* @param out the receiving quaternion
* @param x X component
* @param y Y component
* @param z Z component
* @param w W component
* @returns out
*/
export const set = vec4.set;quat.add
/**
* Adds two quat's
*
* @param out the receiving quaternion
* @param a the first operand
* @param b the second operand
* @returns out
*/
export const add = vec4.add;quat.scale
/**
* Scales a quat by a scalar number
*
* @param out the receiving quaternion
* @param a the quaternion to scale
* @param b amount to scale the quaternion by
* @returns out
*/
export const scale = vec4.scale;quat.dot
/**
* Calculates the dot product of two quat's
*
* @param a the first operand
* @param b the second operand
* @returns dot product of a and b
*/
export const dot = vec4.dot;quat.lerp
/**
* Performs a linear interpolation between two quat's
*
* @param out the receiving quaternion
* @param a the first operand
* @param b the second operand
* @param t interpolation amount, in the range [0-1], between the two inputs
* @returns out
*/
export const lerp = vec4.lerp;quat.length
/**
* Calculates the length of a quat
*
* @param a quaternion to calculate length of
* @returns length of a
*/
export const length = vec4.length;quat.len
/**
* Alias for {@link length}
*/
export const len = length;quat.squaredLength
/**
* Calculates the squared length of a quat
*
* @param a quaternion to calculate squared length of
* @returns squared length of a
*/
export const squaredLength = vec4.squaredLength;quat.sqrLen
/**
* Alias for {@link squaredLength}
*/
export const sqrLen = squaredLength;quat.mul
/**
* Alias for {@link multiply}
*/
export const mul = multiply;quat.normalize
/**
* Normalize a quat
*
* @param out the receiving quaternion
* @param a quaternion to normalize
* @returns out
*/
export const normalize = vec4.normalize;quat.exactEquals
/**
* Returns whether or not the quaternions have exactly the same elements in the same position (when compared with ===)
*
* @param a The first quaternion.
* @param b The second quaternion.
* @returns True if the quaternions are equal, false otherwise.
*/
export const exactEquals = vec4.exactEquals;quat.equals
/**
* Returns whether or not the quaternions have approximately the same elements in the same position.
*
* @param a The first quaternion.
* @param b The second quaternion.
* @returns True if the quaternions are equal, false otherwise.
*/
export function equals(a: Quat, b: Quat): boolean;quat.rotationTo
/**
* Sets a quaternion to represent the shortest rotation from one
* vector to another.
*
* Both vectors are assumed to be unit length.
*
* @param out the receiving quaternion.
* @param a the initial vector
* @param b the destination vector
* @returns out
*/
export const rotationTo = (() => {
const tmpvec3 = vec3.create();
const xUnitVec3 = vec3.fromValues(1, 0, 0);
const yUnitVec3 = vec3.fromValues(0, 1, 0);
return (out: Quat, a: Vec3, b: Vec3): Quat => {
const dot = vec3.dot(a, b);
if (dot < -0.999999) {
vec3.cross(tmpvec3, xUnitVec3, a);
if (vec3.length(tmpvec3) < 0.000001)
vec3.cross(tmpvec3, yUnitVec3, a);
vec3.normalize(tmpvec3, tmpvec3);
setAxisAngle(out, tmpvec3, Math.PI);
return out;
}
if (dot > 0.999999) {
out[0] = 0;
out[1] = 0;
out[2] = 0;
out[3] = 1;
return out;
}
vec3.cross(tmpvec3, a, b);
out[0] = tmpvec3[0];
out[1] = tmpvec3[1];
out[2] = tmpvec3[2];
out[3] = 1 + dot;
return normalize(out, out);
};
})();quat.sqlerp
/**
* Performs a spherical linear interpolation with two control points
*
* @param out the receiving quaternion
* @param a the first operand
* @param b the second operand
* @param c the third operand
* @param d the fourth operand
* @param t interpolation amount, in the range [0-1], between the two inputs
* @returns out
*/
export const sqlerp = (() => {
const temp1 = create();
const temp2 = create();
return (out: Quat, a: Quat, b: Quat, c: Quat, d: Quat, t: number): Quat => {
slerp(temp1, a, d, t);
slerp(temp2, b, c, t);
slerp(out, temp1, temp2, 2 * t * (1 - t));
return out;
};
})();quat.setAxes
/**
* Sets the specified quaternion with values corresponding to the given
* axes. Each axis is a vec3 and is expected to be unit length and
* perpendicular to all other specified axes.
*
* @param view the vector representing the viewing direction
* @param right the vector representing the local "right" direction
* @param up the vector representing the local "up" direction
* @returns out
*/
export const setAxes = (() => {
const matr = mat3.create();
return (out: Quat, view: Vec3, right: Vec3, up: Vec3): Quat => {
matr[0] = right[0];
matr[3] = right[1];
matr[6] = right[2];
matr[1] = up[0];
matr[4] = up[1];
matr[7] = up[2];
matr[2] = -view[0];
matr[5] = -view[1];
matr[8] = -view[2];
return normalize(out, fromMat3(out, matr));
};
})();quat2
quat2.create
/**
* Creates a new identity dual quat
*
* @returns a new dual quaternion [real -> rotation, dual -> translation]
*/
export function create(): Quat2;quat2.clone
/**
* Creates a new quat initialized with values from an existing quaternion
*
* @param a dual quaternion to clone
* @returns new dual quaternion
* @function
*/
export function clone(a: Quat2): Quat2;quat2.fromValues
/**
* Creates a new dual quat initialized with the given values
*
* @param x1 X component
* @param y1 Y component
* @param z1 Z component
* @param w1 W component
* @param x2 X component
* @param y2 Y component
* @param z2 Z component
* @param w2 W component
* @returns new dual quaternion
* @function
*/
export function fromValues(x1: number, y1: number, z1: number, w1: number, x2: number, y2: number, z2: number, w2: number): Quat2;quat2.fromRotationTranslationValues
/**
* Creates a new dual quat from the given values (quat and translation)
*
* @param x1 X component
* @param y1 Y component
* @param z1 Z component
* @param w1 W component
* @param x2 X component (translation)
* @param y2 Y component (translation)
* @param z2 Z component (translation)
* @returns new dual quaternion
* @function
*/
export function fromRotationTranslationValues(x1: number, y1: number, z1: number, w1: number, x2: number, y2: number, z2: number): Quat2;quat2.fromRotationTranslation
/**
* Creates a dual quat from a quaternion and a translation
*
* @param out dual quaternion receiving operation result
* @param q a normalized quaternion
* @param t translation vector
* @returns dual quaternion receiving operation result
* @function
*/
export function fromRotationTranslation(out: Quat2, q: Quat, t: Vec3): Quat2;quat2.fromTranslation
/**
* Creates a dual quat from a translation
*
* @param out dual quaternion receiving operation result
* @param t translation vector
* @returns dual quaternion receiving operation result
* @function
*/
export function fromTranslation(out: Quat2, t: Vec3): Quat2;quat2.fromRotation
/**
* Creates a dual quat from a quaternion
*
* @param out dual quaternion receiving operation result
* @param q the quaternion
* @returns dual quaternion receiving operation result
* @function
*/
export function fromRotation(out: Quat2, q: Quat): Quat2;quat2.fromMat4
/**
* Creates a new dual quat from a matrix (4x4)
*
* @param out the dual quaternion
* @param a the matrix
* @returns dual quat receiving operation result
* @function
*/
export function fromMat4(out: Quat2, a: Mat4): Quat2;quat2.copy
/**
* Copy the values from one dual quat to another
*
* @param out the receiving dual quaternion
* @param a the source dual quaternion
* @returns out
* @function
*/
export function copy(out: Quat2, a: Quat2): Quat2;quat2.identity
/**
* Set a dual quat to the identity dual quaternion
*
* @param out the receiving quaternion
* @returns out
*/
export function identity(out: Quat2): Quat2;quat2.set
/**
* Set the components of a dual quat to the given values
*
* @param out the receiving quaternion
* @param x1 X component
* @param y1 Y component
* @param z1 Z component
* @param w1 W component
* @param x2 X component
* @param y2 Y component
* @param z2 Z component
* @param w2 W component
* @returns out
* @function
*/
export function set(out: Quat2, x1: number, y1: number, z1: number, w1: number, x2: number, y2: number, z2: number, w2: number): Quat2;quat2.getReal
/**
* Gets the real part of a dual quat
* @param out real part
* @param a Dual Quaternion
* @return real part
*/
export const getReal = quat.copy;quat2.getDual
/**
* Gets the dual part of a dual quat
* @param out dual part
* @param a Dual Quaternion
* @return dual part
*/
export function getDual(out: Quat, a: Quat2): Quat;quat2.setReal
/**
* Set the real component of a dual quat to the given quaternion
*
* @param out the receiving quaternion
* @param q a quaternion representing the real part
* @returns out
* @function
*/
export const setReal = quat.copy;quat2.setDual
/**
* Set the dual component of a dual quat to the given quaternion
*
* @param out the receiving quaternion
* @param q a quaternion representing the dual part
* @returns out
* @function
*/
export function setDual(out: Quat2, q: Quat): Quat2;quat2.getTranslation
/**
* Gets the translation of a normalized dual quat
* @param out translation
* @param a Dual Quaternion to be decomposed
* @return translation
*/
export function getTranslation(out: Vec3, a: Quat2): Vec3;quat2.translate
/**
* Translates a dual quat by the given vector
*
* @param out the receiving dual quaternion
* @param a the dual quaternion to translate
* @param v vector to translate by
* @returns out
*/
export function translate(out: Quat2, a: Quat2, v: Vec3): Quat2;quat2.rotateX
/**
* Rotates a dual quat around the X axis
*
* @param out the receiving dual quaternion
* @param a the dual quaternion to rotate
* @param rad how far should the rotation be
* @returns out
*/
export function rotateX(out: Quat2, a: Quat2, rad: number): Quat2;quat2.rotateY
/**
* Rotates a dual quat around the Y axis
*
* @param out the receiving dual quaternion
* @param a the dual quaternion to rotate
* @param rad how far should the rotation be
* @returns out
*/
export function rotateY(out: Quat2, a: Quat2, rad: number): Quat2;quat2.rotateZ
/**
* Rotates a dual quat around the Z axis
*
* @param out the receiving dual quaternion
* @param a the dual quaternion to rotate
* @param rad how far should the rotation be
* @returns out
*/
export function rotateZ(out: Quat2, a: Quat2, rad: number): Quat2;quat2.rotateByQuatAppend
/**
* Rotates a dual quat by a given quaternion (a * q)
*
* @param out the receiving dual quaternion
* @param a the dual quaternion to rotate
* @param q quaternion to rotate by
* @returns out
*/
export function rotateByQuatAppend(out: Quat2, a: Quat2, q: Quat): Quat2;quat2.rotateByQuatPrepend
/**
* Rotates a dual quat by a given quaternion (q * a)
*
* @param out the receiving dual quaternion
* @param q quaternion to rotate by
* @param a the dual quaternion to rotate
* @returns out
*/
export function rotateByQuatPrepend(out: Quat2, q: Quat, a: Quat2): Quat2;quat2.rotateAroundAxis
/**
* Rotates a dual quat around a given axis. Does the normalisation automatically
*
* @param out the receiving dual quaternion
* @param a the dual quaternion to rotate
* @param axis the axis to rotate around
* @param rad how far the rotation should be
* @returns out
*/
export function rotateAroundAxis(out: Quat2, a: Quat2, axis: Vec3, rad: number): Quat2;quat2.add
/**
* Adds two dual quat's
*
* @param out the receiving dual quaternion
* @param a the first operand
* @param b the second operand
* @returns out
* @function
*/
export function add(out: Quat2, a: Quat2, b: Quat2): Quat2;quat2.multiply
/**
* Multiplies two dual quat's
*
* @param out the receiving dual quaternion
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function multiply(out: Quat2, a: Quat2, b: Quat2): Quat2;quat2.mul
/**
* Alias for {@link quat2.multiply}
* @function
*/
export const mul = multiply;quat2.scale
/**
* Scales a dual quat by a scalar number
*
* @param out the receiving dual quat
* @param a the dual quat to scale
* @param b amount to scale the dual quat by
* @returns out
* @function
*/
export function scale(out: Quat2, a: Quat2, b: number): Quat2;quat2.dot
/**
* Calculates the dot product of two dual quat's (The dot product of the real parts)
*
* @param a the first operand
* @param b the second operand
* @returns dot product of a and b
* @function
*/
export const dot = quat.dot;quat2.lerp
/**
* Performs a linear interpolation between two dual quats's
* NOTE: The resulting dual quaternions won't always be normalized (The error is most noticeable when t = 0.5)
*
* @param out the receiving dual quat
* @param a the first operand
* @param b the second operand
* @param t interpolation amount, in the range [0-1], between the two inputs
* @returns out
*/
export function lerp(out: Quat2, a: Quat2, b: Quat2, t: number): Quat2;quat2.invert
/**
* Calculates the inverse of a dual quat. If they are normalized, conjugate is cheaper
*
* @param out the receiving dual quaternion
* @param a dual quat to calculate inverse of
* @returns out
*/
export function invert(out: Quat2, a: Quat2): Quat2;quat2.conjugate
/**
* Calculates the conjugate of a dual quat
* If the dual quaternion is normalized, this function is faster than quat2.inverse and produces the same result.
*
* @param out the receiving quaternion
* @param a quat to calculate conjugate of
* @returns out
*/
export function conjugate(out: Quat2, a: Quat2): Quat2;quat2.length
/**
* Calculates the length of a dual quat
*
* @param a dual quat to calculate length of
* @returns length of a
* @function
*/
export const length = quat.length;quat2.len
/**
* Alias for {@link quat2.length}
* @function
*/
export const len = length;quat2.squaredLength
/**
* Calculates the squared length of a dual quat
*
* @param a dual quat to calculate squared length of
* @returns squared length of a
* @function
*/
export const squaredLength = quat.squaredLength;quat2.sqrLen
/**
* Alias for {@link quat2.squaredLength}
* @function
*/
export const sqrLen = squaredLength;quat2.normalize
/**
* Normalize a dual quat
*
* @param out the receiving dual quaternion
* @param a dual quaternion to normalize
* @returns out
* @function
*/
export function normalize(out: Quat2, a: Quat2): Quat2;quat2.str
/**
* Returns a string representation of a dual quaternion
*
* @param a dual quaternion to represent as a string
* @returns string representation of the dual quat
*/
export function str(a: Quat2): string;quat2.exactEquals
/**
* Returns whether or not the dual quaternions have exactly the same elements in the same position (when compared with ===)
*
* @param a the first dual quaternion.
* @param b the second dual quaternion.
* @returns true if the dual quaternions are equal, false otherwise.
*/
export function exactEquals(a: Quat2, b: Quat2): boolean;quat2.equals
/**
* Returns whether or not the dual quaternions have approximately the same elements in the same position.
*
* @param a the first dual quat.
* @param b the second dual quat.
* @returns true if the dual quats are equal, false otherwise.
*/
export function equals(a: Quat2, b: Quat2): boolean;mat2
mat2.create
/**
* Creates a new identity mat2
*
* @returns a new 2x2 matrix
*/
export function create(): Mat2;mat2.clone
/**
* Creates a new mat2 initialized with values from an existing matrix
*
* @param a matrix to clone
* @returns a new 2x2 matrix
*/
export function clone(a: Mat2): Mat2;mat2.copy
/**
* Copy the values from one mat2 to another
*
* @param out the receiving matrix
* @param a the source matrix
* @returns out
*/
export function copy(out: Mat2, a: Mat2): Mat2;mat2.identity
/**
* Set a mat2 to the identity matrix
*
* @param out the receiving matrix
* @returns out
*/
export function identity(out: Mat2): Mat2;mat2.fromValues
/**
* Create a new mat2 with the given values
*
* @param m00 Component in column 0, row 0 position (index 0)
* @param m01 Component in column 0, row 1 position (index 1)
* @param m10 Component in column 1, row 0 position (index 2)
* @param m11 Component in column 1, row 1 position (index 3)
* @returns out A new 2x2 matrix
*/
export function fromValues(m00: number, m01: number, m10: number, m11: number): Mat2;mat2.set
/**
* Set the components of a mat2 to the given values
*
* @param out the receiving matrix
* @param m00 Component in column 0, row 0 position (index 0)
* @param m01 Component in column 0, row 1 position (index 1)
* @param m10 Component in column 1, row 0 position (index 2)
* @param m11 Component in column 1, row 1 position (index 3)
* @returns out
*/
export function set(out: Mat2, m00: number, m01: number, m10: number, m11: number): Mat2;mat2.transpose
/**
* Transpose the values of a mat2
*
* @param out the receiving matrix
* @param a the source matrix
* @returns out
*/
export function transpose(out: Mat2, a: Mat2): Mat2;mat2.invert
/**
* Inverts a mat2
*
* @param out the receiving matrix
* @param a the source matrix
* @returns out, or null if source matrix is not invertible
*/
export function invert(out: Mat2, a: Mat2): Mat2 | null;mat2.adjoint
/**
* Calculates the adjugate of a mat2
*
* @param out the receiving matrix
* @param a the source matrix
* @returns out
*/
export function adjoint(out: Mat2, a: Mat2): Mat2;mat2.determinant
/**
* Calculates the determinant of a mat2
*
* @param a the source matrix
* @returns determinant of a
*/
export function determinant(a: Mat2): number;mat2.multiply
/**
* Multiplies two mat2's
*
* @param out the receiving matrix
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function multiply(out: Mat2, a: Mat2, b: Mat2): Mat2;mat2.rotate
/**
* Rotates a mat2 by the given angle
*
* @param out the receiving matrix
* @param a the matrix to rotate
* @param rad the angle to rotate the matrix by
* @returns out
*/
export function rotate(out: Mat2, a: Mat2, rad: number): Mat2;mat2.scale
/**
* Scales the mat2 by the dimensions in the given vec2
*
* @param out the receiving matrix
* @param a the matrix to rotate
* @param v the vec2 to scale the matrix by
* @returns out
**/
export function scale(out: Mat2, a: Mat2, v: Vec2): Mat2;mat2.fromRotation
/**
* Creates a matrix from a given angle
* This is equivalent to (but much faster than):
*
* mat2.identity(dest);
* mat2.rotate(dest, dest, rad);
*
* @param out mat2 receiving operation result
* @param rad the angle to rotate the matrix by
* @returns out
*/
export function fromRotation(out: Mat2, rad: number): Mat2;mat2.fromScaling
/**
* Creates a matrix from a vector scaling
* This is equivalent to (but much faster than):
*
* mat2.identity(dest);
* mat2.scale(dest, dest, vec);
*
* @param out mat2 receiving operation result
* @param v Scaling vector
* @returns out
*/
export function fromScaling(out: Mat2, v: Vec2): Mat2;mat2.str
/**
* Returns a string representation of a mat2
*
* @param a matrix to represent as a string
* @returns string representation of the matrix
*/
export function str(a: Mat2): string;mat2.frob
/**
* Returns Frobenius norm of a mat2
*
* @param a the matrix to calculate Frobenius norm of
* @returns Frobenius norm
*/
export function frob(a: Mat2): number;mat2.LDU
/**
* Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix
* @param L the lower triangular matrix
* @param D the diagonal matrix
* @param U the upper triangular matrix
* @param a the input matrix to factorize
*/
export function LDU(L: Mat2, D: Mat2, U: Mat2, a: Mat2): [
Mat2,
Mat2,
Mat2
];mat2.add
/**
* Adds two mat2's
*
* @param out the receiving matrix
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function add(out: Mat2, a: Mat2, b: Mat2): Mat2;mat2.subtract
/**
* Subtracts matrix b from matrix a
*
* @param out the receiving matrix
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function subtract(out: Mat2, a: Mat2, b: Mat2): Mat2;mat2.exactEquals
/**
* Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
*
* @param a The first matrix.
* @param b The second matrix.
* @returns True if the matrices are equal, false otherwise.
*/
export function exactEquals(a: Mat2, b: Mat2): boolean;mat2.equals
/**
* Returns whether or not the matrices have approximately the same elements in the same position.
*
* @param a The first matrix.
* @param b The second matrix.
* @returns True if the matrices are equal, false otherwise.
*/
export function equals(a: Mat2, b: Mat2): boolean;mat2.multiplyScalar
/**
* Multiply each element of the matrix by a scalar.
*
* @param out the receiving matrix
* @param a the matrix to scale
* @param b amount to scale the matrix's elements by
* @returns out
*/
export function multiplyScalar(out: Mat2, a: Mat2, b: number): Mat2;mat2.multiplyScalarAndAdd
/**
* Adds two mat2's after multiplying each element of the second operand by a scalar value.
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param scale the amount to scale b's elements by before adding
* @returns out
*/
export function multiplyScalarAndAdd(out: Mat2, a: Mat2, b: Mat2, scale: number): Mat2;mat2.mul
/**
* Alias for {@link mat2.multiply}
*/
export const mul = multiply;mat2.sub
/**
* Alias for {@link mat2.subtract}
*/
export const sub = subtract;mat2d
mat2d.create
/**
* Creates a new identity mat2d
*
* @returns a new 2x3 matrix
*/
export function create(): Mat2d;mat2d.clone
/**
* Creates a new mat2d initialized with values from an existing matrix
*
* @param a matrix to clone
* @returns a new 2x3 matrix
*/
export function clone(a: Mat2d): Mat2d;mat2d.copy
/**
* Copy the values from one mat2d to another
*
* @param out the receiving matrix
* @param a the source matrix
* @returns out
*/
export function copy(out: Mat2d, a: Mat2d): Mat2d;mat2d.identity
/**
* Set a mat2d to the identity matrix
*
* @param out the receiving matrix
* @returns out
*/
export function identity(out: Mat2d): Mat2d;mat2d.fromValues
/**
* Create a new mat2d with the given values
*
* @param a Component A (index 0)
* @param b Component B (index 1)
* @param c Component C (index 2)
* @param d Component D (index 3)
* @param tx Component TX (index 4)
* @param ty Component TY (index 5)
* @returns A new mat2d
*/
export function fromValues(a: number, b: number, c: number, d: number, tx: number, ty: number): Mat2d;mat2d.set
/**
* Set the components of a mat2d to the given values
*
* @param out the receiving matrix
* @param a Component A (index 0)
* @param b Component B (index 1)
* @param c Component C (index 2)
* @param d Component D (index 3)
* @param tx Component TX (index 4)
* @param ty Component TY (index 5)
* @returns out
*/
export function set(out: Mat2d, a: number, b: number, c: number, d: number, tx: number, ty: number): Mat2d;mat2d.invert
/**
* Inverts a mat2d
*
* @param out the receiving matrix
* @param a the source matrix
* @returns out, or null if source matrix is not invertible
*/
export function invert(out: Mat2d, a: Mat2d): Mat2d | null;mat2d.determinant
/**
* Calculates the determinant of a mat2d
*
* @param a the source matrix
* @returns determinant of a
*/
export function determinant(a: Mat2d): number;mat2d.multiply
/**
* Multiplies two mat2d's
*
* @param out the receiving matrix
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function multiply(out: Mat2d, a: Mat2d, b: Mat2d): Mat2d;mat2d.rotate
/**
* Rotates a mat2d by the given angle
*
* @param out the receiving matrix
* @param a the matrix to rotate
* @param rad the angle to rotate the matrix by
* @returns out
*/
export function rotate(out: Mat2d, a: Mat2d, rad: number): Mat2d;mat2d.scale
/**
* Scales the mat2d by the dimensions in the given vec2
*
* @param out the receiving matrix
* @param a the matrix to translate
* @param v the vec2 to scale the matrix by
* @returns out
**/
export function scale(out: Mat2d, a: Mat2d, v: Vec2): Mat2d;mat2d.translate
/**
* Translates the mat2d by the dimensions in the given vec2
*
* @param out the receiving matrix
* @param a the matrix to translate
* @param v the vec2 to translate the matrix by
* @returns out
**/
export function translate(out: Mat2d, a: Mat2d, v: Vec2): Mat2d;mat2d.fromRotation
/**
* Creates a matrix from a given angle
* This is equivalent to (but much faster than):
*
* mat2d.identity(dest);
* mat2d.rotate(dest, dest, rad);
*
* @param out mat2d receiving operation result
* @param rad the angle to rotate the matrix by
* @returns out
*/
export function fromRotation(out: Mat2d, rad: number): Mat2d;mat2d.fromScaling
/**
* Creates a matrix from a vector scaling
* This is equivalent to (but much faster than):
*
* mat2d.identity(dest);
* mat2d.scale(dest, dest, vec);
*
* @param out mat2d receiving operation result
* @param v Scaling vector
* @returns out
*/
export function fromScaling(out: Mat2d, v: Vec2): Mat2d;mat2d.fromTranslation
/**
* Creates a matrix from a vector translation
* This is equivalent to (but much faster than):
*
* mat2d.identity(dest);
* mat2d.translate(dest, dest, vec);
*
* @param out mat2d receiving operation result
* @param v Translation vector
* @returns out
*/
export function fromTranslation(out: Mat2d, v: Vec2): Mat2d;mat2d.str
/**
* Returns a string representation of a mat2d
*
* @param a matrix to represent as a string
* @returns string representation of the matrix
*/
export function str(a: Mat2d): string;mat2d.frob
/**
* Returns Frobenius norm of a mat2d
*
* @param a the matrix to calculate Frobenius norm of
* @returns Frobenius norm
*/
export function frob(a: Mat2d): number;mat2d.add
/**
* Adds two mat2d's
*
* @param out the receiving matrix
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function add(out: Mat2d, a: Mat2d, b: Mat2d): Mat2d;mat2d.subtract
/**
* Subtracts matrix b from matrix a
*
* @param out the receiving matrix
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function subtract(out: Mat2d, a: Mat2d, b: Mat2d): Mat2d;mat2d.multiplyScalar
/**
* Multiply each element of the matrix by a scalar.
*
* @param out the receiving matrix
* @param a the matrix to scale
* @param b amount to scale the matrix's elements by
* @returns out
*/
export function multiplyScalar(out: Mat2d, a: Mat2d, b: number): Mat2d;mat2d.multiplyScalarAndAdd
/**
* Adds two mat2d's after multiplying each element of the second operand by a scalar value.
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param scale the amount to scale b's elements by before adding
* @returns out
*/
export function multiplyScalarAndAdd(out: Mat2d, a: Mat2d, b: Mat2d, scale: number): Mat2d;mat2d.exactEquals
/**
* Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
*
* @param a The first matrix.
* @param b The second matrix.
* @returns True if the matrices are equal, false otherwise.
*/
export function exactEquals(a: Mat2d, b: Mat2d): boolean;mat2d.equals
/**
* Returns whether or not the matrices have approximately the same elements in the same position.
*
* @param a The first matrix.
* @param b The second matrix.
* @returns True if the matrices are equal, false otherwise.
*/
export function equals(a: Mat2d, b: Mat2d): boolean;mat2d.mul
/**
* Alias for {@link mat2d.multiply}
*/
export const mul = multiply;mat2d.sub
/**
* Alias for {@link mat2d.subtract}
*/
export const sub = subtract;mat3
mat3.create
/**
* Creates a new identity mat3
*
* @returns a new 3x3 matrix
*/
export function create(): Mat3;mat3.fromMat4
/**
* Copies the upper-left 3x3 values into the given mat3.
*
* @param out the receiving 3x3 matrix
* @param a the source 4x4 matrix
* @returns out
*/
export function fromMat4(out: Mat3, a: Mat4): Mat3;mat3.clone
/**
* Creates a new mat3 initialized with values from an existing matrix
*
* @param a matrix to clone
* @returns a new 3x3 matrix
*/
export function clone(a: Mat3): Mat3;mat3.copy
/**
* Copy the values from one mat3 to another
*
* @param out the receiving matrix
* @param a the source matrix
* @returns out
*/
export function copy(out: Mat3, a: Mat3): Mat3;mat3.fromValues
/**
* Create a new mat3 with the given values
*
* @param m00 Component in column 0, row 0 position (index 0)
* @param m01 Component in column 0, row 1 position (index 1)
* @param m02 Component in column 0, row 2 position (index 2)
* @param m10 Component in column 1, row 0 position (index 3)
* @param m11 Component in column 1, row 1 position (index 4)
* @param m12 Component in column 1, row 2 position (index 5)
* @param m20 Component in column 2, row 0 position (index 6)
* @param m21 Component in column 2, row 1 position (index 7)
* @param m22 Component in column 2, row 2 position (index 8)
* @returns A new mat3
*/
export function fromValues(m00: number, m01: number, m02: number, m10: number, m11: number, m12: number, m20: number, m21: number, m22: number): Mat3;mat3.set
/**
* Set the components of a mat3 to the given values
*
* @param out the receiving matrix
* @param m00 Component in column 0, row 0 position (index 0)
* @param m01 Component in column 0, row 1 position (index 1)
* @param m02 Component in column 0, row 2 position (index 2)
* @param m10 Component in column 1, row 0 position (index 3)
* @param m11 Component in column 1, row 1 position (index 4)
* @param m12 Component in column 1, row 2 position (index 5)
* @param m20 Component in column 2, row 0 position (index 6)
* @param m21 Component in column 2, row 1 position (index 7)
* @param m22 Component in column 2, row 2 position (index 8)
* @returns out
*/
export function set(out: Mat3, m00: number, m01: number, m02: number, m10: number, m11: number, m12: number, m20: number, m21: number, m22: number): Mat3;mat3.identity
/**
* Set a mat3 to the identity matrix
*
* @param out the receiving matrix
* @returns out
*/
export function identity(out: Mat3): Mat3;mat3.zero
/**
* Set a mat3 to the zero matrix
*
* @param out the receiving matrix
* @returns out
*/
export function zero(out: Mat3): Mat3;mat3.transpose
/**
* Transpose the values of a mat3
*
* @param out the receiving matrix
* @param a the source matrix
* @returns out
*/
export function transpose(out: Mat3, a: Mat3): Mat3;mat3.invert
/**
* Inverts a mat3
*
* @param out the receiving matrix
* @param a the source matrix
* @returns out
*/
export function invert(out: Mat3, a: Mat3): Mat3 | null;mat3.adjoint
/**
* Calculates the adjugate of a mat3
*
* @param out the receiving matrix
* @param a the source matrix
* @returns out
*/
export function adjoint(out: Mat3, a: Mat3): Mat3;mat3.determinant
/**
* Calculates the determinant of a mat3
*
* @param a the source matrix
* @returns determinant of a
*/
export function determinant(a: Mat3): number;mat3.multiply
/**
* Multiplies two mat3's
*
* @param out the receiving matrix
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function multiply(out: Mat3, a: Mat3, b: Mat3): Mat3;mat3.translate
/**
* Translate a mat3 by the given vector
*
* @param out the receiving matrix
* @param a the matrix to translate
* @param v vector to translate by
* @returns out
*/
export function translate(out: Mat3, a: Mat3, v: Vec2): Mat3;mat3.rotate
/**
* Rotates a mat3 by the given angle
*
* @param out the receiving matrix
* @param a the matrix to rotate
* @param rad the angle to rotate the matrix by
* @returns out
*/
export function rotate(out: Mat3, a: Mat3, rad: number): Mat3;mat3.scale
/**
* Scales the mat3 by the dimensions in the given vec2
*
* @param out the receiving matrix
* @param a the matrix to rotate
* @param v the vec2 to scale the matrix by
* @returns out
**/
export function scale(out: Mat3, a: Mat3, v: Vec2): Mat3;mat3.fromTranslation
/**
* Creates a matrix from a vector translation
* This is equivalent to (but much faster than):
*
* mat3.identity(dest);
* mat3.translate(dest, dest, vec);
*
* @param out mat3 receiving operation result
* @param v Translation vector
* @returns out
*/
export function fromTranslation(out: Mat3, v: Vec2): Mat3;mat3.fromRotation
/**
* Creates a matrix from a given angle
* This is equivalent to (but much faster than):
*
* mat3.identity(dest);
* mat3.rotate(dest, dest, rad);
*
* @param out mat3 receiving operation result
* @param rad the angle to rotate the matrix by
* @returns out
*/
export function fromRotation(out: Mat3, rad: number): Mat3;mat3.fromScaling
/**
* Creates a matrix from a vector scaling
* This is equivalent to (but much faster than):
*
* mat3.identity(dest);
* mat3.scale(dest, dest, vec);
*
* @param out mat3 receiving operation result
* @param v Scaling vector
* @returns out
*/
export function fromScaling(out: Mat3, v: Vec2): Mat3;mat3.fromMat2d
/**
* Copies the values from a mat2d into a mat3
*
* @param out the receiving matrix
* @param a the matrix to copy
* @returns out
**/
export function fromMat2d(out: Mat3, a: Mat2d): Mat3;mat3.fromQuat
/**
* Calculates a 3x3 matrix from the given quaternion
*
* @param out mat3 receiving operation result
* @param q Quaternion to create matrix from
*
* @returns out
*/
export function fromQuat(out: Mat3, q: Quat): Mat3;mat3.normalFromMat4
/**
* Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix
*
* @param out mat3 receiving operation result
* @param a Mat4 to derive the normal matrix from
*
* @returns out
*/
export function normalFromMat4(out: Mat3, a: Mat4): Mat3 | null;mat3.projection
/**
* Generates a 2D projection matrix with the given bounds
*
* @param out mat3 frustum matrix will be written into
* @param width Width of your gl context
* @param height Height of gl context
* @returns out
*/
export function projection(out: Mat3, width: number, height: number): Mat3;mat3.str
/**
* Returns a string representation of a mat3
*
* @param a matrix to represent as a string
* @returns string representation of the matrix
*/
export function str(a: Mat3): string;mat3.frob
/**
* Returns Frobenius norm of a mat3
*
* @param a the matrix to calculate Frobenius norm of
* @returns Frobenius norm
*/
export function frob(a: Mat3): number;mat3.add
/**
* Adds two mat3's
*
* @param out the receiving matrix
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function add(out: Mat3, a: Mat3, b: Mat3): Mat3;mat3.subtract
/**
* Subtracts matrix b from matrix a
*
* @param out the receiving matrix
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function subtract(out: Mat3, a: Mat3, b: Mat3): Mat3;mat3.multiplyScalar
/**
* Multiply each element of the matrix by a scalar.
*
* @param out the receiving matrix
* @param a the matrix to scale
* @param b amount to scale the matrix's elements by
* @returns out
*/
export function multiplyScalar(out: Mat3, a: Mat3, b: number): Mat3;mat3.multiplyScalarAndAdd
/**
* Adds two mat3's after multiplying each element of the second operand by a scalar value.
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param scale the amount to scale b's elements by before adding
* @returns out
*/
export function multiplyScalarAndAdd(out: Mat3, a: Mat3, b: Mat3, scale: number): Mat3;mat3.exactEquals
/**
* Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
*
* @param a The first matrix.
* @param b The second matrix.
* @returns True if the matrices are equal, false otherwise.
*/
export function exactEquals(a: Mat3, b: Mat3): boolean;mat3.equals
/**
* Returns whether or not the matrices have approximately the same elements in the same position.
*
* @param a The first matrix.
* @param b The second matrix.
* @returns True if the matrices are equal, false otherwise.
*/
export function equals(a: Mat3, b: Mat3): boolean;mat3.mul
/**
* Alias for {@link mat3.multiply}
* @function
*/
export const mul = multiply;mat3.sub
/**
* Alias for {@link mat3.subtract}
* @function
*/
export const sub = subtract;mat4
mat4.create
/**
* Creates a new identity mat4
*
* @returns a new 4x4 matrix
*/
export function create(): Mat4;mat4.clone
/**
* Creates a new mat4 initialized with values from an existing matrix
*
* @param a matrix to clone
* @returns a new 4x4 matrix
*/
export function clone(a: Mat4): Mat4;mat4.copy
/**
* Copy the values from one mat4 to another
*
* @param out the receiving matrix
* @param a the source matrix
* @returns out
*/
export function copy(out: Mat4, a: Mat4): Mat4;mat4.fromValues
/**
* Create a new mat4 with the given values
*
* @param m00 Component in column 0, row 0 position (index 0)
* @param m01 Component in column 0, row 1 position (index 1)
* @param m02 Component in column 0, row 2 position (index 2)
* @param m03 Component in column 0, row 3 position (index 3)
* @param m10 Component in column 1, row 0 position (index 4)
* @param m11 Component in column 1, row 1 position (index 5)
* @param m12 Component in column 1, row 2 position (index 6)
* @param m13 Component in column 1, row 3 position (index 7)
* @param m20 Component in column 2, row 0 position (index 8)
* @param m21 Component in column 2, row 1 position (index 9)
* @param m22 Component in column 2, row 2 position (index 10)
* @param m23 Component in column 2, row 3 position (index 11)
* @param m30 Component in column 3, row 0 position (index 12)
* @param m31 Component in column 3, row 1 position (index 13)
* @param m32 Component in column 3, row 2 position (index 14)
* @param m33 Component in column 3, row 3 position (index 15)
* @returns A new mat4
*/
export function fromValues(m00: number, m01: number, m02: number, m03: number, m10: number, m11: number, m12: number, m13: number, m20: number, m21: number, m22: number, m23: number, m30: number, m31: number, m32: number, m33: number): Mat4;mat4.set
/**
* Set the components of a mat4 to the given values
*
* @param out the receiving matrix
* @param m00 Component in column 0, row 0 position (index 0)
* @param m01 Component in column 0, row 1 position (index 1)
* @param m02 Component in column 0, row 2 position (index 2)
* @param m03 Component in column 0, row 3 position (index 3)
* @param m10 Component in column 1, row 0 position (index 4)
* @param m11 Component in column 1, row 1 position (index 5)
* @param m12 Component in column 1, row 2 position (index 6)
* @param m13 Component in column 1, row 3 position (index 7)
* @param m20 Component in column 2, row 0 position (index 8)
* @param m21 Component in column 2, row 1 position (index 9)
* @param m22 Component in column 2, row 2 position (index 10)
* @param m23 Component in column 2, row 3 position (index 11)
* @param m30 Component in column 3, row 0 position (index 12)
* @param m31 Component in column 3, row 1 position (index 13)
* @param m32 Component in column 3, row 2 position (index 14)
* @param m33 Component in column 3, row 3 position (index 15)
* @returns out
*/
export function set(out: Mat4, m00: number, m01: number, m02: number, m03: number, m10: number, m11: number, m12: number, m13: number, m20: number, m21: number, m22: number, m23: number, m30: number, m31: number, m32: number, m33: number): Mat4;mat4.identity
/**
* Set a mat4 to the identity matrix
*
* @param out the receiving matrix
* @returns out
*/
export function identity(out: Mat4): Mat4;mat4.zero
/**
* Set a mat4 to the zero matrix
*
* @param out the receiving matrix
* @returns out
*/
export function zero(out: Mat4): Mat4;mat4.transpose
/**
* Transpose the values of a mat4
*
* @param out the receiving matrix
* @param a the source matrix
* @returns out
*/
export function transpose(out: Mat4, a: Mat4): Mat4;mat4.invert
/**
* Inverts a mat4
*
* @param out the receiving matrix
* @param a the source matrix
* @returns out, or null if source matrix is not invertible
*/
export function invert(out: Mat4, a: Mat4): Mat4 | null;mat4.invert3x3
/**
* Inverts only the 3x3 rotation part of a mat4.
* Sets the translation column and bottom row to [0, 0, 0, 1].
* Equivalent to Jolt's Mat44::Inversed3x3()
*
* @param out the receiving matrix
* @param a the source matrix
* @returns out, or null if the 3x3 part is not invertible
*/
export function invert3x3(out: Mat4, a: Mat4): Mat4 | null;mat4.adjoint
/**
* Calculates the adjugate of a mat4
*
* @param out the receiving matrix
* @param a the source matrix
* @returns out
*/
export function adjoint(out: Mat4, a: Mat4): Mat4;mat4.determinant
/**
* Calculates the determinant of a mat4
*
* @param a the source matrix
* @returns determinant of a
*/
export function determinant(a: Mat4): number;mat4.multiply
/**
* Multiplies two mat4s
*
* @param out the receiving matrix
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function multiply(out: Mat4, a: Mat4, b: Mat4): Mat4;mat4.multiply3x3
/**
* Multiplies two mat4s treating them as 3x3 rotation matrices.
* Only computes the upper-left 3x3 portion, sets the 4th column to [0,0,0,1].
* More efficient than full mat4.multiply when working with pure rotations.
*
* @param out the receiving matrix
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function multiply3x3(out: Mat4, a: Mat4, b: Mat4): Mat4;mat4.multiply3x3RightTransposed
/**
* Multiplies a mat4 by the transpose of another mat4,
* treating both as 3x3 rotation matrices.
* Computes: out = a * transpose(b) (3x3 only)
* Sets the 4th column to [0,0,0,1].
*
* @param out the receiving matrix
* @param a the first operand
* @param b the second operand (will be transposed)
* @returns out
*/
export function multiply3x3RightTransposed(out: Mat4, a: Mat4, b: Mat4): Mat4;mat4.multiply3x3TransposedVec
/**
* Transform a Vec3 by the transpose of the 3x3 rotation part.
*
* @param out the receiving vector
* @param mat the matrix to transform with
* @param vec the vector to transform
* @returns out
*/
export function multiply3x3TransposedVec(out: Vec3, mat: Mat4, vec: Vec3): Vec3;mat4.multiply3x3Vec
/**
* Transform a Vec3 by only the 3x3 rotation part of a Mat4.
*
* @param out the receiving vector
* @param mat the matrix to transform with
* @param vec the vector to transform
* @returns out
*/
export function multiply3x3Vec(out: Vec3, mat: Mat4, vec: Vec3): Vec3;mat4.crossProductMatrix
/**
* Cross product matrix (skew-symmetric matrix).
* Equivalent to Jolt's Mat44::sCrossProduct(Vec3Arg)
*
* @param out the receiving matrix
* @param v the vector to create the cross product matrix from
* @returns out
*/
export function crossProductMatrix(out: Mat4, v: Vec3): Mat4;mat4.translate
/**
* Translate a mat4 by the given vector
*
* @param out the receiving matrix
* @param a the matrix to translate
* @param v vector to translate by
* @returns out
*/
export function translate(out: Mat4, a: Mat4, v: Vec3): Mat4;mat4.scale
/**
* Scales the mat4 by the dimensions in the given vec3 not using vectorization
*
* @param out the receiving matrix
* @param a the matrix to scale
* @param v the vec3 to scale the matrix by
* @returns out
**/
export function scale(out: Mat4, a: Mat4, v: Vec3): Mat4;mat4.rotate
/**
* Rotates a mat4 by the given angle around the given axis
*
* @param out the receiving matrix
* @param a the matrix to rotate
* @param rad the angle to rotate the matrix by
* @param axis the axis to rotate around
* @returns out
*/
export function rotate(out: Mat4, a: Mat4, rad: number, axis: Vec3): Mat4 | null;mat4.rotateX
/**
* Rotates a matrix by the given angle around the X axis
*
* @param out the receiving matrix
* @param a the matrix to rotate
* @param rad the angle to rotate the matrix by
* @returns out
*/
export function rotateX(out: Mat4, a: Mat4, rad: number): Mat4;mat4.rotateY
/**
* Rotates a matrix by the given angle around the Y axis
*
* @param out the receiving matrix
* @param a the matrix to rotate
* @param rad the angle to rotate the matrix by
* @returns out
*/
export function rotateY(out: Mat4, a: Mat4, rad: number): Mat4;mat4.rotateZ
/**
* Rotates a matrix by the given angle around the Z axis
*
* @param out the receiving matrix
* @param a the matrix to rotate
* @param rad the angle to rotate the matrix by
* @returns out
*/
export function rotateZ(out: Mat4, a: Mat4, rad: number): Mat4;mat4.fromTranslation
/**
* Creates a matrix from a vector translation
* This is equivalent to (but much faster than):
*
* mat4.identity(dest);
* mat4.translate(dest, dest, vec);
*
* @param out mat4 receiving operation result
* @param v Translation vector
* @returns out
*/
export function fromTranslation(out: Mat4, v: Vec3): Mat4;mat4.fromScaling
/**
* Creates a matrix from a vector scaling
* This is equivalent to (but much faster than):
*
* mat4.identity(dest);
* mat4.scale(dest, dest, vec);
*
* @param out mat4 receiving operation result
* @param v Scaling vector
* @returns out
*/
export function fromScaling(out: Mat4, v: Vec3): Mat4;mat4.fromRotation
/**
* Creates a matrix from a given angle around a given axis
* This is equivalent to (but much faster than):
*
* mat4.identity(dest);
* mat4.rotate(dest, dest, rad, axis);
*
* @param out mat4 receiving operation result
* @param rad the angle to rotate the matrix by
* @param axis the axis to rotate around
* @returns out
*/
export function fromRotation(out: Mat4, rad: number, axis: Vec3): Mat4 | null;mat4.fromXRotation
/**
* Creates a matrix from the given angle around the X axis
* This is equivalent to (but much faster than):
*
* mat4.identity(dest);
* mat4.rotateX(dest, dest, rad);
*
* @param out mat4 receiving operation result
* @param rad the angle to rotate the matrix by
* @returns out
*/
export function fromXRotation(out: Mat4, rad: number): Mat4;mat4.fromYRotation
/**
* Creates a matrix from the given angle around the Y axis
* This is equivalent to (but much faster than):
*
* mat4.identity(dest);
* mat4.rotateY(dest, dest, rad);
*
* @param out mat4 receiving operation result
* @param rad the angle to rotate the matrix by
* @returns out
*/
export function fromYRotation(out: Mat4, rad: number): Mat4;mat4.fromZRotation
/**
* Creates a matrix from the given angle around the Z axis
* This is equivalent to (but much faster than):
*
* mat4.identity(dest);
* mat4.rotateZ(dest, dest, rad);
*
* @param out mat4 receiving operation result
* @param rad the angle to rotate the matrix by
* @returns out
*/
export function fromZRotation(out: Mat4, rad: number): Mat4;mat4.fromRotationTranslation
/**
* Creates a matrix from a quaternion rotation and vector translation
* This is equivalent to (but much faster than):
*
* mat4.identity(dest);
* mat4.translate(dest, dest, vec);
* let quatMat = mat4.create();
* mat4.fromQuat(quatMat, quat);
* mat4.multiply(dest, dest, quatMat);
*
* @param out mat4 receiving operation result
* @param q Rotation quaternion
* @param v Translation vector
* @returns out
*/
export function fromRotationTranslation(out: Mat4, q: Quat | Quat2, v: Vec3): Mat4;mat4.fromQuat2
/**
* Creates a new mat4 from a dual quat.
*
* @param out Matrix
* @param a Dual Quaternion
* @returns mat4 receiving operation result
*/
export function fromQuat2(out: Mat4, a: Quat2): Mat4;mat4.getTranslation
/**
* Returns the translation vector component of a transformation
* matrix. If a matrix is built with fromRotationTranslation,
* the returned vector will be the same as the translation vector
* originally supplied.
* @param out Vector to receive translation component
* @param mat Matrix to be decomposed (input)
* @return out
*/
export function getTranslation(out: Vec3, mat: Mat4): Vec3;mat4.getScaling
/**
* Returns the scaling factor component of a transformation
* matrix. If a matrix is built with fromRotationTranslationScale
* with a normalized Quaternion parameter, the returned vector will be
* the same as the scaling vector
* originally supplied.
* @param out Vector to receive scaling factor component
* @param mat Matrix to be decomposed (input)
* @return out
*/
export function getScaling(out: Vec3, mat: Mat4): Vec3;mat4.getRotation
/**
* Returns a quaternion representing the rotational component
* of a transformation matrix. If a matrix is built with
* fromRotationTranslation, the returned quaternion will be the
* same as the quaternion originally supplied.
* @param out Quaternion to receive the rotation component
* @param mat Matrix to be decomposed (input)
* @return out
*/
export function getRotation(out: Quat, mat: Mat4): Quat;mat4.decompose
/**
* Decomposes a transformation matrix into its rotation, translation
* and scale components. Returns only the rotation component
* @param out_r Quaternion to receive the rotation component
* @param out_t Vector to receive the translation vector
* @param out_s Vector to receive the scaling factor
* @param mat Matrix to be decomposed (input)
* @returns out_r
*/
export function decompose(out_r: Quat, out_t: Vec3, out_s: Vec3, mat: Mat4): Quat;mat4.fromRotationTranslationScale
/**
* Creates a matrix from a quaternion rotation, vector translation and vector scale
* This is equivalent to (but much faster than):
*
* mat4.identity(dest);
* mat4.translate(dest, dest, vec);
* let quatMat = mat4.create();
* mat4.fromQuat(quatMat, quat);
* mat4.multiply(dest, dest, quatMat);
* mat4.scale(dest, dest, scale)
*
* @param out mat4 receiving operation result
* @param q Rotation quaternion
* @param v Translation vector
* @param s Scaling vector
* @returns out
*/
export function fromRotationTranslationScale(out: Mat4, q: Quat, v: Vec3, s: Vec3): Mat4;mat4.fromRotationTranslationScaleOrigin
/**
* Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin
* This is equivalent to (but much faster than):
*
* mat4.identity(dest);
* mat4.translate(dest, dest, vec);
* mat4.translate(dest, dest, origin);
* let quatMat = mat4.create();
* mat4.fromQuat(quatMat, quat);
* mat4.multiply(dest, dest, quatMat);
* mat4.scale(dest, dest, scale)
* mat4.translate(dest, dest, negativeOrigin);
*
* @param out mat4 receiving operation result
* @param q Rotation quaternion
* @param v Translation vector
* @param s Scaling vector
* @param o The origin vector around which to scale and rotate
* @returns out
*/
export function fromRotationTranslationScaleOrigin(out: Mat4, q: Quat, v: Vec3, s: Vec3, o: Vec3): Mat4;mat4.fromQuat
/**
* Calculates a 4x4 matrix from the given quaternion
*
* @param out mat4 receiving operation result
* @param q Quaternion to create matrix from
*
* @returns out
*/
export function fromQuat(out: Mat4, q: Quat): Mat4;mat4.frustum
/**
* Generates a frustum matrix with the given bounds
*
* @param out mat4 frustum matrix will be written into
* @param left Left bound of the frustum
* @param right Right bound of the frustum
* @param bottom Bottom bound of the frustum
* @param top Top bound of the frustum
* @param near Near bound of the frustum
* @param far Far bound of the frustum
* @returns out
*/
export function frustum(out: Mat4, left: number, right: number, bottom: number, top: number, near: number, far: number): Mat4;mat4.perspectiveNO
/**
* Generates a perspective projection matrix with the given bounds.
* The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1],
* which matches WebGL/OpenGL's clip volume.
* Passing null/undefined/no value for far will generate infinite projection matrix.
*
* @param out mat4 frustum matrix will be written into
* @param fovy Vertical field of view in radians
* @param aspect Aspect ratio. typically viewport width/height
* @param near Near bound of the frustum
* @param far Far bound of the frustum, can be null or Infinity
* @returns out
*/
export function perspectiveNO(out: Mat4, fovy: number, aspect: number, near: number, far: number): Mat4;mat4.perspective
/**
* Alias for {@link mat4.perspectiveNO}
* @function
*/
export const perspective = perspectiveNO;mat4.perspectiveZO
/**
* Generates a perspective projection matrix suitable for WebGPU with the given bounds.
* The near/far clip planes correspond to a normalized device coordinate Z range of [0, 1],
* which matches WebGPU/Vulkan/DirectX/Metal's clip volume.
* Passing null/undefined/no value for far will generate infinite projection matrix.
*
* @param out mat4 frustum matrix will be written into
* @param fovy Vertical field of view in radians
* @param aspect Aspect ratio. typically viewport width/height
* @param near Near bound of the frustum
* @param far Far bound of the frustum, can be null or Infinity
* @returns out
*/
export function perspectiveZO(out: Mat4, fovy: number, aspect: number, near: number, far: number): Mat4;mat4.perspectiveFromFieldOfView
/**
* Generates a perspective projection matrix with the given field of view.
* This is primarily useful for generating projection matrices to be used
* with the still experiemental WebVR API.
*
* @param out mat4 frustum matrix will be written into
* @param fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees
* @param near Near bound of the frustum
* @param far Far bound of the frustum
* @returns out
*/
export function perspectiveFromFieldOfView(out: Mat4, fov: {
upDegrees: number;
downDegrees: number;
leftDegrees: number;
rightDegrees: number;
}, near: number, far: number): Mat4;mat4.orthoNO
/**
* Generates a orthogonal projection matrix with the given bounds.
* The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1],
* which matches WebGL/OpenGL's clip volume.
*
* @param out mat4 frustum matrix will be written into
* @param left Left bound of the frustum
* @param right Right bound of the frustum
* @param bottom Bottom bound of the frustum
* @param top Top bound of the frustum
* @param near Near bound of the frustum
* @param far Far bound of the frustum
* @returns out
*/
export function orthoNO(out: Mat4, left: number, right: number, bottom: number, top: number, near: number, far: number): Mat4;mat4.ortho
/**
* Alias for {@link mat4.orthoNO}
* @function
*/
export const ortho = orthoNO;mat4.orthoZO
/**
* Generates a orthogonal projection matrix with the given bounds.
* The near/far clip planes correspond to a normalized device coordinate Z range of [0, 1],
* which matches WebGPU/Vulkan/DirectX/Metal's clip volume.
*
* @param out mat4 frustum matrix will be written into
* @param left Left bound of the frustum
* @param right Right bound of the frustum
* @param bottom Bottom bound of the frustum
* @param top Top bound of the frustum
* @param near Near bound of the frustum
* @param far Far bound of the frustum
* @returns out
*/
export function orthoZO(out: Mat4, left: number, right: number, bottom: number, top: number, near: number, far: number): Mat4;mat4.lookAt
/**
* Generates a look-at matrix with the given eye position, focal point, and up axis.
* If you want a matrix that actually makes an object look at another object, you should use targetTo instead.
*
* @param out mat4 frustum matrix will be written into
* @param eye Position of the viewer
* @param center Point the viewer is looking at
* @param up vec3 pointing up
* @returns out
*/
export function lookAt(out: Mat4, eye: Vec3, center: Vec3, up: Vec3): Mat4;mat4.targetTo
/**
* Generates a matrix that makes something look at something else.
*
* @param out mat4 frustum matrix will be written into
* @param eye Position of the viewer
* @param target Point the viewer is looking at
* @param up vec3 pointing up
* @returns out
*/
export function targetTo(out: Mat4, eye: Vec3, target: Vec3, up: Vec3): Mat4;mat4.str
/**
* Returns a string representation of a mat4
*
* @param a matrix to represent as a string
* @returns {String} string representation of the matrix
*/
export function str(a: Mat4): string;mat4.frob
/**
* Returns Frobenius norm of a mat4
*
* @param a the matrix to calculate Frobenius norm of
* @returns Frobenius norm
*/
export function frob(a: Mat4): number;mat4.add
/**
* Adds two mat4's
*
* @param out the receiving matrix
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function add(out: Mat4, a: Mat4, b: Mat4): Mat4;mat4.subtract
/**
* Subtracts matrix b from matrix a
*
* @param out the receiving matrix
* @param a the first operand
* @param b the second operand
* @returns out
*/
export function subtract(out: Mat4, a: Mat4, b: Mat4): Mat4;mat4.multiplyScalar
/**
* Multiply each element of the matrix by a scalar.
*
* @param out the receiving matrix
* @param a the matrix to scale
* @param b amount to scale the matrix's elements by
* @returns out
*/
export function multiplyScalar(out: Mat4, a: Mat4, b: number): Mat4;mat4.multiplyScalarAndAdd
/**
* Adds two mat4's after multiplying each element of the second operand by a scalar value.
*
* @param out the receiving vector
* @param a the first operand
* @param b the second operand
* @param scale the amount to scale b's elements by before adding
* @returns out
*/
export function multiplyScalarAndAdd(out: Mat4, a: Mat4, b: Mat4, scale: number): Mat4;mat4.exactEquals
/**
* Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
*
* @param a The first matrix.
* @param b The second matrix.
* @returns {Boolean} True if the matrices are equal, false otherwise.
*/
export function exactEquals(a: Mat4, b: Mat4): boolean;mat4.equals
/**
* Returns whether or not the matrices have approximately the same elements in the same position.
*
* @param a The first matrix.
* @param b The second matrix.
* @returns {Boolean} True if the matrices are equal, false otherwise.
*/
export function equals(a: Mat4, b: Mat4): boolean;mat4.mul
/**
* Alias for {@link mat4.multiply}
* @function
*/
export const mul = multiply;mat4.sub
/**
* Alias for {@link mat4.subtract}
* @function
*/
export const sub = subtract;circle
circle.create
export function create(): Circle;segment2
segment2.closestPoint
/**
* Calculates the closest point on a line segment to a given point
* @param out Output parameter for the closest point
* @param point The point
* @param a First endpoint of the segment
* @param b Second endpoint of the segment
*/
export function closestPoint(out: Vec2, point: Vec2, a: Vec2, b: Vec2): Vec2;box3
box3.create
/**
* Create a new empty Box3 with "min" set to positive infinity and "max" set to negative infinity
* @returns A new Box3
*/
export function create(): Box3;box3.clone
/**
* Clones a Box3
* @param box - A Box3 to clone
* @returns a clone of box
*/
export function clone(box: Box3): Box3;box3.copy
/**
* Copies a Box3 to another Box3
* @param out the output Box3
* @param box the input Box3
* @returns the output Box3
*/
export function copy(out: Box3, box: Box3): Box3;box3.set
/**
* Sets the min and max values of a Box3
* @param out - The output Box3
* @param minX - The minimum X coordinate
* @param minY - The minimum Y coordinate
* @param minZ - The minimum Z coordinate
* @param maxX - The maximum X coordinate
* @param maxY - The maximum Y coordinate
* @param maxZ - The maximum Z coordinate
* @returns The updated Box3
*/
export function set(out: Box3, minX: number, minY: number, minZ: number, maxX: number, maxY: number, maxZ: number): Box3;box3.setFromVectors
/**
* Sets the min and max values of a Box3 from Vec3 vectors
* @param out - The output Box3
* @param min - The minimum corner
* @param max - The maximum corner
* @returns The updated Box3
*/
export function setFromVectors(out: Box3, min: Vec3, max: Vec3): Box3;box3.min
/**
* Extracts the minimum corner of a Box3
* @param out - The output Vec3 for the minimum corner
* @param box - The input Box3
* @returns The minimum corner
*/
export function min(out: Vec3, box: Box3): Vec3;box3.max
/**
* Extracts the maximum corner of a Box3
* @param out - The output Vec3 for the maximum corner
* @param box - The input Box3
* @returns The maximum corner
*/
export function max(out: Vec3, box: Box3): Vec3;box3.empty
/**
* Set a Box3 to empty (min to positive infinity, max to negative infinity)
* @param out - The Box3 to make empty
* @returns The emptied Box3
*/
export function empty(out: Box3): Box3;box3.exactEquals
/**
* Returns whether or not the boxes have exactly the same elements in the same position (when compared with ===)
* @param a - The first box
* @param b - The second box
* @returns True if the boxes are equal, false otherwise
*/
export function exactEquals(a: Box3, b: Box3): boolean;box3.equals
/**
* Returns whether or not the boxes have approximately the same elements in the same position
* @param a - The first box
* @param b - The second box
* @returns True if the boxes are equal, false otherwise
*/
export function equals(a: Box3, b: Box3): boolean;box3.setFromCenterAndSize
/**
* Sets the box from a center point and size
* @param out - The output Box3
* @param center - The center point
* @param size - The size of the box
* @returns The updated Box3
*/
export function setFromCenterAndSize(out: Box3, center: Vec3, size: Vec3): Box3;box3.expandByPoint
/**
* Expands a Box3 to include a point
* @param out - The output Box3
* @param box - The input Box3
* @param point - The point to include
* @returns The expanded Box3
*/
export function expandByPoint(out: Box3, box: Box3, point: Vec3): Box3;box3.expandByExtents
/**
* Widens a Box3 by a vector on both sides
* Subtracts the vector from min and adds it to max
* @param out - The output Box3
* @param box - The input Box3
* @param vector - The vector to expand by
* @returns The expanded Box3
*/
export function expandByExtents(out: Box3, box: Box3, vector: Vec3): Box3;box3.expandByMargin
/**
* Expands a Box3 uniformly by a scalar margin on all sides
* Subtracts the margin from min and adds it to max on each axis
* @param out - The output Box3
* @param box - The input Box3
* @param margin - The uniform margin to expand by
* @returns The expanded Box3
*/
export function expandByMargin(out: Box3, box: Box3, margin: number): Box3;box3.union
/**
* Computes the union of two bounding boxes
* Returns a Box3 that encompasses both input boxes
* @param out - The output Box3
* @param boxA - The first Box3
* @param boxB - The second Box3
* @returns The union Box3
*/
export function union(out: Box3, boxA: Box3, boxB: Box3): Box3;box3.center
/**
* Calculate the center point of a bounding box
* @param out - The output Vec3 for the center
* @param box - The input Box3
* @returns The center point
*/
export function center(out: Vec3, box: Box3): Vec3;box3.extents
/**
* Calculate the extents (half-size) of a bounding box
* @param out - The output Vec3 for the extents
* @param box - The input Box3
* @returns The extents (distance from center to each face)
*/
export function extents(out: Vec3, box: Box3): Vec3;box3.size
/**
* Calculate the size (dimensions) of a bounding box
* @param out - The output Vec3 for the size
* @param box - The input Box3
* @returns The size (width, height, depth)
*/
export function size(out: Vec3, box: Box3): Vec3;box3.surfaceArea
/**
* Calculate the surface area of a bounding box
* @param box - The input Box3
* @returns The surface area
*/
export function surfaceArea(box: Box3): number;box3.scale
/**
* Scale a bounding box by a vector, handling non-uniform and negative scaling
* @param out - The output Box3
* @param box - The input Box3
* @param scale - The scale to apply (as a Vec3)
* @returns The scaled Box3
*/
export function scale(out: Box3, box: Box3, scale: Vec3): Box3;box3.transformMat4
/**
* Transform a bounding box by a 4x4 matrix
* Transforms all 8 corners and creates a new AABB that encompasses them
* @param out - The output Box3
* @param box - The input Box3
* @param mat - The 4x4 transformation matrix
* @returns The transformed Box3
*/
export function transformMat4(out: Box3, box: Box3, mat: Mat4): Box3;box3.containsPoint
/**
* Test if a point is contained within the bounding box
* @param box - The bounding box
* @param point - The point to test
* @returns true if the point is inside or on the boundary of the box
*/
export function containsPoint(box: Box3, point: Vec3): boolean;box3.containsBox3
/**
* Test if one Box3 completely contains another Box3
* @param container - The potentially containing Box3
* @param contained - The Box3 that might be contained
* @returns true if the container Box3 completely contains the contained Box3
*/
export function containsBox3(container: Box3, contained: Box3): boolean;box3.intersectsBox3
/**
* Check whether two bounding boxes intersect
*/
export function intersectsBox3(boxA: Box3, boxB: Box3): boolean;box3.intersectsTriangle3
export function intersectsTriangle3(box: Box3, a: Vec3, b: Vec3, c: Vec3): boolean;box3.intersectsSphere
/**
* Test intersection between axis-aligned bounding box and a sphere.
*/
export function intersectsSphere(box: Box3, sphere: Sphere): boolean;box3.intersectsPlane3
/**
* Test intersection between axis-aligned bounding box and plane.
*/
export function intersectsPlane3(box: Box3, plane: Plane3): boolean;obb3
obb3.create
export function create(): OBB3;obb3.clone
export function clone(a: OBB3): OBB3;obb3.copy
export function copy(out: OBB3, a: OBB3): OBB3;obb3.set
/**
* Sets an OBB from center, half extents, and a rotation matrix.
* @param out the OBB to store the result
* @param center the center of the OBB
* @param halfExtents the half extents of the OBB
* @param rotation the Mat3 rotation matrix
* @returns the OBB with the given center, half extents, and rotation
*/
export function set(out: OBB3, center: Vec3, halfExtents: Vec3, rotation: Mat3): OBB3;obb3.setFromCenterHalfExtentsQuaternion
/**
* Sets an OBB from center, half extents, and a quaternion.
* Convenience helper for users who store orientation as a quaternion.
*
* @param out - The OBB to store the result
* @param center - The center of the OBB
* @param halfExtents - The half extents of the OBB
* @param q - The quaternion representing the OBB's orientation
* @returns out
*/
export function setFromCenterHalfExtentsQuaternion(out: OBB3, center: Vec3, halfExtents: Vec3, q: Quat): OBB3;obb3.setFromBox3
/**
* Creates an OBB from an axis-aligned bounding box (AABB).
* The resulting OBB will have the same center and extents as the AABB,
* with no rotation (identity orientation).
*
* @param out - The OBB to store the result
* @param aabb - The AABB (min and max corners)
* @returns out
*/
export function setFromBox3(out: OBB3, aabb: Box3): OBB3;obb3.containsPoint
/**
* Tests whether a point is contained within an OBB.
*
* @param obb - The OBB to test
* @param point - The point to test
* @returns true if the point is inside the OBB
*/
export function containsPoint(obb: OBB3, point: Vec3): boolean;obb3.clampPoint
export function clampPoint(out: Vec3, obb: OBB3, point: Vec3): Vec3;obb3.intersectsOBB3
export function intersectsOBB3(a: OBB3, b: OBB3, epsilon = Number.EPSILON): boolean;obb3.intersectsBox3
/**
* Tests whether an OBB intersects with an AABB.
*
* @param obb - The OBB
* @param aabb - The AABB (axis-aligned bounding box)
* @returns true if they intersect
*/
export function intersectsBox3(obb: OBB3, aabb: Box3): boolean;obb3.applyMatrix4
export function applyMatrix4(out: OBB3, obb: OBB3, matrix: Mat4): OBB3;plane3
plane3.create
/**
* Creates a new plane with normal (0, 1, 0) and constant 0
* @returns A new plane
*/
export function create(): Plane3;plane3.fromNormalAndConstant
/**
* Creates a plane from a normal and constant
* @param out - The output plane
* @param normal - The plane normal (should be unit length)
* @param constant - The signed distance from origin
* @returns The output plane
*/
export function fromNormalAndConstant(out: Plane3, normal: Vec3, constant: number): Plane3;plane3.fromNormalAndPoint
/**
* Creates a plane from a normal and a point on the plane
* @param out - The output plane
* @param normal - The plane normal (should be unit length)
* @param point - A point on the plane
* @returns The output plane
*/
export function fromNormalAndPoint(out: Plane3, normal: Vec3, point: Vec3): Plane3;plane3.fromCoplanarPoints
/**
* Creates a plane from three coplanar points
* @param out - The output plane
* @param a - First point
* @param b - Second point
* @param c - Third point
* @returns The output plane
*/
export function fromCoplanarPoints(out: Plane3, a: Vec3, b: Vec3, c: Vec3): Plane3;plane3.clone
/**
* Clones a plane
* @param plane - The plane to clone
* @returns A new plane
*/
export function clone(plane: Plane3): Plane3;plane3.copy
/**
* Copies one plane to another
* @param out - The output plane
* @param plane - The source plane
* @returns The output plane
*/
export function copy(out: Plane3, plane: Plane3): Plane3;plane3.normalize
/**
* Normalizes a plane (ensures the normal vector is unit length)
* @param out - The output plane
* @param plane - The input plane
* @returns The normalized plane
*/
export function normalize(out: Plane3, plane: Plane3): Plane3;plane3.negate
/**
* Negates a plane (flips the normal and constant)
* @param out - The output plane
* @param plane - The input plane
* @returns The negated plane
*/
export function negate(out: Plane3, plane: Plane3): Plane3;plane3.offset
/**
* Offsets a plane by a distance along its normal
* @param out - The output plane
* @param plane - The input plane
* @param distance - The distance to offset (positive = in direction of normal)
* @returns The offset plane
*/
export function offset(out: Plane3, plane: Plane3, distance: number): Plane3;plane3.distanceToPoint
/**
* Calculates the signed distance from a point to the plane
* @param plane - The plane
* @param point - The point
* @returns The signed distance (positive = in direction of normal)
*/
export function distanceToPoint(plane: Plane3, point: Vec3): number;plane3.projectPoint
/**
* Projects a point onto the plane
* @param out - The output point
* @param plane - The plane
* @param point - The point to project
* @returns The projected point
*/
export function projectPoint(out: Vec3, plane: Plane3, point: Vec3): Vec3;plane3.transform
/**
* Transforms a plane by a 4x4 matrix
* @param out - The output plane
* @param plane - The plane to transform
* @param matrix - The transformation matrix
* @returns The transformed plane
*/
export function transform(out: Plane3, plane: Plane3, matrix: Mat4): Plane3;plane3.intersectsSphere
/**
* Tests if a sphere intersects the plane
* @param plane - The plane
* @param sphere - The sphere
* @returns True if they intersect
*/
export function intersectsSphere(plane: Plane3, sphere: Sphere): boolean;plane3.exactEquals
/**
* Tests if two planes are exactly equal
* @param a - First plane
* @param b - Second plane
* @returns True if planes are exactly equal
*/
export function exactEquals(a: Plane3, b: Plane3): boolean;plane3.intersect
/**
* Finds the intersection point of three planes
* @param p1 - First plane
* @param p2 - Second plane
* @param p3 - Third plane
* @param out - The output point where the three planes intersect
* @returns True if intersection exists, false if planes are degenerate or parallel
*/
export function intersect(p1: Plane3, p2: Plane3, p3: Plane3, out: Vec3): boolean;plane3.equals
/**
* Tests if two planes are equal
* @param a - First plane
* @param b - Second plane
* @returns True if planes are equal
*/
export function equals(a: Plane3, b: Plane3): boolean;sphere
sphere.create
/**
* Creates a new sphere with a default center 0,0,0 and radius 1
* @returns A new sphere.
*/
export function create(): Sphere;triangle3
triangle3.bounds
/**
* Computes the axis-aligned bounding box of a triangle defined by three vertices.
* @param out the output box to store the result.
* @param a the first vertex of the triangle.
* @param b the second vertex of the triangle.
* @param c the third vertex of the triangle.
* @returns the output box containing the axis-aligned bounding box of the triangle.
*/
export function bounds(out: Box3, a: Vec3, b: Vec3, c: Vec3): Box3;triangle3.normal
/**
* Computes the normal vector of a triangle defined by three vertices.
* @param out the output vector to store the result.
* @param a the first vertex of the triangle.
* @param b the second vertex of the triangle.
* @param c the third vertex of the triangle.
* @returns the output vector containing the normal of the triangle.
*/
export function normal(out: Vec3, a: Vec3, b: Vec3, c: Vec3): Vec3;triangle3.centroid
/**
* Computes the centroid of a triangle defined by three vertices.
* @param out the output vector to store the result.
* @param a the first vertex of the triangle.
* @param b the second vertex of the triangle.
* @param c the third vertex of the triangle.
* @returns the output vector containing the centroid of the triangle.
*/
export function centroid(out: Vec3, a: Vec3, b: Vec3, c: Vec3): Vec3;raycast3
raycast3.create
/**
* Creates a new Raycast3 with default values (origin at (0,0,0), direction (0,0,0), length 1.
* @returns A new Raycast3.
*/
export function create(): Raycast3;raycast3.fromValues
/**
* Creates a new Raycast3 from given values.
* @param origin The origin Vec3.
* @param direction The direction Vec3.
* @param length The length of the ray.
* @returns A new Raycast3.
*/
export function fromValues(origin: Vec3, direction: Vec3, length: number): Raycast3;raycast3.set
/**
* Sets the components of a Raycast3.
* @param out The output Raycast3.
* @param origin The origin Vec3.
* @param direction The direction Vec3.
* @param length The length of the ray.
* @returns The output Raycast3.
*/
export function set(out: Raycast3, origin: Vec3, direction: Vec3, length: number): Raycast3;raycast3.copy
/**
* Copies a Raycast3.
* @param out The output Raycast3.
* @param a The input Raycast3.
* @returns The output Raycast3.
*/
export function copy(out: Raycast3, a: Raycast3): Raycast3;raycast3.fromSegment
/**
* Creates a Raycast3 from two points.
* @param out The output Raycast3.
* @param a The starting point.
* @param b The ending point.
* @returns The output Raycast3.
*/
export function fromSegment(out: Raycast3, a: Vec3, b: Vec3): Raycast3;raycast3.IntersectsTriangleResult
/**
* Result of a ray-triangle intersection test
* @see createIntersectsTriangleResult
* @see intersectsTriangle
*/
export type IntersectsTriangleResult = {
fraction: number;
hit: boolean;
frontFacing: boolean;
};raycast3.createIntersectsTriangleResult
/**
* Creates a new IntersectsTriangleResult with default values.
* @returns A new IntersectsTriangleResult.
*/
export function createIntersectsTriangleResult(): IntersectsTriangleResult;raycast3.intersectsTriangle
/**
* Ray-triangle intersection test.
* Based on https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
*
* @param out output object to store result (hit boolean, fraction, frontFacing)
* @param ray ray to test (with origin, direction, and length)
* @param a first vertex of triangle
* @param b second vertex of triangle
* @param c third vertex of triangle
* @param backfaceCulling if true, backfaces will not be considered hits
*/
export function intersectsTriangle(out: IntersectsTriangleResult, ray: Raycast3, a: Vec3, b: Vec3, c: Vec3, backfaceCulling: boolean): void;raycast3.intersectsBox3
/**
* Test if a ray intersects an axis-aligned bounding box.
* Uses slab-based algorithm that handles parallel rays correctly.
*
* @param ray Ray to test (with origin, direction, and length)
* @param aabb AABB to test against
* @returns true if ray intersects the AABB, false otherwise
*/
export function intersectsBox3(ray: Raycast3, aabb: Box3): boolean;quickhull3
quickhull3
/**
* Computes the convex hull of a set of 3D points using an incremental QuickHull algorithm.
*
* @param points An array of numbers representing the 3D points (x1, y1, z1, x2, y2, z2, ...)
* @returns An array of indices representing the triangles of the convex hull (i1, j1, k1, i2, j2, k2, ...).
*/
export function quickhull3(points: number[]): number[];quickhull2
quickhull2
/**
* Computes the convex hull of a set of 2D points using the QuickHull algorithm.
* The hull is returned as an array of indices in counter-clockwise order.
*
* Implementation of pseudocode from: https://en.wikipedia.org/wiki/Quickhull
*
* @param points flat array of 2D points: [x0, y0, x1, y1, ...]
* @returns indices of hull vertices in ccw order
*/
export function quickhull2(points: number[]): number[];circumcircle
circumcircle
/**
* Calculates the circumcircle of three points and stores the center in the output parameter.
* @param out The circle to store the result in
* @param triangle The triangle defined by three points
* @returns
*/
export function circumcircle(out: Circle, a: Vec2, b: Vec2, c: Vec2): Circle;easing
easing.exp
export function exp(t: number);easing.linear
export function linear(t: number);easing.sineIn
export function sineIn(x: number);easing.sineOut
export function sineOut(x: number);easing.sineInOut
export function sineInOut(x: number);easing.cubicIn
export function cubicIn(x: number);easing.cubicOut
export function cubicOut(x: number);easing.cubicInOut
export function cubicInOut(x: number);easing.quintIn
export function quintIn(x: number);easing.quintOut
export function quintOut(x: number);easing.quintInOut
export function quintInOut(x: number);easing.circIn
export function circIn(x: number);easing.circOut
export function circOut(x: number);easing.circInOut
export function circInOut(x: number);easing.quartIn
export function quartIn(t: number);easing.quartOut
export function quartOut(t: number);easing.quartInOut
export function quartInOut(t: number);easing.expoIn
export function expoIn(x: number);easing.expoOut
export function expoOut(x: number);easing.expoInOut
export function expoInOut(x: number);easing.rsqw
export function rsqw(t: number, delta = 0.01, a = 1, f = 1 / (2 * Math.PI));noise
NoiseGenerator2D
export type NoiseGenerator2D = (x: number, y: number) => number;NoiseGenerator3D
export type NoiseGenerator3D = (x: number, y: number, z: number) => number;createSimplex2D
/**
* Creates a 2D simplex noise generator with the given seed
*
* @param seed The seed value for the noise generator
* @returns A function that generates 2D simplex noise values
*/
export function createSimplex2D(seed: number): NoiseGenerator2D;createSimplex3D
/**
* Creates a 3D simplex noise generator with the given seed
*
* @param seed The seed value for the noise generator
* @returns A function that generates 3D simplex noise values
*/
export function createSimplex3D(seed: number): NoiseGenerator3D;createPerlin2D
/**
* Creates a 2D Perlin noise generator with the given seed
*
* @param seed The seed value for the noise generator
* @returns A function that generates 2D Perlin noise values
*/
export function createPerlin2D(seed: number): NoiseGenerator2D;createPerlin3D
/**
* Creates a 3D Perlin noise generator with the given seed
*
* @param seed The seed value for the noise generator
* @returns A function that generates 3D Perlin noise values
*/
export function createPerlin3D(seed: number): NoiseGenerator3D;random
createMulberry32Generator
/**
* Creates a Mulberry32 seeded pseudo-random number generator.
* Mulberry32 is a simple, fast, and effective PRNG that passes statistical tests
* and has good distribution properties.
*
* @param seed The seed value (32-bit integer)
* @returns A function that generates random numbers between 0 and 1
*/
export function createMulberry32Generator(seed: number): () => number;generateMulberry32Seed
/**
* Generates a random seed value.
* This is a 32-bit unsigned integer, suitable for use with the Mulberry32 PRNG.
*/
export function generateMulberry32Seed(): number;randomInt
/**
* Generates a random integer between min and max (inclusive).
* @param min the minimum value (inclusive)
* @param max the maximum value (inclusive)
* @param randomFloat01 the random float in the range [0, 1) to use for randomness. Defaults to Math.random().
* @returns A random integer between min and max (inclusive).
*/
export function randomInt(min: number, max: number, randomFloat01: number = Math.random()): number;randomFloat
/**
* Generates a random float between min and max.
* @param min the minimum value (inclusive)
* @param max the maximum value (inclusive)
* @param randomFloat01 the random float in the range [0, 1) to use for randomness. Defaults to Math.random().
* @returns A random float between min and max.
*/
export function randomFloat(min: number, max: number, randomFloat01: number = Math.random()): number;randomBool
/**
* Generates a random boolean with a given chance of being true.
* @param chance The probability of returning true (between 0 and 1). Defaults to 0.5.
* @param randomFloat01 the random float in the range [0, 1) to use for randomness. Defaults to Math.random().
* @returns A boolean value based on the chance.
*/
export function randomBool(chance = 0.5, randomFloat01: number = Math.random()): boolean;randomSign
/**
* Generates a random sign, either 1 or -1, based on a given chance.
* @param plusChance The probability of returning 1 (between 0 and 1). Defaults to 0.5.
* @param randomFloat01 the random float in the range [0, 1) to use for randomness. Defaults to Math.random().
* @returns A random sign, either 1 or -1.
*/
export function randomSign(plusChance = 0.5, randomFloat01: number = Math.random());randomChoice
/**
* Chooses a random item from an array.
* @param items The array of items to choose from.
* @param randomFloat01 the random float in the range [0, 1) to use for randomness. Defaults to Math.random().
* @returns A randomly chosen item from the array.
* @throws Error if the array is empty.
*/
export function randomChoice<T>(items: T[], randomFloat01: number = Math.random()): T;randomVec2
/**
* Generates a random Vec2 with a scale of 1
*
* @param out the receiving vector
* @param randomFn Function to generate random numbers, defaults to Math.random
* @returns out
*/
export function randomVec2(out: Vec2 = [0, 0], randomFn: () => number = Math.random): Vec2;randomVec3
/**
* Generates a random Vec3 with a scale of 1
*
* @param out the receiving vector
* @param randomFn Function to generate random numbers, defaults to Math.random
* @returns out
*/
export function randomVec3(out: Vec3 = [0, 0, 0], randomFn: () => number = Math.random): Vec3;randomVec4
/**
* Generates a random Vec4 with a scale of 1
*
* @param out the receiving vector
* @param randomFn Function to generate random numbers, defaults to Math.random
* @returns out
*/
export function randomVec4(out: Vec4 = [0, 0, 0, 0], randomFn: () => number = Math.random): Vec4;randomQuat
/**
* Generates a random unit quaternion
*
* @param out the receiving quaternion
* @returns out
*/
export function randomQuat(out: Quat = [0, 0, 0, 0], randomFn: () => number = Math.random): Quat;common
EPSILON
export const EPSILON = 0.000001;round
/**
* Symmetric round
* see https://www.npmjs.com/package/round-half-up-symmetric#user-content-detailed-background
*
* @param a value to round
*/
export function round(a: number): number;degreesToRadians
/**
* Converts Degrees To Radians
*
* @param a Angle in Degrees
*/
export function degreesToRadians(degrees: number): number;radiansToDegrees
/**
* Converts Radians To Degrees
*
* @param a Angle in Radians
*/
export function radiansToDegrees(radians: number): number;equals
/**
* Tests whether or not the arguments have approximately the same value, within an absolute
* or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less
* than or equal to 1.0, and a relative tolerance is used for larger values)
*
* @param a The first number to test.
* @param b The second number to test.
* @returns True if the numbers are approximately equal, false otherwise.
*/
export function equals(a: number, b: number, epsilon = EPSILON): boolean;fade
/**
* Ease-in-out, goes to -Infinite before 0 and Infinite after 1
*
* https://www.desmos.com/calculator/vsnmlaljdu
*
* @param t
* @returns
*/
export function fade(t: number);lerp
/**
*
* Returns the result of linearly interpolating between input A and input B by input T.
*
* @param v0
* @param v1
* @param t
* @returns
*/
export function lerp(v0: number, v1: number, t: number);clamp
/**
* Clamp a value between min and max
*/
export function clamp(value: number, min: number, max: number): number;remap
/**
* Remaps a number from one range to another.
*/
export function remap(number: number, inLow: number, inHigh: number, outLow: number, outHigh: number): number;remapClamp
/**
* Remaps a number from one range to another, clamping the result to the output range.
*/
export function remapClamp(value: number, inLow: number, inHigh: number, outLow: number, outHigh: number): number;On this page
Languages
TypeScript99.9%JavaScript0.1%
Contributors
MIT License
Created July 6, 2025
Updated March 6, 2026
