Global

Methods

# toRad(number) → {number}

Converts degrees to radians.

Parameters:
Name Type Description
number

angle

Returns:
Type
number

# toDeg(number) → {number}

Converts radians to degrees.

Parameters:
Name Type Description
number

angle

Returns:
Type
number

# v2_zero() → {Array.<number>}

Null 3-vector [0,0]

Returns:
Type
Array.<number>

# v2_random() → {Array.<number>}

Random point on a unit circle.

Returns:
Type
Array.<number>

# v2_magnitude(vector) → {number}

Magnitude of vector.

Parameters:
Name Type Description
vector Array.<number>
Returns:
Type
number

# v2_sqrMag(vector) → {number}

Squared magnitude of vector.

Parameters:
Name Type Description
vector Array.<number>
Returns:
Type
number

# v2_normalize(vector) → {Array.<number>}

Normalized vector. (Error on magnitude 0)

Parameters:
Name Type Description
vector Array.<number>
Returns:
Type
Array.<number>

# v2_abs(vector) → {Array.<number>}

Absolute value of all elements.

Parameters:
Name Type Description
vector Array.<number>
Returns:
Type
Array.<number>

# v2_ceil(vector) → {Array.<number>}

Ceiling of all elements.

Parameters:
Name Type Description
vector Array.<number>
Returns:
Type
Array.<number>

# v2_floor(vector) → {Array.<number>}

Floor of all elements.

Parameters:
Name Type Description
vector Array.<number>
Returns:
Type
Array.<number>

# v2_inverse(vector) → {Array.<number>}

Reciprocal of all elements.

Parameters:
Name Type Description
vector Array.<number>
Returns:
Type
Array.<number>

# v2_scale(vector, number) → {Array.<number>}

Multiply all elements by a constant scale factor.

Parameters:
Name Type Description
vector Array.<number>
number

scale

Returns:
Type
Array.<number>

# v2_multiply(vectorA, vectorB) → {Array.<number>}

Multiply individual elements of two vectors

Parameters:
Name Type Description
vectorA Array.<number>
vectorB Array.<number>
Returns:
Type
Array.<number>

# v2_add(vectorA, vectorB) → {Array.<number>}

Add two vectors

Parameters:
Name Type Description
vectorA Array.<number>
vectorB Array.<number>
Returns:
Type
Array.<number>

# v2_sub(vectorA, vectorB) → {Array.<number>}

Subtract two vectors

Parameters:
Name Type Description
vectorA Array.<number>
vectorB Array.<number>
Returns:
Type
Array.<number>

# v2_dot(vectorA, vectorB) → {number}

Dot product of two vectors

Parameters:
Name Type Description
vectorA Array.<number>
vectorB Array.<number>
Returns:
Type
number

# v2_min(vectorA, vectorB) → {number}

Minimum of two vectors, compared element by element.

Parameters:
Name Type Description
vectorA Array.<number>
vectorB Array.<number>
Returns:
Type
number

# v2_max(vectorA, vectorB) → {Array.<number>}

Maximum of two vectors, compared element by element.

Parameters:
Name Type Description
vectorA Array.<number>
vectorB Array.<number>
Returns:
Type
Array.<number>

# v2_angle(vectorA, vectorB) → {number}

Angle in radian between two vectors.

Parameters:
Name Type Description
vectorA Array.<number>
vectorB Array.<number>
Returns:
Type
number

# v2_lerp(vectorA, vectorB, interpolation) → {Array.<number>}

Linear interpolation between two vectors

Parameters:
Name Type Description
vectorA Array.<number>
vectorB Array.<number>
interpolation number

value between 0 and 1

Returns:
Type
Array.<number>

# v2_equals(vectorA, vectorB, epsilonopt) → {boolean}

Checks for vector equality within an epsilon.

Parameters:
Name Type Attributes Default Description
vectorA Array.<number>
vectorB Array.<number>
epsilon number <optional>
0
Returns:
Type
boolean

# v2_isZero(vector) → {boolean}

Checks if vector is [0,0]

Parameters:
Name Type Description
vector Array.<number>
Returns:
Type
boolean

# v2_manhattan(vector) → {number}

Manhattan distance of vector

Parameters:
Name Type Description
vector Array.<number>
Returns:
Type
number

# v2_transform(vector, matrix) → {Array.<number>}

Multiplies vector by a 2x2 matrix

Parameters:
Name Type Description
vector Array.<number>
matrix Array.<number>
Returns:
Type
Array.<number>

# v2_rotate(vector, angle) → {Array.<number>}

