Operations

add(a1, a2[, result])
Arguments:
  • a1 (Matrix) – first operand
  • a2 (Matrix) – second operand
  • result (Matrix) – result buffer
Returns:

result

Adds two buffers of the same size.

subtract(a1, a2[, result])
Arguments:
  • a1 (Matrix) – first operand
  • a2 (Matrix) – second operand
  • result (Matrix) – result buffer
Returns:

result

Subtracts two buffers of the same size.

scale(a, s[, result])
Arguments:
  • a (Matrix) – buffer
  • s (number) – scalar
  • result (Matrix) – result
Returns:

result

Scales a buffer by multiplying each component by a scalar.

equal(a1, a2[, e])
Arguments:
  • a1 (Matrix) – first operand
  • a2 (Matrix) – second operand
  • e (number) – comparision tolerance, defaults to 10E-5
Returns:

true if operands are equal (within tolerance), false otherwise

Compares two buffers component-wise for equality. Differences smaller than e are ignored.

clone(a[, result])
Arguments:

Creates a component-wise copy of a buffer.

clear(a[, s])
Arguments:
  • a (Matrix) – buffer
  • s (number) – scalar, defaults to 0

Clears a buffer by writing a scalar into each component.

toMathML(a)
Arguments:

Converts a buffer to MathML representation.

toString(a)
Arguments:

Converts a buffer to string representation.

Vector

set(v, values)
Arguments:
  • v (Vector) – vector
  • values (Array) – array of values
Returns:

v

length(v)
Arguments:
Returns:

length of v

length2(v)
Arguments:
Returns:

squared length of v

dot(v1, v2)
Arguments:
  • v1 (Vector) – first vector
  • v2 (Vector) – second vector
Returns:

inner product of v1 and v2

negate(v[, result])
Arguments:
Returns:

negation of v

limit(v, s[, result])
Arguments:
  • v (Vector) – vector
  • s (number) – scalar limit
Returns:

v resized to have length at most s

normalize(v[, result])
Arguments:
Returns:

a unit vector in the direction of v

distance(v1, v2)
Arguments:
  • v1 (Vector) – origin vector
  • v2 (Vector) – target vector
Returns:

the distance from v1 to v2

angle(v1, v2)
Arguments:
  • v1 (Vector) – first vector
  • v2 (Vector) – second vector
Returns:

the angle betwen v1 and v2

lerp(v1, v2, s[, result])
Arguments:
  • v1 (Vector) – origin vector
  • v2 (Vector) – target vector
  • s (number) – interpolation scalar
  • result (Vector) – result
Returns:

interpolation from v1 to v2 by s

direction(v1, v2[, result])
Arguments:
Returns:

unit vector pointing from v1 to v2

extract(v, offset, length[, result])
Arguments:
  • v (Vector) – vector
  • offset (number) – offset from the start ov v
  • length (number) – number of elements to extract
  • result (Vector) – result
Returns:

length elements of v, starting from offset

zero(v)
Arguments:
Returns:

v with all components 0

zero(d)
Arguments:
  • d (number) – dimension
Returns:

a new Vector with all components 0

one(v)
Arguments:
Returns:

v with all components 1

one(d)
Arguments:
  • d (number) – dimension
Returns:

a new Vector with all components 1

Vector2

x([result])
Arguments:
Returns:

2-dimensional y unit vector (1, 0)

y([result])
Arguments:
Returns:

2-dimensional y unit vector (0, 1)

u([result])
Arguments:
Returns:

2-dimensional u unit vector (1, 0)

v([result])
Arguments:
Returns:

2-dimensional v unit vector (0, 1)

Vector3

cross(v1, v2[, result])
Arguments:
Returns:

outer product of v1 and v2

unproject(v, view, projection, viewport[, result])

Note

Not yet implemented

Arguments:
  • v (Vector) – screen space vector
  • view (Matrix) – view matrix
  • projection (Matrix) – projection matrix
  • viewport (Array) – viewport parameters, as [x, y, width, height]
  • result (Vector) – result
Returns:

vector projected from screen space to object space

x([result])
Arguments:
Returns:

3-dimensional y unit vector (1, 0, 0)

y([result])
Arguments:
Returns:

3-dimensional y unit vector (0, 1, 0)

