Matrix toolbox — `Mat3` · `Mat4` · `Vec*` · `Quat`

Auto-generated from bridge/src/js/prelude/src/ on 2026-05-21. Run task gen:api-reference to refresh.

The linear-algebra toolbox (gl-matrix, column-major), available at runtime as the Matrix global. Mat3 is the workhorse for 2-D transforms — its estimateSimilarity / estimateAffine / estimateHomography statics fit a transform to point pairs and return a matrix you can pass straight into img.warpPerspective(). Also includes Mat4, Vec2/Vec3/Vec4, Quat/Quat2, Mat2/Mat2d.

← Back to API Reference index


Classes

Mat2

2x2 Matrix (4 float32)

Extends

  • Float32Array

Indexable

[index: number]: number

Constructors

Constructor
new Mat2(): Mat2;

Creates a new identity mat2

Returns

Mat2

Overrides
Float32Array.constructor

Methods

add()
add(b): this;

Adds two mat2's

Parameters
Parameter Type Description
b ReadonlyMat2 the second operand
Returns

this

this

adjoint()
adjoint(): this;

Calculates the adjugate of a mat2

Returns

this

this

copy()
copy(a): this;

Copy the values from one mat2 to another

Parameters
Parameter Type Description
a ReadonlyMat2 the source matrix
Returns

this

this

determinant()
determinant(): number;

Calculates the determinant of a mat2

Returns

number

determinant of this

equals()
equals(b): boolean;

Returns whether or not the matrices have approximately the same elements in the same position.

Parameters
Parameter Type Description
b ReadonlyMat2 The second matrix.
Returns

boolean

True if the matrices are equal, false otherwise.

exactEquals()
exactEquals(b): boolean;

Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)

Parameters
Parameter Type Description
b ReadonlyMat2 The second matrix.
Returns

boolean

True if the matrices are equal, false otherwise.

frob()
frob(): number;

Returns Frobenius norm of a mat2

Returns

number

Frobenius norm

fromRotation()
fromRotation(rad): this;

Creates a matrix from a given angle

Parameters
Parameter Type Description
rad number the angle to rotate the matrix by
Returns

this

this

fromScaling()
fromScaling(v): this;

Creates a matrix from a vector scaling

Parameters
Parameter Type Description
v ReadonlyVec2 Scaling vector
Returns

this

this

identity()
identity(): this;

Set a mat2 to the identity matrix

Returns

this

this

invert()
invert(): Mat2 | null;

Inverts a mat2

Returns

Mat2 | null

this, or null if source matrix is not invertible

LDU()
LDU(
   L, 
   D, 
   U): [mat2, mat2, mat2];

Returns L, D and U matrices (Lower triangular, Diagonal and Upper triangular) by factorizing the input matrix

Parameters
Parameter Type Description
L mat2 the lower triangular matrix
D mat2 the diagonal matrix
U mat2 the upper triangular matrix
Returns

[mat2, mat2, mat2]

multiply()
multiply(b): this;

Multiplies two mat2's

Parameters
Parameter Type Description
b ReadonlyMat2 the second operand
Returns

this

this

multiplyScalar()
multiplyScalar(b): this;

Multiply each element of the matrix by a scalar.

Parameters
Parameter Type Description
b number amount to scale the matrix's elements by
Returns

this

this

multiplyScalarAndAdd()
multiplyScalarAndAdd(b, scale): this;

Adds two mat2's after multiplying each element of the second operand by a scalar value.

Parameters
Parameter Type Description
b ReadonlyMat2 the second operand
scale number the amount to scale b's elements by before adding
Returns

this

this

rotate()
rotate(rad): this;

Rotates a mat2 by the given angle

Parameters
Parameter Type Description
rad number the angle to rotate the matrix by
Returns

this

this

scale()
scale(v): this;

Scales the mat2 by the dimensions in the given vec2

Parameters
Parameter Type Description
v ReadonlyVec2 the vec2 to scale the matrix by
Returns

this

this

setValues()
setValues(
   m00, 
   m01, 
   m10, 
   m11): this;

Set the components of a mat2 to the given values

Parameters
Parameter Type
m00 number
m01 number
m10 number
m11 number
Returns

this

this

str()
str(): string;

Returns a string representation of a mat2

Returns

string

string representation of the matrix

subtract()
subtract(b): this;

Subtracts matrix b from this

Parameters
Parameter Type Description
b ReadonlyMat2 the second operand
Returns

this

this

transpose()
transpose(): this;

Transpose the values of a mat2

Returns

this

this

clone()
static clone(a): Mat2;

Creates a new mat2 initialized with values from an existing matrix

Parameters
Parameter Type Description
a ReadonlyMat2 matrix to clone
Returns

Mat2

a new 2x2 matrix

fromValues()
static fromValues(
   m00, 
   m01, 
   m10, 
   m11): Mat2;

Create a new mat2 with the given values

Parameters
Parameter Type
m00 number
m01 number
m10 number
m11 number
Returns

Mat2

A new mat2

Mat2d

2x3 Matrix

A mat2d contains six elements defined as:

This is a short form for the 3x3 matrix:

Extends

  • Float32Array

Indexable

[index: number]: number

Constructors

Constructor
new Mat2d(): Mat2d;

Creates a new identity mat2d

Returns

Mat2d

Overrides
Float32Array.constructor

Methods

add()
add(b): this;

Adds two mat2d's

Parameters
Parameter Type Description
b ReadonlyMat2d the second operand
Returns

this

this

copy()
copy(a): this;

Copy the values from one mat2d to another

Parameters
Parameter Type Description
a ReadonlyMat2d the source matrix
Returns

this

this

determinant()
determinant(): number;

Calculates the determinant of a mat2d

Returns

number

determinant of this

equals()
equals(b): boolean;

Returns whether or not the matrices have approximately the same elements in the same position.

Parameters
Parameter Type Description
b ReadonlyMat2d The second matrix.
Returns

boolean

True if the matrices are equal, false otherwise.

exactEquals()
exactEquals(b): boolean;

Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)

Parameters
Parameter Type Description
b ReadonlyMat2d The second matrix.
Returns

boolean

True if the matrices are equal, false otherwise.

frob()
frob(): number;

Returns Frobenius norm of a mat2d

Returns

number

Frobenius norm

fromRotation()
fromRotation(rad): this;

Creates a matrix from a given angle

Parameters
Parameter Type Description
rad number the angle to rotate the matrix by
Returns

this

this

fromScaling()
fromScaling(v): this;

Creates a matrix from a vector scaling

Parameters
Parameter Type Description
v ReadonlyVec2 Scaling vector
Returns

this

this

fromTranslation()
fromTranslation(v): this;

Creates a matrix from a vector translation

Parameters
Parameter Type Description
v ReadonlyVec2 Translation vector
Returns

this

this

identity()
identity(): this;

Set a mat2d to the identity matrix

Returns

this

this

invert()
invert(): Mat2d | null;

Inverts a mat2d

Returns

Mat2d | null

this, or null if source matrix is not invertible

multiply()
multiply(b): this;

Multiplies two mat2d's

Parameters
Parameter Type Description
b ReadonlyMat2d the second operand
Returns

this

this

multiplyScalar()
multiplyScalar(b): this;

Multiply each element of the matrix by a scalar.

Parameters
Parameter Type Description
b number amount to scale the matrix's elements by
Returns

this

this

multiplyScalarAndAdd()
multiplyScalarAndAdd(b, scale): this;

Adds two mat2d's after multiplying each element of the second operand by a scalar value.

Parameters
Parameter Type Description
b ReadonlyMat2d the second operand
scale number the amount to scale b's elements by before adding
Returns

this

this

rotate()
rotate(rad): this;

Rotates a mat2d by the given angle

Parameters
Parameter Type Description
rad number the angle to rotate the matrix by
Returns

this

this

scale()
scale(v): this;

Scales the mat2d by the dimensions in the given vec2

Parameters
Parameter Type Description
v ReadonlyVec2 the vec2 to scale the matrix by
Returns

this

this

setValues()
setValues(
   a, 
   b, 
   c, 
   d, 
   tx, 
   ty): this;

Set the components of a mat2d to the given values

Parameters
Parameter Type
a number
b number
c number
d number
tx number
ty number
Returns

this

this

str()
str(): string;

Returns a string representation of a mat2d

Returns

string

string representation of the matrix

subtract()
subtract(b): this;

Subtracts matrix b from this

Parameters
Parameter Type Description
b ReadonlyMat2d the second operand
Returns

this

this

translate()
translate(v): this;

Translates the mat2d by the dimensions in the given vec2

Parameters
Parameter Type Description
v ReadonlyVec2 the vec2 to translate the matrix by
Returns