Rotate clockwise. Angle in radians.

Parameters:
Name Type Description
vector Array.<number>
angle number
Returns:
Type
Array.<number>

# v3_zero() → {Array.<number>}

Null 2-vector [0,0]

Returns:
Type
Array.<number>

# v3_random() → {Array.<number>}

Random point on a unit sphere.

Returns:
Type
Array.<number>

# v3_magnitude(vector) → {number}

Magnitude of vector.

Parameters:
Name Type Description
vector Array.<number>
Returns:
Type
number

# v3_sqrMag(vector) → {number}

Squared magnitude of vector.

Parameters:
Name Type Description
vector Array.<number>
Returns:
Type
number

# v3_normalize(vector) → {Array.<number>}

Normalized vector. (Error on magnitude 0)

Parameters:
Name Type Description
vector Array.<number>
Returns:
Type
Array.<number>

# v3_abs(vector) → {Array.<number>}

Absolute value of all elements.

Parameters:
Name Type Description
vector Array.<number>
Returns:
Type
Array.<number>

# v3_ceil(vector) → {Array.<number>}

Ceiling of all elements.

Parameters:
Name Type Description
vector Array.<number>
Returns:
Type
Array.<number>

# v3_floor(vector) → {Array.<number>}

Floor of all elements.

Parameters:
Name Type Description
vector Array.<number>
Returns:
Type
Array.<number>

# v3_inverse(vector) → {Array.<number>}

Reciprocal of all elements.

Parameters:
Name Type Description
vector Array.<number>
Returns:
Type
Array.<number>

# v3_scale(vector, number) → {Array.<number>}

Multiply all elements by a constant scale factor.

Parameters:
Name Type Description
vector Array.<number>
number

scale

Returns:
Type
Array.<number>

# v3_multiply(vectorA, vectorB) → {Array.<number>}

Multiply individual elements of two vectors

Parameters:
Name Type Description
vectorA Array.<number>
vectorB Array.<number>
Returns:
Type
Array.<number>

# v3_add(vectorA, vectorB) → {Array.<number>}

Add two vectors

Parameters:
Name Type Description
vectorA Array.<number>
vectorB Array.<number>
Returns:
Type
Array.<number>

# v3_sub(vectorA, vectorB) → {Array.<number>}

Subtract two vectors

Parameters:
Name Type Description
vectorA Array.<number>
vectorB Array.<number>
Returns:
Type
Array.<number>

# v3_dot(vectorA, vectorB) → {number}

Dot product of two vectors

Parameters:
Name Type Description
vectorA Array.<number>
vectorB Array.<number>
Returns:
Type
number

# v3_cross(vectorA, vectorB) → {number}

Cross product of two vectors

Parameters:
Name Type Description
vectorA Array.<number>
vectorB Array.<number>
Returns:
Type
number

# v3_min(vectorA, vectorB) → {number}

Minimum of two vectors, compared element by element.

Parameters:
Name Type Description
vectorA Array.<number>
vectorB Array.<number>
Returns:
Type
number

# v3_max(vectorA, vectorB) → {Array.<number>}

Maximum of two vectors, compared element by element.

Parameters:
Name Type Description
vectorA Array.<number>
vectorB Array.<number>
Returns:
Type
Array.<number>

# v3_angle(vectorA, vectorB) → {number}

Angle in radian between two vectors.

Parameters:
Name Type Description
vectorA Array.<number>
vectorB Array.<number>
Returns:
Type
number

# v3_lerp(vectorA, vectorB, t) → {Array.<number>}

Linear interpolation between two vectors

Parameters:
Name Type Description
vectorA Array.<number>
vectorB Array.<number>
t number

value between 0 and 1

Returns:
Type
Array.<number>

# v3_equals(vectorA, vectorB, epsilonopt) → {boolean}

Checks for vector equality within an epsilon.

Parameters:
Name Type Attributes Default Description
vectorA Array.<number>
vectorB Array.<number>
epsilon number <optional>
0
Returns:
Type
boolean

# v3_isZero(vector) → {boolean}

Checks if vector is [0,0,0]

Parameters:
Name Type Description
vector Array.<number>
Returns:
Type
boolean

# v3_manhattan(vector) → {number}

Manhattan distance of vector

Parameters:
Name Type Description
vector Array.<number>
Returns:
Type
number

# v3_transform(vector, matrix) → {Array.<number>}

Multiplies vector by a 4x4 matrix (Treats the vector as [x,y,z,1] in homogenous coordinates)

Parameters:
Name Type Description
vector Array.<number>
matrix Array.<number>
Returns:
Type
Array.<number>