z([result])
Arguments:
Returns:

3-dimensional z unit vector (0, 0, 1)

Vector4

x([result])
Arguments:
Returns:

4-dimensional y unit vector (1, 0, 0, 0)

y([result])
Arguments:
Returns:

4-dimensional y unit vector (0, 1, 0, 0)

z([result])
Arguments:
Returns:

4-dimensional z unit vector (0, 0, 1, 0)

w([result])
Arguments:
Returns:

4-dimensional w unit vector (0, 0, 0, 1)

Quaternion

inverse(q[, result])
Arguments:
Returns:

inverse of q

conjugate(q[, result])
Arguments:
Returns:

conjugate of q

identity([result])
Arguments:
Returns:

the identity quaternion (0, 0, 0, 1)

slerp(q1, q2, s[, result])
Arguments:
Returns:

spherical linear interpolation between q1 and q2

rotation(v1, v2[, result])

Note

Not yet implemented

Arguments:
Returns:

quaternion of rotation between two 3-dimensional vectors

toAxisAngle(q[, result])
Arguments:
Returns:

axis-angle representated as a 3-dimensional vector

fromAxisAngle(v[, result])
Arguments:
Returns:

quaternion computed from axis-angle as a 3-dimensional vector

Matrix

multiply(m1, m2[, reuslt])
Arguments:
Returns:

the matrix product of m1 with m2

inverse(m[, result])

Note

Valid for square matrices only

Arguments:
Returns:

inverse of m

transpose(m[, result])

Note

Implemented for square matrices only

Arguments:
Returns:

transpose of m

identity(m)

Note

Valid for square matrices only

Arguments:
  • m (Matrix) – square matrix
Returns:

identity matrix

identity(d)
Arguments:
  • d (number) – dimension
Returns:

identity matrix of dimension d

extract(m, rowOffset, columnOffset, rows, columns[, result])

Note

Not yet implemented

Arguments:
  • m (Matrix) – matrix
  • rowOffset (number) – starting row
  • columnOffset (number) – starting column
  • rows (number) – number of rows to extract
  • columns (number) – number of columns to extract
  • result (Matrix) – result
Returns:

sub-matrix of m

Matrix2

toAngle(m)
Arguments:
  • m (Matrix) – rotation matrix
Returns:

angle in radians

fromAngle(angle[, result])
Arguments:
  • angle (number) – angle in radians
  • result (Matrix) – result
Returns:

2-dimensional rotation matrix

Matrix3

toQuaternion(m[, result])

Note

Not yet implemented

Arguments:
Returns:

quaternion rotation

fromQuaternion(q[, result])

Note

Not yet implemented

Arguments:
Returns:

rotation matrix

toAxisAngle(m[, result])

Note

Not yet implemented

Arguments:
Returns:

axis-angle vector

fromAxisAngle(v[, result])

Note

Not yet implemented

Arguments:
  • v (Vector) – axis-angle vector
  • result (Matrix) – result
Returns:

rotation matrix

Transform

translate(left, right[, result])

Note

One of the operands must be a Transform

Arguments:
  • left – left operand
  • right – right operand
  • result (Transform) – result
Returns:

transform with translation applied

The translation should be expressed as a 3-dimensional vector.

rotate(left, right[, result])

Note

One of the operands must be a Transform

Arguments:
  • left – left operand
  • right – right operand
  • result (Transform) – result
Returns:

transform with rotation applied

The rotation should be expressed as an angle or rotation matrix for 2 dimensions, or rotation matrix, axis-angle or quaternion for 3 dimensions.

scale(left, right[, result])

Note

One of the operands must be a Transform

Arguments:
  • left – left operand
  • right – right operand
  • result (Transform) – result
Returns:

transform with scaling applied

The scaling should be expressed as a vector, with each component specifying the factor in the corresponding dimension.

linear(t[, result])
Arguments:
Returns:

linear part (rotation and scaling) of the affine transform

svd(t, translation, rotation, scaling)
Arguments:
  • t (Transform) – transform
  • translation (Vector) – result vector to store translation
  • rotation (Quaternion) – result quaternion to store rotation
  • scaling (Vector) – result vector to store scaling

Table Of Contents

Previous topic

Types

Next topic

Constants

This Page