this

this

clone()
static clone(a): Mat2d;

Creates a new mat2d initialized with values from an existing matrix

Parameters
Parameter Type Description
a ReadonlyMat2d matrix to clone
Returns

Mat2d

a new 2x3 matrix

fromValues()
static fromValues(
   a, 
   b, 
   c, 
   d, 
   tx, 
   ty): Mat2d;

Create a new mat2d with the given values

Parameters
Parameter Type
a number
b number
c number
d number
tx number
ty number
Returns

Mat2d

A new mat2d


Mat3

3x3 Matrix.

Storage layout — read this once

Mat3 is column-major (the gl-matrix convention). The flat 9-element backing array stores columns, not rows:

  index:   0  1  2   3  4  5   6  7  8
  column:  └ col 0 ┘ └ col 1 ┘ └ col 2 ┘

The logical transform it represents — the one that actually moves a point — maps a 2-D point (x, y) to (x', y') like this:

  x' = m[0]·x + m[3]·y + m[6]
  y' = m[1]·x + m[4]·y + m[7]

So translation (tx, ty) lives at indices 6 and 7, not 2 and 5. That surprises everyone coming from a row-major / textbook background — it is correct and consistent across every gl-matrix type here.

Talking to the engine

The Rust image ops (warpPerspective, stampAt) speak row-major src→dst. You never convert by hand: pass a Mat3 straight into img.warpPerspective(...) and the prelude transposes it for you. The Mat3.estimateSimilarity, Mat3.estimateAffine and Mat3.estimateHomography fitters return ready-to-use Mat3 instances representing the src→dst forward transform.

Extends

  • Float32Array

Indexable

[index: number]: number

Constructors

Constructor
new Mat3(): Mat3;

Creates a new identity mat3

Returns

Mat3

Overrides
Float32Array.constructor

Methods

add()
add(b): this;

Adds two mat3's

Parameters
Parameter Type Description
b ReadonlyMat3 the second operand
Returns

this

this

adjoint()
adjoint(): this;

Calculates the adjugate of a mat3

Returns

this

this

copy()
copy(a): this;

Copy the values from one mat3 to another

Parameters
Parameter Type Description
a ReadonlyMat3 the source matrix
Returns

this

this

determinant()
determinant(): number;

Calculates the determinant of a mat3

Returns

number

determinant of this

equals()
equals(b): boolean;

Returns whether or not the matrices have approximately the same elements in the same position.

Parameters
Parameter Type Description
b ReadonlyMat3 The second matrix.
Returns

boolean

True if the matrices are equal, false otherwise.

exactEquals()
exactEquals(b): boolean;

Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)

Parameters
Parameter Type Description
b ReadonlyMat3 The second matrix.
Returns

boolean

True if the matrices are equal, false otherwise.

frob()
frob(): number;

Returns Frobenius norm of a mat3

Returns

number

Frobenius norm

fromMat2d()
fromMat2d(a): this;

Copies the values from a mat2d into a mat3

Parameters
Parameter Type Description
a ReadonlyMat2d the matrix to copy
Returns

this

this

fromQuat()
fromQuat(q): this;

Calculates a 3x3 matrix from the given quaternion

Parameters
Parameter Type Description
q ReadonlyQuat Quaternion to create matrix from
Returns

this

this

fromRotation()
fromRotation(rad): this;

Creates a matrix from a given angle

Parameters
Parameter Type Description
rad number the angle to rotate the matrix by
Returns

this

this

fromScaling()
fromScaling(v): this;

Creates a matrix from a vector scaling

Parameters
Parameter Type Description
v ReadonlyVec2 Scaling vector
Returns

this

this

fromTranslation()
fromTranslation(v): this;

Creates a matrix from a vector translation

Parameters
Parameter Type Description
v ReadonlyVec2 Translation vector
Returns

this

this

identity()
identity(): this;

Set a mat3 to the identity matrix

Returns

this

this

invert()
invert(): Mat3 | null;

Inverts a mat3

Returns

Mat3 | null

this, or null if source matrix is not invertible

multiply()
multiply(b): this;

Multiplies two mat3's

Parameters
Parameter Type Description
b ReadonlyMat3 the second operand
Returns

this

this

multiplyScalar()
multiplyScalar(b): this;

Multiply each element of the matrix by a scalar.

Parameters
Parameter Type Description
b number amount to scale the matrix's elements by
Returns

this

this

multiplyScalarAndAdd()
multiplyScalarAndAdd(b, scale): this;

Adds two mat3's after multiplying each element of the second operand by a scalar value.

Parameters
Parameter Type Description
b ReadonlyMat3 the second operand
scale number the amount to scale b's elements by before adding
Returns

this

this

normalFromMat4()
normalFromMat4(a): Mat3 | null;

Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix

Parameters
Parameter Type Description
a ReadonlyMat4 Mat4 to derive the normal matrix from
Returns

Mat3 | null

this

projection()
projection(width, height): this;

Generates a 2D projection matrix with the given bounds

Parameters
Parameter Type Description
width number Width of your gl context
height number Height of gl context
Returns

this

this

rotate()
rotate(rad): this;

Rotates a mat3 by the given angle

Parameters
Parameter Type Description
rad number the angle to rotate the matrix by
Returns

this

this

scale()
scale(v): this;

Scales the mat3 by the dimensions in the given vec2

Parameters
Parameter Type Description
v ReadonlyVec2 the vec2 to scale the matrix by
Returns

this

this

setValues()
setValues(
   m00, 
   m01, 
   m02, 
   m10, 
   m11, 
   m12, 
   m20, 
   m21, 
   m22): this;

Set the components of a mat3 to the given values

Parameters
Parameter Type
m00 number
m01 number
m02 number
m10 number
m11 number
m12 number
m20 number
m21 number
m22 number
Returns

this

this

str()
str(): string;

Returns a string representation of a mat3

Returns

string

string representation of the matrix

subtract()
subtract(b): this;

Subtracts matrix b from this

Parameters
Parameter Type Description
b ReadonlyMat3 the second operand
Returns

this

this

toRowMajor()
toRowMajor(): number[];

Export this matrix as a row-major flat array [a, b, c, d, e, f, g, h, i] — the layout the Rust engine ops (warpPerspective, stampAt) expect.

You rarely need this directly: img.warpPerspective(w, h, mat3) accepts a Mat3 and calls this for you.

Returns

number[]

translate()
translate(v): this;

Translate a mat3 by the given vector

Parameters
Parameter Type Description
v ReadonlyVec2 vector to translate by
Returns

this

this

transpose()
transpose(): this;

Transpose the values of a mat3

Returns

this

this

clone()
static clone(a): Mat3;

Creates a new mat3 initialized with values from an existing matrix

Parameters
Parameter Type Description
a ReadonlyMat3 matrix to clone
Returns

Mat3

a new 3x3 matrix

estimateAffine()
static estimateAffine(srcPts, dstPts): Mat3;

Fit a full affine transform (scale + rotation + shear + translation — 6 DOF) to corresponding point pairs.

Solved via least-squares; needs ≥ 3 pairs. The returned Mat3 is the src→dst forward transform. Unlike Mat3.estimateSimilarity this allows non-uniform scale and shear, so parallel lines stay parallel but angles may change.

Parameters
Parameter Type Description
srcPts readonly PointPair[] Source points, each [x, y].
dstPts readonly PointPair[] Destination points, each [x, y]. Must match srcPts length.
Returns

Mat3

A new Mat3 (src→dst forward transform).

Throws

If the lists differ in length, have < 3 pairs, or the points are collinear (degenerate).

estimateHomography()
static estimateHomography(srcPts, dstPts): Mat3;

Fit a perspective homography (8 DOF) to corresponding point pairs.

Needs ≥ 4 pairs — exactly 4 gives an exact fit, more gives a least-squares fit. Coordinates are normalised internally so the solve stays stable even for large images (> 1000 px). The returned Mat3 is the src→dst forward transform.

This is the general case: it can represent any straight-line- preserving warp, including keystone / perspective distortion.

Parameters
Parameter Type Description
srcPts readonly PointPair[] Source points, each [x, y].
dstPts readonly PointPair[] Destination points, each [x, y]. Must match srcPts length.
Returns

Mat3

A new Mat3 (src→dst forward transform).

Example
const src = [[0,0],[w,0],[w,h],[0,h]];
const H = Matrix.Mat3.estimateHomography(src, dstQuad);
img.warpPerspective(canvasW, canvasH, H);
Throws

If the lists differ in length, have < 4 pairs, or the points are degenerate (collinear / coincident).

estimateSimilarity()
static estimateSimilarity(srcPts, dstPts): Mat3;