# v3_rotateX(vector, angle) → {Array.<number>}

Rotate around x axis. Angle in radians. Clockwise looking along axis

Parameters:
Name Type Description
vector Array.<number>
angle number
Returns:
Type
Array.<number>

# v3_rotateY(vector, angle) → {Array.<number>}

Rotate around y axis. Angle in radians. Clockwise looking along axis

Parameters:
Name Type Description
vector Array.<number>
angle number
Returns:
Type
Array.<number>

# v3_rotateZ(vector, angle) → {Array.<number>}

Rotate around z axis. Angle in radians. Clockwise looking along axis

Parameters:
Name Type Description
vector Array.<number>
angle number
Returns:
Type
Array.<number>

# v3_rotate(vector, quaternion) → {Array.<number>}

Rotate by a quaternion

Parameters:
Name Type Description
vector Array.<number>
quaternion Array.<number>
Returns:
Type
Array.<number>

# q_identity() → {Array.<number>}

Identity quaternion

Returns:
Type
Array.<number>

# q_normalize(quaternion) → {Array.<number>}

Normalize quaternion. (If you do a long series of quaternion operations, periodically renormalize to prevent drift.)

Parameters:
Name Type Description
quaternion Array.<number>
Returns:

quaternion

Type
Array.<number>

# q_invert(quaternion) → {Array.<number>}

Reverse the rotation.

Parameters:
Name Type Description
quaternion Array.<number>
Returns:

quaternion

Type
Array.<number>

# q_axisAngle(axis, angle) → {Array.<number>}

Creates a quaternion for a rotation around an axis. The angle is clockwise in radians looking along the axis. The axis should be normalized.

Parameters:
Name Type Description
axis Array.<number>
angle number
Returns:

quaternion

Type
Array.<number>

# q_lookAt(forward, up, target) → {Array.<number>}

Given a forward vector, an up vector, and a target vector, generates a quaternion that will rotate the forward vector to look at the target vector. All vectors should be normalized.

Parameters:
Name Type Description
forward Array.<number>
up Array.<number>
target Array.<number>
Returns:

quaternion

Type
Array.<number>

# q_euler(x, y, z) → {Array.<number>}

Creates a quaternion from the given Euler angles. All angles are in radians.

Parameters:
Name Type Description
x number
y number
z number
Returns:

quaternion

Type
Array.<number>

# q_pitch(quaternion) → {number}

Extracts the Euler angle around the x axis from a quaternion.

Parameters:
Name Type Description
quaternion Array.<number>
Returns:

angle

Type
number

# q_yaw(quaternion) → {number}

Extracts the Euler angle around the y axis from a quaternion.

Parameters:
Name Type Description
quaternion Array.<number>
Returns:

angle

Type
number

# q_roll(quaternion) → {number}

Extracts the Euler angle around the z axis from a quaternion.

Parameters:
Name Type Description
quaternion Array.<number>
Returns:

angle

Type
number

# q_multiply(quaternionA, quaternionB) → {Array.<number>}

Combines two rotations. QuaternionA is applied before quaternionB.

Parameters:
Name Type Description
quaternionA Array.<number>
quaternionB Array.<number>
Returns:

quaternion

Type
Array.<number>

# q_slerp(quaternionA, quaternionB, t) → {Array.<number>}

Interpolates between two rotations.

Parameters:
Name Type Description
quaternionA Array.<number>
quaternionB Array.<number>
t number

value between 0 and 1

Returns:

quaternion

Type
Array.<number>

# q_equals(quaternionA, quaternionB, epsilonopt) → {boolean}

Checks for quaternion equality within an epsilon.

Parameters:
Name Type Attributes Default Description
quaternionA Array.<number>
quaternionB Array.<number>
epsilon number <optional>
0.0001
Returns:
Type
boolean

# q_isZero(quaternion) → {boolean}

Checks if quaternion is [0,0,0,1]

Parameters:
Name Type Description
quaternion Array.<number>
Returns:
Type
boolean

# m2_zero() → {Array.<number>}

Returns a 2x2 zero Matrix

Returns:

2x2 Matrix

Type
Array.<number>

# m2_identity() → {Array.<number>}

Returns a 2x2 identity matrix

Returns:

2x2 Matrix

Type
Array.<number>

# m2_rotation(angle) → {Array.<number>}

Returns a 2x2 matrix that will rotate a 2-vector clockwise. Angle is in radians.

Parameters:
Name Type Description
angle number
Returns:

2x2 Matrix

Type
Array.<number>

