Methods
# toRad(number) → {number}
Converts degrees to radians.
Name | Type | Description |
---|---|---|
number |
angle |
- Type
- number
# toDeg(number) → {number}
Converts radians to degrees.
Name | Type | Description |
---|---|---|
number |
angle |
- Type
- number
# v2_zero() → {Array.<number>}
Null 3-vector [0,0]
- Type
- Array.<number>
# v2_random() → {Array.<number>}
Random point on a unit circle.
- Type
- Array.<number>
# v2_magnitude(vector) → {number}
Magnitude of vector.
Name | Type | Description |
---|---|---|
vector |
Array.<number> |
- Type
- number
# v2_sqrMag(vector) → {number}
Squared magnitude of vector.
Name | Type | Description |
---|---|---|
vector |
Array.<number> |
- Type
- number
# v2_normalize(vector) → {Array.<number>}
Normalized vector. (Error on magnitude 0)
Name | Type | Description |
---|---|---|
vector |
Array.<number> |
- Type
- Array.<number>
# v2_abs(vector) → {Array.<number>}
Absolute value of all elements.
Name | Type | Description |
---|---|---|
vector |
Array.<number> |
- Type
- Array.<number>
# v2_ceil(vector) → {Array.<number>}
Ceiling of all elements.
Name | Type | Description |
---|---|---|
vector |
Array.<number> |
- Type
- Array.<number>
# v2_floor(vector) → {Array.<number>}
Floor of all elements.
Name | Type | Description |
---|---|---|
vector |
Array.<number> |
- Type
- Array.<number>
# v2_inverse(vector) → {Array.<number>}
Reciprocal of all elements.
Name | Type | Description |
---|---|---|
vector |
Array.<number> |
- Type
- Array.<number>
# v2_scale(vector, number) → {Array.<number>}
Multiply all elements by a constant scale factor.
Name | Type | Description |
---|---|---|
vector |
Array.<number> | |
number |
scale |
- Type
- Array.<number>
# v2_multiply(vectorA, vectorB) → {Array.<number>}
Multiply individual elements of two vectors
Name | Type | Description |
---|---|---|
vectorA |
Array.<number> | |
vectorB |
Array.<number> |
- Type
- Array.<number>
# v2_add(vectorA, vectorB) → {Array.<number>}
Add two vectors
Name | Type | Description |
---|---|---|
vectorA |
Array.<number> | |
vectorB |
Array.<number> |
- Type
- Array.<number>
# v2_sub(vectorA, vectorB) → {Array.<number>}
Subtract two vectors
Name | Type | Description |
---|---|---|
vectorA |
Array.<number> | |
vectorB |
Array.<number> |
- Type
- Array.<number>
# v2_dot(vectorA, vectorB) → {number}
Dot product of two vectors
Name | Type | Description |
---|---|---|
vectorA |
Array.<number> | |
vectorB |
Array.<number> |
- Type
- number
# v2_min(vectorA, vectorB) → {number}
Minimum of two vectors, compared element by element.
Name | Type | Description |
---|---|---|
vectorA |
Array.<number> | |
vectorB |
Array.<number> |
- Type
- number
# v2_max(vectorA, vectorB) → {Array.<number>}
Maximum of two vectors, compared element by element.
Name | Type | Description |
---|---|---|
vectorA |
Array.<number> | |
vectorB |
Array.<number> |
- Type
- Array.<number>
# v2_angle(vectorA, vectorB) → {number}
Angle in radian between two vectors.
Name | Type | Description |
---|---|---|
vectorA |
Array.<number> | |
vectorB |
Array.<number> |
- Type
- number
# v2_lerp(vectorA, vectorB, interpolation) → {Array.<number>}
Linear interpolation between two vectors
Name | Type | Description |
---|---|---|
vectorA |
Array.<number> | |
vectorB |
Array.<number> | |
interpolation |
number | value between 0 and 1 |
- Type
- Array.<number>
# v2_equals(vectorA, vectorB, epsilonopt) → {boolean}
Checks for vector equality within an epsilon.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
vectorA |
Array.<number> | |||
vectorB |
Array.<number> | |||
epsilon |
number |
<optional> |
0 |
- Type
- boolean
# v2_isZero(vector) → {boolean}
Checks if vector is [0,0]
Name | Type | Description |
---|---|---|
vector |
Array.<number> |
- Type
- boolean
# v2_manhattan(vector) → {number}
Manhattan distance of vector
Name | Type | Description |
---|---|---|
vector |
Array.<number> |
- Type
- number
# v2_transform(vector, matrix) → {Array.<number>}
Multiplies vector by a 2x2 matrix
Name | Type | Description |
---|---|---|
vector |
Array.<number> | |
matrix |
Array.<number> |
- Type
- Array.<number>
# v2_rotate(vector, angle) → {Array.<number>}
Rotate clockwise. Angle in radians.
Name | Type | Description |
---|---|---|
vector |
Array.<number> | |
angle |
number |
- Type
- Array.<number>
# v3_zero() → {Array.<number>}
Null 2-vector [0,0]
- Type
- Array.<number>
# v3_random() → {Array.<number>}
Random point on a unit sphere.
- Type
- Array.<number>
# v3_magnitude(vector) → {number}
Magnitude of vector.
Name | Type | Description |
---|---|---|
vector |
Array.<number> |
- Type
- number
# v3_sqrMag(vector) → {number}
Squared magnitude of vector.
Name | Type | Description |
---|---|---|
vector |
Array.<number> |
- Type
- number
# v3_normalize(vector) → {Array.<number>}
Normalized vector. (Error on magnitude 0)
Name | Type | Description |
---|---|---|
vector |
Array.<number> |
- Type
- Array.<number>
# v3_abs(vector) → {Array.<number>}
Absolute value of all elements.
Name | Type | Description |
---|---|---|
vector |
Array.<number> |
- Type
- Array.<number>
# v3_ceil(vector) → {Array.<number>}
Ceiling of all elements.
Name | Type | Description |
---|---|---|
vector |
Array.<number> |
- Type
- Array.<number>
# v3_floor(vector) → {Array.<number>}
Floor of all elements.
Name | Type | Description |
---|---|---|
vector |
Array.<number> |
- Type
- Array.<number>
# v3_inverse(vector) → {Array.<number>}
Reciprocal of all elements.
Name | Type | Description |
---|---|---|
vector |
Array.<number> |
- Type
- Array.<number>
# v3_scale(vector, number) → {Array.<number>}
Multiply all elements by a constant scale factor.
Name | Type | Description |
---|---|---|
vector |
Array.<number> | |
number |
scale |
- Type
- Array.<number>
# v3_multiply(vectorA, vectorB) → {Array.<number>}
Multiply individual elements of two vectors
Name | Type | Description |
---|---|---|
vectorA |
Array.<number> | |
vectorB |
Array.<number> |
- Type
- Array.<number>
# v3_add(vectorA, vectorB) → {Array.<number>}
Add two vectors
Name | Type | Description |
---|---|---|
vectorA |
Array.<number> | |
vectorB |
Array.<number> |
- Type
- Array.<number>
# v3_sub(vectorA, vectorB) → {Array.<number>}
Subtract two vectors
Name | Type | Description |
---|---|---|
vectorA |
Array.<number> | |
vectorB |
Array.<number> |
- Type
- Array.<number>
# v3_dot(vectorA, vectorB) → {number}
Dot product of two vectors
Name | Type | Description |
---|---|---|
vectorA |
Array.<number> | |
vectorB |
Array.<number> |
- Type
- number
# v3_cross(vectorA, vectorB) → {number}
Cross product of two vectors
Name | Type | Description |
---|---|---|
vectorA |
Array.<number> | |
vectorB |
Array.<number> |
- Type
- number
# v3_min(vectorA, vectorB) → {number}
Minimum of two vectors, compared element by element.
Name | Type | Description |
---|---|---|
vectorA |
Array.<number> | |
vectorB |
Array.<number> |
- Type
- number
# v3_max(vectorA, vectorB) → {Array.<number>}
Maximum of two vectors, compared element by element.
Name | Type | Description |
---|---|---|
vectorA |
Array.<number> | |
vectorB |
Array.<number> |
- Type
- Array.<number>
# v3_angle(vectorA, vectorB) → {number}
Angle in radian between two vectors.
Name | Type | Description |
---|---|---|
vectorA |
Array.<number> | |
vectorB |
Array.<number> |
- Type
- number
# v3_lerp(vectorA, vectorB, t) → {Array.<number>}
Linear interpolation between two vectors
Name | Type | Description |
---|---|---|
vectorA |
Array.<number> | |
vectorB |
Array.<number> | |
t |
number | value between 0 and 1 |
- Type
- Array.<number>
# v3_equals(vectorA, vectorB, epsilonopt) → {boolean}
Checks for vector equality within an epsilon.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
vectorA |
Array.<number> | |||
vectorB |
Array.<number> | |||
epsilon |
number |
<optional> |
0 |
- Type
- boolean
# v3_isZero(vector) → {boolean}
Checks if vector is [0,0,0]
Name | Type | Description |
---|---|---|
vector |
Array.<number> |
- Type
- boolean
# v3_manhattan(vector) → {number}
Manhattan distance of vector
Name | Type | Description |
---|---|---|
vector |
Array.<number> |
- 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)
Name | Type | Description |
---|---|---|
vector |
Array.<number> | |
matrix |
Array.<number> |
- Type
- Array.<number>
# v3_rotateX(vector, angle) → {Array.<number>}
Rotate around x axis. Angle in radians. Clockwise looking along axis
Name | Type | Description |
---|---|---|
vector |
Array.<number> | |
angle |
number |
- Type
- Array.<number>
# v3_rotateY(vector, angle) → {Array.<number>}
Rotate around y axis. Angle in radians. Clockwise looking along axis
Name | Type | Description |
---|---|---|
vector |
Array.<number> | |
angle |
number |
- Type
- Array.<number>
# v3_rotateZ(vector, angle) → {Array.<number>}
Rotate around z axis. Angle in radians. Clockwise looking along axis
Name | Type | Description |
---|---|---|
vector |
Array.<number> | |
angle |
number |
- Type
- Array.<number>
# v3_rotate(vector, quaternion) → {Array.<number>}
Rotate by a quaternion
Name | Type | Description |
---|---|---|
vector |
Array.<number> | |
quaternion |
Array.<number> |
- Type
- Array.<number>
# q_identity() → {Array.<number>}
Identity quaternion
- Type
- Array.<number>
# q_normalize(quaternion) → {Array.<number>}
Normalize quaternion. (If you do a long series of quaternion operations, periodically renormalize to prevent drift.)
Name | Type | Description |
---|---|---|
quaternion |
Array.<number> |
quaternion
- Type
- Array.<number>
# q_invert(quaternion) → {Array.<number>}
Reverse the rotation.
Name | Type | Description |
---|---|---|
quaternion |
Array.<number> |
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.
Name | Type | Description |
---|---|---|
axis |
Array.<number> | |
angle |
number |
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.
Name | Type | Description |
---|---|---|
forward |
Array.<number> | |
up |
Array.<number> | |
target |
Array.<number> |
quaternion
- Type
- Array.<number>
# q_euler(x, y, z) → {Array.<number>}
Creates a quaternion from the given Euler angles. All angles are in radians.
Name | Type | Description |
---|---|---|
x |
number | |
y |
number | |
z |
number |
quaternion
- Type
- Array.<number>
# q_pitch(quaternion) → {number}
Extracts the Euler angle around the x axis from a quaternion.
Name | Type | Description |
---|---|---|
quaternion |
Array.<number> |
angle
- Type
- number
# q_yaw(quaternion) → {number}
Extracts the Euler angle around the y axis from a quaternion.
Name | Type | Description |
---|---|---|
quaternion |
Array.<number> |
angle
- Type
- number
# q_roll(quaternion) → {number}
Extracts the Euler angle around the z axis from a quaternion.
Name | Type | Description |
---|---|---|
quaternion |
Array.<number> |
angle
- Type
- number
# q_multiply(quaternionA, quaternionB) → {Array.<number>}
Combines two rotations. QuaternionA is applied before quaternionB.
Name | Type | Description |
---|---|---|
quaternionA |
Array.<number> | |
quaternionB |
Array.<number> |
quaternion
- Type
- Array.<number>
# q_slerp(quaternionA, quaternionB, t) → {Array.<number>}
Interpolates between two rotations.
Name | Type | Description |
---|---|---|
quaternionA |
Array.<number> | |
quaternionB |
Array.<number> | |
t |
number | value between 0 and 1 |
quaternion
- Type
- Array.<number>
# q_equals(quaternionA, quaternionB, epsilonopt) → {boolean}
Checks for quaternion equality within an epsilon.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
quaternionA |
Array.<number> | |||
quaternionB |
Array.<number> | |||
epsilon |
number |
<optional> |
0.0001 |
- Type
- boolean
# q_isZero(quaternion) → {boolean}
Checks if quaternion is [0,0,0,1]
Name | Type | Description |
---|---|---|
quaternion |
Array.<number> |
- Type
- boolean
# m2_zero() → {Array.<number>}
Returns a 2x2 zero Matrix
2x2 Matrix
- Type
- Array.<number>
# m2_identity() → {Array.<number>}
Returns a 2x2 identity matrix
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.
Name | Type | Description |
---|---|---|
angle |
number |
2x2 Matrix
- Type
- Array.<number>
# m4_zero() → {Array.<number>}
Returns a 4x4 zero matrix
2x2 Matrix
- Type
- Array.<number>
# m4_identity() → {Array.<number>}
Returns a 4x4 identity matrix
4x4 Matrix
- Type
- Array.<number>
# m4_translation(translation) → {Array.<number>}
Creates a 4x4 transform matrix from a 3-vector translation.
Name | Type | Description |
---|---|---|
translation |
Array.<number> |
4x4 Matrix
- Type
- Array.<number>
# m4_getTranslation(matrix) → {Array.<number>}
Extracts the translation from a 4x4 transform matrix.
Name | Type | Description |
---|---|---|
matrix |
Array.<number> |
3-vector
- Type
- Array.<number>
# m4_scale(scale) → {Array.<number>}
Creates a 4x4 transform matrix from a 3-vector scale, or a scale constant.
Name | Type | Description |
---|---|---|
scale |
Array.<number> | number |
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.
Name | Type | Description |
---|---|---|
axis |
Array.<number> | |
angle |
number |
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.
Name | Type | Description |
---|---|---|
angle |
number |
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.
Name | Type | Description |
---|---|---|
angle |
number |
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.
Name | Type | Description |
---|---|---|
angle |
number |
4x4 Matrix
- Type
- Array.<number>
# m4_rotationQ(rotation) → {Array.<number>}
Creates a 4x4 rotation matrix from a quaternion.
Name | Type | Description |
---|---|---|
rotation |
Array.<number> |
4x4 Matrix
- Type
- Array.<number>
# m4_getRotation(matrix) → {Array.<number>}
Extracts the rotation quaternion from a 4x4 transform matrix.
Name | Type | Description |
---|---|---|
matrix |
Array.<number> |
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.
Name | Type | Description |
---|---|---|
scale |
Array.<number> | number | |
rotation |
Array.<number> | |
translation |
Array.<number> |
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.
Name | Type | Description |
---|---|---|
fov |
number | |
aspect |
number | |
near |
number | |
far |
number |
4x4 Matrix
- Type
- Array.<number>
# m4_transpose(matrix) → {Array.<number>}
Returns the transpose of a 4x4 matrix
Name | Type | Description |
---|---|---|
matrix |
Array.<number> |
4x4 Matrix
- Type
- Array.<number>
# m4_determinant(matrix) → {number}
Returns the determinant of a 4x4 matrix
Name | Type | Description |
---|---|---|
matrix |
Array.<number> |
Determinant
- Type
- number
# m4_invert(matrix) → {Array.<number>}
Returns the inverse of a 4x4 matrix
Name | Type | Description |
---|---|---|
matrix |
Array.<number> |
4x4 Matrix
- Type
- Array.<number>
# m4_multiply(matrixA, matrixB) → {Array.<number>}
Multiply two 4x4 matrices
Name | Type | Description |
---|---|---|
matrixA |
Array.<number> | |
matrixB |
Array.<number> |
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.
Name | Type | Description |
---|---|---|
matrix |
Array.<number> |
4x4 Matrix
- Type
- Array.<number>