Fit a similarity transform (uniform scale + rotation + translation — 4 DOF, no shear) to corresponding point pairs.

Solved via Procrustes least-squares; needs ≥ 2 pairs (more pairs → best-fit average). The returned Mat3 is the src→dst forward transform — feed it straight to img.warpPerspective(...), or call .invert() for dst→src.

Parameters
Parameter Type Description
srcPts readonly PointPair[] Source points, each [x, y].
dstPts readonly PointPair[] Destination points, each [x, y]. Must match srcPts length.
Returns

Mat3

A new Mat3 (src→dst forward transform).

Example
const fwd = Matrix.Mat3.estimateSimilarity(faceLandmarks, TEMPLATE);
const aligned = orig.clone().warpPerspective(512, 512, fwd);
const backToOrig = Matrix.Mat3.clone(fwd).invert();
Throws

If the lists differ in length, have < 2 pairs, or the source points are coincident (degenerate).

fromValues()
static fromValues(
   m00, 
   m01, 
   m02, 
   m10, 
   m11, 
   m12, 
   m20, 
   m21, 
   m22): Mat3;

Create a new mat3 with the given values

Parameters
Parameter Type
m00 number
m01 number
m02 number
m10 number
m11 number
m12 number
m20 number
m21 number
m22 number
Returns

Mat3

A new mat3


Mat4

4x4 Matrix

Extends

  • Float32Array

Indexable

[index: number]: number

Constructors

Constructor
new Mat4(): Mat4;

Creates a new identity mat4

Returns

Mat4

Overrides
Float32Array.constructor

Methods

add()
add(b): this;

Adds two mat4's

Parameters
Parameter Type Description
b ReadonlyMat4 the second operand
Returns

this

this

adjoint()
adjoint(): this;

Calculates the adjugate of a mat4

Returns

this

this

copy()
copy(a): this;

Copy the values from one mat4 to another

Parameters
Parameter Type Description
a ReadonlyMat4 the source matrix
Returns

this

this

decompose()
decompose(
   out_r, 
   out_t, 
   out_s): quat;

Decomposes a transformation matrix into its rotation, translation and scale components.

Parameters
Parameter Type Description
out_r quat Quaternion to receive the rotation component
out_t vec3 Vector to receive the translation vector
out_s vec3 Vector to receive the scaling factor
Returns

quat

out_r

determinant()
determinant(): number;

Calculates the determinant of a mat4

Returns

number

determinant of a

equals()
equals(b): boolean;

Returns whether or not the matrices have approximately the same elements in the same position.

Parameters
Parameter Type Description
b ReadonlyMat4 The second matrix.
Returns

boolean

True if the matrices are equal, false otherwise.

exactEquals()
exactEquals(b): boolean;

Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)

Parameters
Parameter Type Description
b ReadonlyMat4 The second matrix.
Returns

boolean

True if the matrices are equal, false otherwise.

frob()
frob(): number;

Returns Frobenius norm of a mat4

Returns

number

Frobenius norm

fromQuat()
fromQuat(q): this;

Calculates a 4x4 matrix from the given quaternion

Parameters
Parameter Type Description
q ReadonlyQuat Quaternion to create matrix from
Returns

this

this

fromQuat2()
fromQuat2(a): this;

Creates a new mat4 from a dual quat.

Parameters
Parameter Type Description
a ReadonlyQuat2 Dual Quaternion
Returns

this

this

fromRotation()
fromRotation(rad, axis): Mat4 | null;

Creates a matrix from a given angle around a given axis

Parameters
Parameter Type Description
rad number the angle to rotate the matrix by
axis ReadonlyVec3 the axis to rotate around
Returns

Mat4 | null

this

fromRotationTranslation()
fromRotationTranslation(q, v): this;

Creates a matrix from a quaternion rotation and vector translation

Parameters
Parameter Type Description
q ReadonlyQuat Rotation quaternion
v ReadonlyVec3 Translation vector
Returns

this

this

fromRotationTranslationScale()
fromRotationTranslationScale(
   q, 
   v, 
   s): this;

Creates a matrix from a quaternion rotation, vector translation and vector scale

Parameters
Parameter Type Description
q ReadonlyQuat Rotation quaternion
v ReadonlyVec3 Translation vector
s ReadonlyVec3 Scaling vector
Returns

this

this

fromRotationTranslationScaleOrigin()
fromRotationTranslationScaleOrigin(
   q, 
   v, 
   s, 
   o): this;

Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin

Parameters
Parameter Type Description
q ReadonlyQuat Rotation quaternion
v ReadonlyVec3 Translation vector
s ReadonlyVec3 Scaling vector
o ReadonlyVec3 The origin vector around which to scale and rotate
Returns

this

this

fromScaling()
fromScaling(v): this;

Creates a matrix from a vector scaling

Parameters
Parameter Type Description
v ReadonlyVec3 Scaling vector
Returns

this

this

fromTranslation()
fromTranslation(v): this;

Creates a matrix from a vector translation

Parameters
Parameter Type Description
v ReadonlyVec3 Translation vector
Returns

this

this

fromXRotation()
fromXRotation(rad): this;

Creates a matrix from the given angle around the X axis

Parameters
Parameter Type Description
rad number the angle to rotate the matrix by
Returns

this

this

fromYRotation()
fromYRotation(rad): this;

Creates a matrix from the given angle around the Y axis

Parameters
Parameter Type Description
rad number the angle to rotate the matrix by
Returns

this

this

fromZRotation()
fromZRotation(rad): this;

Creates a matrix from the given angle around the Z axis

Parameters
Parameter Type Description
rad number the angle to rotate the matrix by
Returns

this

this

frustum()
frustum(
   left, 
   right, 
   bottom, 
   top, 
   near, 
   far): this;

Generates a frustum matrix with the given bounds

Parameters
Parameter Type
left number
right number
bottom number
top number
near number
far number
Returns

this

this

getRotation()
getRotation(out): quat;

Returns a quaternion representing the rotational component of a transformation matrix.

Parameters
Parameter Type Description
out quat Quaternion to receive the rotation component
Returns

quat

out

getScaling()
getScaling(out): vec3;

Returns the scaling factor component of a transformation matrix.

Parameters
Parameter Type Description
out vec3 Vector to receive scaling factor component
Returns

vec3

out

getTranslation()
getTranslation(out): vec3;

Returns the translation vector component of a transformation matrix.

Parameters
Parameter Type Description
out vec3 Vector to receive translation component
Returns

vec3

out

identity()
identity(): this;

Set a mat4 to the identity matrix

Returns

this

this

invert()
invert(): Mat4 | null;

Inverts a mat4

Returns

Mat4 | null

this, or null if source matrix is not invertible

lookAt()
lookAt(
   eye, 
   center, 
   up): this;

Generates a look-at matrix with the given eye position, focal point, and up axis.

Parameters
Parameter Type
eye ReadonlyVec3
center ReadonlyVec3
up ReadonlyVec3
Returns

this

this

multiply()
multiply(b): this;

Multiplies two mat4s

Parameters
Parameter Type Description
b ReadonlyMat4 the second operand
Returns

this

this

multiplyScalar()
multiplyScalar(b): this;

Multiply each element of the matrix by a scalar.

Parameters
Parameter Type Description
b number amount to scale the matrix's elements by
Returns

this

this

multiplyScalarAndAdd()
multiplyScalarAndAdd(b, scale): this;

Adds two mat4's after multiplying each element of the second operand by a scalar value.

Parameters
Parameter Type Description
b ReadonlyMat4 the second operand
scale number the amount to scale b's elements by before adding
Returns

this

this

orthoNO()
orthoNO(
   left, 
   right, 
   bottom, 
   top, 
   near, 
   far): this;

Generates a orthogonal projection matrix with the given bounds.

Parameters
Parameter Type
left number
right number
bottom number
top number
near number
far number
Returns

this

this

orthoZO()
orthoZO(
   left, 
   right, 
   bottom, 
   top, 
   near, 
   far): this;

Generates a orthogonal projection matrix with the given bounds.

Parameters
Parameter Type
left number
right number
bottom number
top number
near number
far number
Returns

this

this

perspectiveFromFieldOfView()
perspectiveFromFieldOfView(
   fov, 
   near, 
   far): this;

Generates a perspective projection matrix with the given field of view.

Parameters
Parameter Type
fov { downDegrees: number; leftDegrees: number; rightDegrees: number; upDegrees: number; }
fov.downDegrees number
fov.leftDegrees number
fov.rightDegrees number
fov.upDegrees number
near number
far number
Returns

this

this

perspectiveNO()
perspectiveNO(
   fovy, 
   aspect, 
   near, 
   far?): this;