# m4_zero() → {Array.<number>}

Returns a 4x4 zero matrix

Returns:

2x2 Matrix

Type
Array.<number>

# m4_identity() → {Array.<number>}

Returns a 4x4 identity matrix

Returns:

4x4 Matrix

Type
Array.<number>

# m4_translation(translation) → {Array.<number>}

Creates a 4x4 transform matrix from a 3-vector translation.

Parameters:
Name Type Description
translation Array.<number>
Returns:

4x4 Matrix

Type
Array.<number>

# m4_getTranslation(matrix) → {Array.<number>}

Extracts the translation from a 4x4 transform matrix.

Parameters:
Name Type Description
matrix Array.<number>
Returns:

3-vector

Type
Array.<number>

# m4_scale(scale) → {Array.<number>}

Creates a 4x4 transform matrix from a 3-vector scale, or a scale constant.

Parameters:
Name Type Description
scale Array.<number> | number
Returns:

4x4 Matrix

Type
Array.<number>

# m4_rotation(axis, angle) → {Array.<number>}

Creates a 4x4 rotation matrix around the given axis. Angle is in radians, and rotation is clockwise looking along axis.

Parameters:
Name Type Description
axis Array.<number>
angle number
Returns:

4x4 Matrix

Type
Array.<number>

# m4_rotationX(angle) → {Array.<number>}

Creates a 4x4 rotation matrix around the x axis. Angle is in radians, and rotation is clockwise looking along axis.

Parameters:
Name Type Description
angle number
Returns:

4x4 Matrix

Type
Array.<number>

# m4_rotationY(angle) → {Array.<number>}

Creates a 4x4 rotation matrix around the y axis. Angle is in radians, and rotation is clockwise looking along axis.

Parameters:
Name Type Description
angle number
Returns:

4x4 Matrix

Type
Array.<number>

# m4_rotationZ(angle) → {Array.<number>}

Creates a 4x4 rotation matrix around the z axis. Angle is in radians, and rotation is clockwise looking along axis.

Parameters:
Name Type Description
angle number
Returns:

4x4 Matrix

Type
Array.<number>

# m4_rotationQ(rotation) → {Array.<number>}

Creates a 4x4 rotation matrix from a quaternion.

Parameters:
Name Type Description
rotation Array.<number>
Returns:

4x4 Matrix

Type
Array.<number>

# m4_getRotation(matrix) → {Array.<number>}

Extracts the rotation quaternion from a 4x4 transform matrix.

Parameters:
Name Type Description
matrix Array.<number>
Returns:

Quaternion

Type
Array.<number>

# m4_scaleRotationTranslation(scale, rotation, translation) → {Array.<number>}

Creates a 4x4 transform matrix from a scale, a rotation, and a translation. The scale can be either a 3-vector or a scalar. The rotation is a quaternion.

Parameters:
Name Type Description
scale Array.<number> | number
rotation Array.<number>
translation Array.<number>
Returns:

4x4 Matrix

Type
Array.<number>

# m4_perspective(fov, aspect, near, far) → {Array.<number>}

Creates a 4x4 perspective matrix from a field of view, an aspect ratio, and the near and far clip planes. The FOV is in radians.

Parameters:
Name Type Description
fov number
aspect number
near number
far number
Returns:

4x4 Matrix

Type
Array.<number>

# m4_transpose(matrix) → {Array.<number>}

Returns the transpose of a 4x4 matrix

Parameters:
Name Type Description
matrix Array.<number>
Returns:

4x4 Matrix

Type
Array.<number>

# m4_determinant(matrix) → {number}

Returns the determinant of a 4x4 matrix

Parameters:
Name Type Description
matrix Array.<number>
Returns:

Determinant

Type
number

# m4_invert(matrix) → {Array.<number>}

Returns the inverse of a 4x4 matrix

Parameters:
Name Type Description
matrix Array.<number>
Returns:

4x4 Matrix

Type
Array.<number>

# m4_multiply(matrixA, matrixB) → {Array.<number>}

Multiply two 4x4 matrices

Parameters:
Name Type Description
matrixA Array.<number>
matrixB Array.<number>
Returns:

4x4 Matrix

Type
Array.<number>

# m4_toNormal4(matrix) → {Array.<number>}

Extracts the scaling/rotation components of a 4x4 transform matrix and performs an inverse/transpose operation on them. This is the transform that should be applied to the surface normals of an object in a 3d rendered scene instead of the object's regular 4x4 transform.

Parameters:
Name Type Description
matrix Array.<number>
Returns:

4x4 Matrix

Type
Array.<number>