Generates a perspective projection matrix with the given bounds.

Parameters
Parameter Type Default value
fovy number undefined
aspect number undefined
near number undefined
far number | null null
Returns

this

this

perspectiveZO()
perspectiveZO(
   fovy, 
   aspect, 
   near, 
   far?): this;

Generates a perspective projection matrix suitable for WebGPU with the given bounds.

Parameters
Parameter Type Default value
fovy number undefined
aspect number undefined
near number undefined
far number | null null
Returns

this

this

rotate()
rotate(rad, axis): Mat4 | null;

Rotates a mat4 by the given angle around the given axis

Parameters
Parameter Type Description
rad number the angle to rotate the matrix by
axis ReadonlyVec3 the axis to rotate around
Returns

Mat4 | null

this

rotateX()
rotateX(rad): this;

Rotates a matrix by the given angle around the X axis

Parameters
Parameter Type Description
rad number the angle to rotate the matrix by
Returns

this

this

rotateY()
rotateY(rad): this;

Rotates a matrix by the given angle around the Y axis

Parameters
Parameter Type Description
rad number the angle to rotate the matrix by
Returns

this

this

rotateZ()
rotateZ(rad): this;

Rotates a matrix by the given angle around the Z axis

Parameters
Parameter Type Description
rad number the angle to rotate the matrix by
Returns

this

this

scale()
scale(v): this;

Scales the mat4 by the dimensions in the given vec3

Parameters
Parameter Type Description
v ReadonlyVec3 the vec3 to scale the matrix by
Returns

this

this

str()
str(): string;

Returns a string representation of a mat4

Returns

string

string representation of the matrix

subtract()
subtract(b): this;

Subtracts matrix b from this

Parameters
Parameter Type Description
b ReadonlyMat4 the second operand
Returns

this

this

targetTo()
targetTo(
   eye, 
   target, 
   up): this;

Generates a matrix that makes something look at something else.

Parameters
Parameter Type
eye ReadonlyVec3
target ReadonlyVec3
up ReadonlyVec3
Returns

this

this

translate()
translate(v): this;

Translate a mat4 by the given vector

Parameters
Parameter Type Description
v ReadonlyVec3 vector to translate by
Returns

this

this

transpose()
transpose(): this;

Transpose the values of a mat4

Returns

this

this

clone()
static clone(a): Mat4;

Creates a new mat4 initialized with values from an existing matrix

Parameters
Parameter Type Description
a ReadonlyMat4 matrix to clone
Returns

Mat4

a new 4x4 matrix

fromValues()
static fromValues(
   m00, 
   m01, 
   m02, 
   m03, 
   m10, 
   m11, 
   m12, 
   m13, 
   m20, 
   m21, 
   m22, 
   m23, 
   m30, 
   m31, 
   m32, 
   m33): Mat4;

Create a new mat4 with the given values

Parameters
Parameter Type
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
Returns

Mat4

A new mat4


Quat

Quaternion

Extends

Indexable

[index: number]: number

Accessors

w
Get Signature
get w(): number;

W component

Returns

number

Set Signature
set w(v): void;
Parameters
Parameter Type
v number
Returns

void

Inherited from

Vec4.w

x
Get Signature
get x(): number;

X component

Returns

number

Set Signature
set x(v): void;
Parameters
Parameter Type
v number
Returns

void

Inherited from

Vec4.x

y
Get Signature
get y(): number;

Y component

Returns

number

Set Signature
set y(v): void;
Parameters
Parameter Type
v number
Returns

void

Inherited from

Vec4.y

z
Get Signature
get z(): number;

Z component

Returns

number

Set Signature
set z(v): void;
Parameters
Parameter Type
v number
Returns

void

Inherited from

Vec4.z

Constructors

Constructor
new Quat(): Quat;

Creates a new identity quat

Returns

Quat

Overrides

Vec4.constructor

Methods

add()
add(b): this;

Adds another vec4 to this

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
Returns

this

this

Inherited from

Vec4.add

calculateW()
calculateW(): this;

Calculates the W component from the X, Y, and Z components.

Returns

this

this

ceil()
ceil(): this;

Math.ceil the components of this vec4

Returns

this

this

Inherited from

Vec4.ceil

conjugate()
conjugate(): this;

Calculates the conjugate of a quat

Returns

this

this

copy()
copy(a): this;

Copy the values from one vec4 to another

Parameters
Parameter Type Description
a ReadonlyVec4 the source vector
Returns

this

this

Inherited from

Vec4.copy

cross()
cross(
   u, 
   v, 
   w): this;

Returns the cross-product of three vectors in a 4-dimensional space

Parameters
Parameter Type Description
u ReadonlyVec4 the first vector
v ReadonlyVec4 the second vector
w ReadonlyVec4 the third vector
Returns

this

this

Inherited from

Vec4.cross

distance()
distance(b): number;

Calculates the euclidian distance between this vec4 and another

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
Returns

number

distance between this and b

Inherited from

Vec4.distance

divide()
divide(b): this;

Divides this by another vec4

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
Returns

this

this

Inherited from

Vec4.divide

dot()
dot(b): number;

Calculates the dot product of this vec4 and another

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
Returns

number

dot product of this and b

Inherited from

Vec4.dot

equals()
equals(b): boolean;

Returns whether or not the quaternions point approximately to the same direction. Both quaternions are assumed to be unit length.

Parameters
Parameter Type Description
b ReadonlyQuat The second unit quaternion.
Returns

boolean

True if the quaternions are equal, false otherwise.

Overrides

Vec4.equals

exactEquals()
exactEquals(b): boolean;

Returns whether or not this vector and another exactly have the same elements in the same position (when compared with ===)

Parameters
Parameter Type Description
b ReadonlyVec4 The second vector.
Returns

boolean

True if the vectors are equal, false otherwise.

Inherited from

Vec4.exactEquals

exp()
exp(): this;

Calculate the exponential of a unit quaternion.

Returns

this

this

floor()
floor(): this;

Math.floor the components of this vec4

Returns

this

this

Inherited from

Vec4.floor

fromEuler()
fromEuler(
   x, 
   y, 
   z, 
   order?): this;

Creates a quaternion from the given euler angle x, y, z

Parameters
Parameter Type Default value Description
x number undefined Angle to rotate around X axis in degrees.
y number undefined Angle to rotate around Y axis in degrees.
z number undefined Angle to rotate around Z axis in degrees.
order "xyz" | "xzy" | "yxz" | "yzx" | "zxy" | "zyx" glMatrix.ANGLE_ORDER Intrinsic order for conversion, default is zyx.
Returns

this

this

fromMat3()
fromMat3(m): this;

Creates a quaternion from the given 3x3 rotation matrix.

Parameters
Parameter Type Description
m ReadonlyMat3 rotation matrix
Returns

this

this

getAngle()
getAngle(b): number;

Gets the angular distance between two unit quaternions

Parameters
Parameter Type Description
b ReadonlyQuat Destination unit quaternion
Returns

number

Angle, in radians, between the two quaternions

getAxisAngle()
getAxisAngle(out_axis): number;

Gets the rotation axis and angle for a given quaternion

Parameters
Parameter Type Description
out_axis vec3 Vector receiving the axis of rotation
Returns

number

Angle, in radians, of the rotation

identity()
identity(): this;

Set a quat to the identity quaternion

Returns

this

this

inverse()
inverse(): this;

Returns the inverse of the components of this vec4

Returns

this

this

Inherited from

Vec4.inverse

invert()
invert(): this;

Calculates the inverse of a quat

Returns

this

this

lerp()
lerp(b, t): this;

Performs a linear interpolation between this vec4 and another

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
t number interpolation amount, in the range [0-1], between the two inputs
Returns

this

this

Inherited from

Vec4.lerp

ln()
ln(): this;

Calculate the natural logarithm of a unit quaternion.

Returns

this

this

magnitude()
magnitude(): number;

Calculates the magnitude of this vec4

Returns

number

magnitude of this

Inherited from

Vec4.magnitude

max()
max(b): this;

Returns the maximum of this vec4 and another

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
Returns

this

this

Inherited from

Vec4.max

min()
min(b): this;

Returns the minimum of this vec4 and another

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
Returns

this

this

Inherited from

Vec4.min

multiply()
multiply(b): this;

Multiplies two quat's

Parameters
Parameter Type Description
b ReadonlyQuat the second operand
Returns

this

this

Overrides

Vec4.multiply

negate()
negate(): this;

Negates the components of this vec4

Returns

this

this

Inherited from

Vec4.negate

normalize()
normalize(): this;

Normalize this vec4

Returns

this

this

Inherited from

Vec4.normalize

pow()
pow(b): this;

Calculate the scalar power of a unit quaternion.

Parameters
Parameter Type Description
b number amount to scale the quaternion by
Returns

this

this

random()
random(): this;

Generates a random unit quaternion

Returns

this

this

Overrides

Vec4.random

rotateX()
rotateX(rad): this;

Rotates a quaternion by the given angle about the X axis

Parameters
Parameter Type Description
rad number angle (in radians) to rotate
Returns

this

this

rotateY()
rotateY(rad): this;

Rotates a quaternion by the given angle about the Y axis

Parameters
Parameter Type Description
rad number angle (in radians) to rotate
Returns

this

this

rotateZ()
rotateZ(rad): this;

Rotates a quaternion by the given angle about the Z axis

Parameters
Parameter Type Description
rad number angle (in radians) to rotate
Returns

this

this

rotationTo()
rotationTo(a, b): this;

Sets a quaternion to represent the shortest rotation from one vector to another. Both vectors are assumed to be unit length.

Parameters
Parameter Type Description
a ReadonlyVec3 the initial vector
b ReadonlyVec3 the destination vector
Returns

this

this

round()
round(): this;

symmetric round the components of this vec4

Returns

this

this

Inherited from

Vec4.round

scale()
scale(b): this;

Scales this vec4 by a scalar number

Parameters
Parameter Type Description
b number amount to scale the vector by
Returns

this

this

Inherited from

Vec4.scale

scaleAndAdd()
scaleAndAdd(b, scale): this;

Adds another vec4 to this after scaling the second operand by a scalar value

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
scale number the amount to scale b by before adding
Returns

this

this

Inherited from

Vec4.scaleAndAdd

setAxes()
setAxes(
   view, 
   right, 
   up): this;

Sets the specified quaternion with values corresponding to the given axes.

Parameters
Parameter Type Description
view ReadonlyVec3 the vector representing the viewing direction
right ReadonlyVec3 the vector representing the local "right" direction
up ReadonlyVec3 the vector representing the local "up" direction
Returns

this

this

setAxisAngle()
setAxisAngle(axis, rad): this;

Sets a quat from the given angle and rotation axis

Parameters
Parameter Type Description
axis ReadonlyVec3 the axis around which to rotate
rad number the angle in radians
Returns

this

this

setVec4()
setVec4(
   x, 
   y, 
   z, 
   w): this;

Set the components of a vec4 to the given values

Parameters
Parameter Type Description
x number X component
y number Y component
z number Z component
w number W component
Returns

this

this

Inherited from

Vec4.setVec4

slerp()
slerp(b, t): this;

Performs a spherical linear interpolation between this and another quat

Parameters
Parameter Type Description
b ReadonlyQuat the second operand
t number interpolation amount, in the range [0-1], between the two inputs
Returns

this

this

sqlerp()
sqlerp(
   a, 
   b, 
   c, 
   d, 
   t): this;

Performs a spherical linear interpolation with two control points

Parameters
Parameter Type Description
a ReadonlyQuat the first operand
b ReadonlyQuat the second operand
c ReadonlyQuat the third operand
d ReadonlyQuat the fourth operand
t number interpolation amount, in the range [0-1], between the two inputs
Returns

this

this

squaredDistance()
squaredDistance(b): number;

Calculates the squared euclidian distance between this vec4 and another

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
Returns

number

squared distance between this and b

Inherited from

Vec4.squaredDistance

squaredMagnitude()
squaredMagnitude(): number;

Calculates the squared magnitude of this vec4

Returns

number

squared magnitude of this

Inherited from

Vec4.squaredMagnitude

str()
str(): string;

Returns a string representation of a quaternion

Returns

string

string representation of the vector

Overrides

Vec4.str

subtract()
subtract(b): this;

Subtracts another vec4 from this

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
Returns

this

this

Inherited from

Vec4.subtract

transformMat4()
transformMat4(m): this;

Transforms this vec4 with a mat4.

Parameters
Parameter Type Description
m ReadonlyMat4 matrix to transform with
Returns

this

this

Inherited from

Vec4.transformMat4

transformQuat()
transformQuat(q): this;

Transforms this vec4 with a quat

Parameters
Parameter Type Description
q ReadonlyQuat normalized quaternion to transform with
Returns

this

this

Inherited from

Vec4.transformQuat

zero()
zero(): this;

Set the components of this vec4 to zero

Returns

this

this

Inherited from

Vec4.zero

clone()
static clone(a): Vec4;

Creates a new vec4 initialized with values from an existing vector

Parameters
Parameter Type Description
a ReadonlyVec4 vector to clone
Returns

Vec4

a new 4D vector

Inherited from

Vec4.clone

forEach()
static forEach(
   a, 
   stride, 
   offset, 
   count, 
   fn, 
arg?): number[] | Float32Array<ArrayBufferLike>;

Perform some operation over an array of vec4s.

Parameters
Parameter Type Description
a number[] | Float32Array<ArrayBufferLike> the array of vectors to iterate over
stride number Number of elements between the start of each vec4. If 0, stride retrieves the next vec4
offset number Number of elements to skip before the first vec4
count number Number of vec4s to iterate over. If 0, iterates over entire array
fn (out, a, arg) => void Function to call for each vector in the array
arg? any Additional argument to pass to fn
Returns

number[] | Float32Array<ArrayBufferLike>

a

Inherited from

Vec4.forEach

fromValues()
static fromValues(
   x, 
   y, 
   z, 
   w): Vec4;

Creates a new vec4 initialized with the given values

Parameters
Parameter Type Description
x number X component
y number Y component
z number Z component
w number W component
Returns

Vec4

a new 4D vector

Inherited from

Vec4.fromValues


Quat2

Dual Quaternion

Extends

  • Float32Array

Indexable

[index: number]: number

Constructors

Constructor
new Quat2(): Quat2;

Creates a new identity dual quat

Returns

Quat2

Overrides
Float32Array.constructor

Methods

add()
add(b): this;

Adds two dual quat's

Parameters
Parameter Type Description
b ReadonlyQuat2 the second operand
Returns

this

this

conjugate()
conjugate(): this;

Calculates the conjugate of a dual quat

Returns

this

this

copy()
copy(a): this;

Copy the values from one dual quat to another

Parameters
Parameter Type Description
a ReadonlyQuat2 the source dual quaternion
Returns

this

this

dot()
dot(b): number;

Calculates the dot product of two dual quat's (The dot product of the real parts)

Parameters
Parameter Type Description
b ReadonlyQuat2 the second operand
Returns

number

dot product of this and b

equals()
equals(b): boolean;

Returns whether or not the dual quaternions have approximately the same elements in the same position.

Parameters
Parameter Type Description
b ReadonlyQuat2 the second dual quat.
Returns

boolean

true if the dual quats are equal, false otherwise.

exactEquals()
exactEquals(b): boolean;

Returns whether or not the dual quaternions have exactly the same elements in the same position (when compared with ===)

Parameters
Parameter Type Description
b ReadonlyQuat2 the second dual quaternion.
Returns

boolean

true if the dual quaternions are equal, false otherwise.

fromMat4()
fromMat4(a): this;

Creates a new dual quat from a matrix (4x4)

Parameters
Parameter Type Description
a ReadonlyMat4 the matrix
Returns

this

this

fromRotation()
fromRotation(q): this;

Creates a dual quat from a quaternion

Parameters
Parameter Type Description
q ReadonlyQuat the quaternion
Returns

this

this

fromRotationTranslation()
fromRotationTranslation(q, t): this;

Creates a dual quat from a quaternion and a translation

Parameters
Parameter Type Description
q ReadonlyQuat a normalized quaternion
t ReadonlyVec3 translation vector
Returns

this

this

fromTranslation()
fromTranslation(t): this;

Creates a dual quat from a translation

Parameters
Parameter Type Description
t ReadonlyVec3 translation vector
Returns

this

this

getTranslation()
getTranslation(out): vec3;

Gets the translation of a normalized dual quat

Parameters
Parameter Type Description
out vec3 translation
Returns

vec3

translation

identity()
identity(): this;

Set a dual quat to the identity dual quaternion

Returns

this

this

invert()
invert(): this;

Calculates the inverse of a dual quat.

Returns

this

this

lerp()
lerp(b, t): this;

Performs a linear interpolation between two dual quats's

Parameters
Parameter Type Description
b ReadonlyQuat2 the second operand
t number interpolation amount, in the range [0-1], between the two inputs
Returns

this

this

multiply()
multiply(b): this;

Multiplies two dual quat's

Parameters
Parameter Type Description
b ReadonlyQuat2 the second operand
Returns

this

this

normalize()
normalize(): this;

Normalize a dual quat

Returns

this

this

rotateAroundAxis()
rotateAroundAxis(axis, rad): this;

Rotates a dual quat around a given axis.

Parameters
Parameter Type Description
axis ReadonlyVec3 the axis to rotate around
rad number how far the rotation should be
Returns

this

this

rotateByQuatAppend()
rotateByQuatAppend(q): this;

Rotates a dual quat by a given quaternion (a * q)

Parameters
Parameter Type Description
q ReadonlyQuat quaternion to rotate by
Returns

this

this

rotateByQuatPrepend()
rotateByQuatPrepend(q): this;

Rotates a dual quat by a given quaternion (q * a)

Parameters
Parameter Type Description
q ReadonlyQuat quaternion to rotate by
Returns

this

this

rotateX()
rotateX(rad): this;

Rotates a dual quat around the X axis

Parameters
Parameter Type Description
rad number how far should the rotation be
Returns

this

this

rotateY()
rotateY(rad): this;

Rotates a dual quat around the Y axis

Parameters
Parameter Type Description
rad number how far should the rotation be
Returns

this

this

rotateZ()
rotateZ(rad): this;

Rotates a dual quat around the Z axis

Parameters
Parameter Type Description
rad number how far should the rotation be
Returns

this

this

scale()
scale(b): this;

Scales a dual quat by a scalar number

Parameters
Parameter Type Description
b number amount to scale the dual quat by
Returns

this

this

setValues()
setValues(
   x1, 
   y1, 
   z1, 
   w1, 
   x2, 
   y2, 
   z2, 
   w2): this;

Set the components of a dual quat to the given values

Parameters
Parameter Type
x1 number
y1 number
z1 number
w1 number
x2 number
y2 number
z2 number
w2 number
Returns

this

this

str()
str(): string;

Returns a string representation of a dual quaternion

Returns

string

string representation of the dual quat

translate()
translate(v): this;

Translates a dual quat by the given vector

Parameters
Parameter Type Description
v ReadonlyVec3 vector to translate by
Returns

this

this

clone()
static clone(a): Quat2;

Creates a new dual quat initialized with values from an existing quaternion

Parameters
Parameter Type Description
a ReadonlyQuat2 dual quaternion to clone
Returns

Quat2

new dual quaternion

fromRotationTranslationValues()
static fromRotationTranslationValues(
   x1, 
   y1, 
   z1, 
   w1, 
   x2, 
   y2, 
   z2): Quat2;

Creates a new dual quat from the given values (quat and translation)

Parameters
Parameter Type
x1 number
y1 number
z1 number
w1 number
x2 number
y2 number
z2 number
Returns

Quat2

new dual quaternion

fromValues()
static fromValues(
   x1, 
   y1, 
   z1, 
   w1, 
   x2, 
   y2, 
   z2, 
   w2): Quat2;

Creates a new dual quat initialized with the given values

Parameters
Parameter Type
x1 number
y1 number
z1 number
w1 number
x2 number
y2 number
z2 number
w2 number
Returns

Quat2

new dual quaternion


Vec2

2 Dimensional Vector

Extends

  • Float32Array

Indexable

[index: number]: number

Accessors

x
Get Signature
get x(): number;

X component

Returns

number

Set Signature
set x(v): void;
Parameters
Parameter Type
v number
Returns

void

y
Get Signature
get y(): number;

Y component

Returns

number

Set Signature
set y(v): void;
Parameters
Parameter Type
v number
Returns

void

Constructors

Constructor
new Vec2(x?, y?): Vec2;

Creates a new vec2

Parameters
Parameter Type Default value Description
x number 0 X component
y number 0 Y component
Returns

Vec2

Overrides
Float32Array.constructor

Methods

add()
add(b): this;

Adds another vec2 to this

Parameters
Parameter Type Description
b ReadonlyVec2 the second operand
Returns

this

this

angle()
angle(b): number;

Get the smallest angle between this vec2 and another

Parameters
Parameter Type Description
b ReadonlyVec2 The second operand
Returns

number

The angle in radians

ceil()
ceil(): this;

Math.ceil the components of this vec2

Returns

this

this

copy()
copy(a): this;

Copy the values from one vec2 to another

Parameters
Parameter Type Description
a ReadonlyVec2 the source vector
Returns

this

this

cross()
cross(b, out): vec3;

Computes the cross product of this vec2 and another Note that the cross product must by definition produce a 3D vector

Parameters
Parameter Type Description
b ReadonlyVec2 the second operand
out vec3 the receiving vector
Returns

vec3

out

distance()
distance(b): number;

Calculates the euclidian distance between this vec2 and another

Parameters
Parameter Type Description
b ReadonlyVec2 the second operand
Returns

number

distance between this and b

divide()
divide(b): this;

Divides this by another vec2

Parameters
Parameter Type Description
b ReadonlyVec2 the second operand
Returns

this

this

dot()
dot(b): number;

Calculates the dot product of this vec2 and another

Parameters
Parameter Type Description
b ReadonlyVec2 the second operand
Returns

number

dot product of this and b

equals()
equals(b): boolean;

Returns whether or not this vector and another have approximately the same elements in the same position.

Parameters
Parameter Type Description
b ReadonlyVec2 The second vector.
Returns

boolean

True if the vectors are equal, false otherwise.

exactEquals()
exactEquals(b): boolean;

Returns whether or not this vector and another exactly have the same elements in the same position (when compared with ===)

Parameters
Parameter Type Description
b ReadonlyVec2 The second vector.
Returns

boolean

True if the vectors are equal, false otherwise.

floor()
floor(): this;

Math.floor the components of this vec2

Returns

this

this

inverse()
inverse(): this;

Returns the inverse of the components of this vec2

Returns

this

this

lerp()
lerp(b, t): this;

Performs a spherical linear interpolation between this vec2 and another

Parameters
Parameter Type Description
b ReadonlyVec2 the second operand
t number interpolation amount, in the range [0-1], between the two inputs
Returns

this

this

magnitude()
magnitude(): number;

Calculates the magnitude of this vec2

Returns

number

magnitude of this

max()
max(b): this;

Returns the maximum of this vec2 and another

Parameters
Parameter Type Description
b ReadonlyVec2 the second operand
Returns

this

this

min()
min(b): this;

Returns the minimum of this vec2 and another

Parameters
Parameter Type Description
b ReadonlyVec2 the second operand
Returns

this

this

multiply()
multiply(b): this;

Multiplies another vec2 with this

Parameters
Parameter Type Description
b ReadonlyVec2 the second operand
Returns

this

this

negate()
negate(): this;

Negates the components of this vec2

Returns

this

this

normalize()
normalize(): this;

Normalize this vec2

Returns

this

this

random()
random(scale?): this;

Generates a random vector with the given scale

Parameters
Parameter Type Default value Description
scale? number 1.0 Length of the resulting vector. If omitted, a unit vector will be returned
Returns

this

this

rotate()
rotate(origin, rad): this;

Rotate this 2D vector

Parameters
Parameter Type Description
origin ReadonlyVec2 The origin of the rotation
rad number The angle of rotation in radians
Returns

this

this

round()
round(): this;

symmetric round the components of this vec2

Returns

this

this

scale()
scale(b): this;

Scales this vec2 by a scalar number

Parameters
Parameter Type Description
b number amount to scale the vector by
Returns

this

this

scaleAndAdd()
scaleAndAdd(b, scale): this;

Adds another vec2 to this after scaling the second operand by a scalar value

Parameters
Parameter Type Description
b ReadonlyVec2 the second operand
scale number the amount to scale b by before adding
Returns

this

this

setValues()
setValues(x, y): this;

Set the components of a vec2 to the given values

Parameters
Parameter Type Description
x number X component
y number Y component
Returns

this

this

signedAngle()
signedAngle(b): number;

Get the signed angle in the interval [-pi,pi] between this vec2 and another (positive if this is to the right of b)

Parameters
Parameter Type Description
b ReadonlyVec2 The second vector
Returns

number

The signed angle in radians

squaredDistance()
squaredDistance(b): number;

Calculates the squared euclidian distance between this vec2 and another

Parameters
Parameter Type Description
b ReadonlyVec2 the second operand
Returns

number

squared distance between this and b

squaredMagnitude()
squaredMagnitude(): number;

Calculates the squared magnitude of this vec2

Returns

number

squared magnitude of this

str()
str(): string;

Returns a string representation of this vector

Returns

string

string representation of the vector

subtract()
subtract(b): this;

Subtracts another vec2 from this

Parameters
Parameter Type Description
b ReadonlyVec2 the second operand
Returns

this

this

transformMat2()
transformMat2(m): this;

Transforms this vec2 with a mat2

Parameters
Parameter Type Description
m ReadonlyMat2 matrix to transform with
Returns

this

this

transformMat2d()
transformMat2d(m): this;

Transforms this vec2 with a mat2d

Parameters
Parameter Type Description
m ReadonlyMat2d matrix to transform with
Returns

this

this

transformMat3()
transformMat3(m): this;

Transforms this vec2 with a mat3 3rd vector component is implicitly '1'

Parameters
Parameter Type Description
m ReadonlyMat3 matrix to transform with
Returns

this

this

transformMat4()
transformMat4(m): this;

Transforms this vec2 with a mat4 3rd vector component is implicitly '0' 4th vector component is implicitly '1'

Parameters
Parameter Type Description
m ReadonlyMat4 matrix to transform with
Returns

this

this

zero()
zero(): this;

Set the components of this vec2 to zero

Returns

this

this

clone()
static clone(a): Vec2;

Creates a new vec2 initialized with values from an existing vector

Parameters
Parameter Type Description
a ReadonlyVec2 vector to clone
Returns

Vec2

a new 2D vector

forEach()
static forEach(
   a, 
   stride, 
   offset, 
   count, 
   fn, 
arg?): number[] | Float32Array<ArrayBufferLike>;

Perform some operation over an array of vec2s.

Parameters
Parameter Type Description
a number[] | Float32Array<ArrayBufferLike> the array of vectors to iterate over
stride number Number of elements between the start of each vec2. If 0, stride retrieves the next vec2
offset number Number of elements to skip before the first vec2
count number Number of vec2s to iterate over. If 0, iterates over entire array
fn (out, a, arg) => void Function to call for each vector in the array
arg? any Additional argument to pass to fn
Returns

number[] | Float32Array<ArrayBufferLike>

a

fromValues()
static fromValues(x, y): Vec2;

Creates a new vec2 initialized with the given values

Parameters
Parameter Type Description
x number X component
y number Y component
Returns

Vec2

a new 2D vector


Vec3

3 Dimensional Vector

Extends

  • Float32Array

Indexable

[index: number]: number

Accessors

x
Get Signature
get x(): number;

X component

Returns

number

Set Signature
set x(v): void;
Parameters
Parameter Type
v number
Returns

void

y
Get Signature
get y(): number;

Y component

Returns

number

Set Signature
set y(v): void;
Parameters
Parameter Type
v number
Returns

void

z
Get Signature
get z(): number;

Z component

Returns

number

Set Signature
set z(v): void;
Parameters
Parameter Type
v number
Returns

void

Constructors

Constructor
new Vec3(
   x?, 
   y?, 
   z?): Vec3;

Creates a new vec3

Parameters
Parameter Type Default value Description
x number 0 X component
y number 0 Y component
z number 0 Z component
Returns

Vec3

Overrides
Float32Array.constructor

Methods

add()
add(b): this;

Adds another vec3 to this

Parameters
Parameter Type Description
b ReadonlyVec3 the second operand
Returns

this

this

angle()
angle(b): number;

Get the angle between this vec3 and another

Parameters
Parameter Type Description
b ReadonlyVec3 The second operand
Returns

number

The angle in radians

bezier()
bezier(
   b, 
   c, 
   d, 
   t): this;

Performs a bezier interpolation with two control points

Parameters
Parameter Type Description
b ReadonlyVec3 the second operand
c ReadonlyVec3 the third operand
d ReadonlyVec3 the fourth operand
t number interpolation amount, in the range [0-1], between the two inputs
Returns

this

this

ceil()
ceil(): this;

Math.ceil the components of this vec3

Returns

this

this

copy()
copy(a): this;

Copy the values from one vec3 to another

Parameters
Parameter Type Description
a ReadonlyVec3 the source vector
Returns

this

this

cross()
cross(b): this;

Computes the cross product of this vec3 and another

Parameters
Parameter Type Description
b ReadonlyVec3 the second operand
Returns

this

this

distance()
distance(b): number;

Calculates the euclidian distance between this vec3 and another

Parameters
Parameter Type Description
b ReadonlyVec3 the second operand
Returns

number

distance between this and b

divide()
divide(b): this;

Divides this by another vec3

Parameters
Parameter Type Description
b ReadonlyVec3 the second operand
Returns

this

this

dot()
dot(b): number;

Calculates the dot product of this vec3 and another

Parameters
Parameter Type Description
b ReadonlyVec3 the second operand
Returns

number

dot product of this and b

equals()
equals(b): boolean;

Returns whether or not this vector and another have approximately the same elements in the same position.

Parameters
Parameter Type Description
b ReadonlyVec3 The second vector.
Returns

boolean

True if the vectors are equal, false otherwise.

exactEquals()
exactEquals(b): boolean;

Returns whether or not this vector and another exactly have the same elements in the same position (when compared with ===)

Parameters
Parameter Type Description
b ReadonlyVec3 The second vector.
Returns

boolean

True if the vectors are equal, false otherwise.

floor()
floor(): this;

Math.floor the components of this vec3

Returns

this

this

hermite()
hermite(
   b, 
   c, 
   d, 
   t): this;

Performs a hermite interpolation with two control points

Parameters
Parameter Type Description
b ReadonlyVec3 the second operand
c ReadonlyVec3 the third operand
d ReadonlyVec3 the fourth operand
t number interpolation amount, in the range [0-1], between the two inputs
Returns

this

this

inverse()
inverse(): this;

Returns the inverse of the components of this vec3

Returns

this

this

lerp()
lerp(b, t): this;

Performs a linear interpolation between this vec3 and another

Parameters
Parameter Type Description
b ReadonlyVec3 the second operand
t number interpolation amount, in the range [0-1], between the two inputs
Returns

this

this

magnitude()
magnitude(): number;

Calculates the magnitude of this vec3

Returns

number

magnitude of this

max()
max(b): this;

Returns the maximum of this vec3 and another

Parameters
Parameter Type Description
b ReadonlyVec3 the second operand
Returns

this

this

min()
min(b): this;

Returns the minimum of this vec3 and another

Parameters
Parameter Type Description
b ReadonlyVec3 the second operand
Returns

this

this

multiply()
multiply(b): this;

Multiplies another vec3 with this

Parameters
Parameter Type Description
b ReadonlyVec3 the second operand
Returns

this

this

negate()
negate(): this;

Negates the components of this vec3

Returns

this

this

normalize()
normalize(): this;

Normalize this vec3

Returns

this

this

random()
random(scale?): this;

Generates a random vector with the given scale

Parameters
Parameter Type Default value Description
scale? number 1.0 Length of the resulting vector. If omitted, a unit vector will be returned
Returns

this

this

rotateX()
rotateX(origin, rad): this;

Rotate this 3D vector around the x-axis

Parameters
Parameter Type Description
origin ReadonlyVec3 The origin of the rotation
rad number The angle of rotation in radians
Returns

this

this

rotateY()
rotateY(origin, rad): this;

Rotate this 3D vector around the y-axis

Parameters
Parameter Type Description
origin ReadonlyVec3 The origin of the rotation
rad number The angle of rotation in radians
Returns

this

this

rotateZ()
rotateZ(origin, rad): this;

Rotate this 3D vector around the z-axis

Parameters
Parameter Type Description
origin ReadonlyVec3 The origin of the rotation
rad number The angle of rotation in radians
Returns

this

this

round()
round(): this;

symmetric round the components of this vec3

Returns

this

this

scale()
scale(b): this;

Scales this vec3 by a scalar number

Parameters
Parameter Type Description
b number amount to scale the vector by
Returns

this

this

scaleAndAdd()
scaleAndAdd(b, scale): this;

Adds another vec3 to this after scaling the second operand by a scalar value

Parameters
Parameter Type Description
b ReadonlyVec3 the second operand
scale number the amount to scale b by before adding
Returns

this

this

setVec3()
setVec3(
   x, 
   y, 
   z): this;

Set the components of a vec3 to the given values

Parameters
Parameter Type Description
x number X component
y number Y component
z number Z component
Returns

this

this

slerp()
slerp(b, t): this;

Performs a spherical linear interpolation between this vec3 and another

Parameters
Parameter Type Description
b ReadonlyVec3 the second operand
t number interpolation amount, in the range [0-1], between the two inputs
Returns

this

this

squaredDistance()
squaredDistance(b): number;

Calculates the squared euclidian distance between this vec3 and another

Parameters
Parameter Type Description
b ReadonlyVec3 the second operand
Returns

number

squared distance between this and b

squaredMagnitude()
squaredMagnitude(): number;

Calculates the squared magnitude of this vec3

Returns

number

squared magnitude of this

str()
str(): string;

Returns a string representation of this vector

Returns

string

string representation of the vector

subtract()
subtract(b): this;

Subtracts another vec3 from this

Parameters
Parameter Type Description
b ReadonlyVec3 the second operand
Returns

this

this

transformMat3()
transformMat3(m): this;

Transforms this vec3 with a mat3.

Parameters
Parameter Type Description
m ReadonlyMat3 the 3x3 matrix to transform with
Returns

this

this

transformMat4()
transformMat4(m): this;

Transforms this vec3 with a mat4. 4th vector component is implicitly '1'

Parameters
Parameter Type Description
m ReadonlyMat4 matrix to transform with
Returns

this

this

transformQuat()
transformQuat(q): this;

Transforms this vec3 with a quat

Parameters
Parameter Type Description
q ReadonlyQuat normalized quaternion to transform with
Returns

this

this

zero()
zero(): this;

Set the components of this vec3 to zero

Returns

this

this

clone()
static clone(a): Vec3;

Creates a new vec3 initialized with values from an existing vector

Parameters
Parameter Type Description
a ReadonlyVec3 vector to clone
Returns

Vec3

a new 3D vector

forEach()
static forEach(
   a, 
   stride, 
   offset, 
   count, 
   fn, 
arg?): number[] | Float32Array<ArrayBufferLike>;

Perform some operation over an array of vec3s.

Parameters
Parameter Type Description
a number[] | Float32Array<ArrayBufferLike> the array of vectors to iterate over
stride number Number of elements between the start of each vec3. If 0, stride retrieves the next vec3
offset number Number of elements to skip before the first vec3
count number Number of vec3s to iterate over. If 0, iterates over entire array
fn (out, a, arg) => void Function to call for each vector in the array
arg? any Additional argument to pass to fn
Returns

number[] | Float32Array<ArrayBufferLike>

a

fromValues()
static fromValues(
   x, 
   y, 
   z): Vec3;

Creates a new vec3 initialized with the given values

Parameters
Parameter Type Description
x number X component
y number Y component
z number Z component
Returns

Vec3

a new 3D vector


Vec4

4 Dimensional Vector

Extends

  • Float32Array

Extended by

Indexable

[index: number]: number

Accessors

w
Get Signature
get w(): number;

W component

Returns

number

Set Signature
set w(v): void;
Parameters
Parameter Type
v number
Returns

void

x
Get Signature
get x(): number;

X component

Returns

number

Set Signature
set x(v): void;
Parameters
Parameter Type
v number
Returns

void

y
Get Signature
get y(): number;

Y component

Returns

number

Set Signature
set y(v): void;
Parameters
Parameter Type
v number
Returns

void

z
Get Signature
get z(): number;

Z component

Returns

number

Set Signature
set z(v): void;
Parameters
Parameter Type
v number
Returns

void

Constructors

Constructor
new Vec4(
   x?, 
   y?, 
   z?, 
   w?): Vec4;

Creates a new vec4

Parameters
Parameter Type Default value Description
x number 0 X component
y number 0 Y component
z number 0 Z component
w number 0 W component
Returns

Vec4

Overrides
Float32Array.constructor

Methods

add()
add(b): this;

Adds another vec4 to this

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
Returns

this

this

ceil()
ceil(): this;

Math.ceil the components of this vec4

Returns

this

this

copy()
copy(a): this;

Copy the values from one vec4 to another

Parameters
Parameter Type Description
a ReadonlyVec4 the source vector
Returns

this

this

cross()
cross(
   u, 
   v, 
   w): this;

Returns the cross-product of three vectors in a 4-dimensional space

Parameters
Parameter Type Description
u ReadonlyVec4 the first vector
v ReadonlyVec4 the second vector
w ReadonlyVec4 the third vector
Returns

this

this

distance()
distance(b): number;

Calculates the euclidian distance between this vec4 and another

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
Returns

number

distance between this and b

divide()
divide(b): this;

Divides this by another vec4

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
Returns

this

this

dot()
dot(b): number;

Calculates the dot product of this vec4 and another

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
Returns

number

dot product of this and b

equals()
equals(b): boolean;

Returns whether or not this vector and another have approximately the same elements in the same position.

Parameters
Parameter Type Description
b ReadonlyVec4 The second vector.
Returns

boolean

True if the vectors are equal, false otherwise.

exactEquals()
exactEquals(b): boolean;

Returns whether or not this vector and another exactly have the same elements in the same position (when compared with ===)

Parameters
Parameter Type Description
b ReadonlyVec4 The second vector.
Returns

boolean

True if the vectors are equal, false otherwise.

floor()
floor(): this;

Math.floor the components of this vec4

Returns

this

this

inverse()
inverse(): this;

Returns the inverse of the components of this vec4

Returns

this

this

lerp()
lerp(b, t): this;

Performs a linear interpolation between this vec4 and another

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
t number interpolation amount, in the range [0-1], between the two inputs
Returns

this

this

magnitude()
magnitude(): number;

Calculates the magnitude of this vec4

Returns

number

magnitude of this

max()
max(b): this;

Returns the maximum of this vec4 and another

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
Returns

this

this

min()
min(b): this;

Returns the minimum of this vec4 and another

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
Returns

this

this

multiply()
multiply(b): this;

Multiplies another vec4 with this

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
Returns

this

this

negate()
negate(): this;

Negates the components of this vec4

Returns

this

this

normalize()
normalize(): this;

Normalize this vec4

Returns

this

this

random()
random(scale?): this;

Generates a random vector with the given scale

Parameters
Parameter Type Default value Description
scale? number 1.0 Length of the resulting vector. If omitted, a unit vector will be returned
Returns

this

this

round()
round(): this;

symmetric round the components of this vec4

Returns

this

this

scale()
scale(b): this;

Scales this vec4 by a scalar number

Parameters
Parameter Type Description
b number amount to scale the vector by
Returns

this

this

scaleAndAdd()
scaleAndAdd(b, scale): this;

Adds another vec4 to this after scaling the second operand by a scalar value

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
scale number the amount to scale b by before adding
Returns

this

this

setVec4()
setVec4(
   x, 
   y, 
   z, 
   w): this;

Set the components of a vec4 to the given values

Parameters
Parameter Type Description
x number X component
y number Y component
z number Z component
w number W component
Returns

this

this

squaredDistance()
squaredDistance(b): number;

Calculates the squared euclidian distance between this vec4 and another

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
Returns

number

squared distance between this and b

squaredMagnitude()
squaredMagnitude(): number;

Calculates the squared magnitude of this vec4

Returns

number

squared magnitude of this

str()
str(): string;

Returns a string representation of this vector

Returns

string

string representation of the vector

subtract()
subtract(b): this;

Subtracts another vec4 from this

Parameters
Parameter Type Description
b ReadonlyVec4 the second operand
Returns

this

this

transformMat4()
transformMat4(m): this;

Transforms this vec4 with a mat4.

Parameters
Parameter Type Description
m ReadonlyMat4 matrix to transform with
Returns

this

this

transformQuat()
transformQuat(q): this;

Transforms this vec4 with a quat

Parameters
Parameter Type Description
q ReadonlyQuat normalized quaternion to transform with
Returns

this

this

zero()
zero(): this;

Set the components of this vec4 to zero

Returns

this

this

clone()
static clone(a): Vec4;

Creates a new vec4 initialized with values from an existing vector

Parameters
Parameter Type Description
a ReadonlyVec4 vector to clone
Returns

Vec4

a new 4D vector

forEach()
static forEach(
   a, 
   stride, 
   offset, 
   count, 
   fn, 
arg?): number[] | Float32Array<ArrayBufferLike>;

Perform some operation over an array of vec4s.

Parameters
Parameter Type Description
a number[] | Float32Array<ArrayBufferLike> the array of vectors to iterate over
stride number Number of elements between the start of each vec4. If 0, stride retrieves the next vec4
offset number Number of elements to skip before the first vec4
count number Number of vec4s to iterate over. If 0, iterates over entire array
fn (out, a, arg) => void Function to call for each vector in the array
arg? any Additional argument to pass to fn
Returns

number[] | Float32Array<ArrayBufferLike>

a

fromValues()
static fromValues(
   x, 
   y, 
   z, 
   w): Vec4;

Creates a new vec4 initialized with the given values

Parameters
Parameter Type Description
x number X component
y number Y component
z number Z component
w number W component
Returns

Vec4

a new 4D vector

Variables

ANGLE_ORDER

const ANGLE_ORDER: "xyz" | "xzy" | "yxz" | "yzx" | "zxy" | "zyx" = "zyx";