Class: Matrix4x4

RS.Math.Matrix4x4

Class representing a row major 4x4 Matrix.

new RS.Math.Matrix4x4 (initial)

Creates a new Matrix4x4. Accepts any arguments that RS.Math.Matrix4x4#set accepts.

Name Type Description
initial RS.Math.Matrix4x4 | Array | Object | Number optional

initial value.

Example
let m = new RS.Math.Matrix4x4();
m = new RS.Math.Matrix4x4(11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34, 41, 42, 43, 44);
m = new RS.Math.Matrix4x4([11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34, 41, 42, 43, 44]);
m = new RS.Math.Matrix4x4([
               [11, 12, 13, 14],
               [21, 22, 23, 24],
               [31, 32, 33, 34],
               [41, 42, 43, 44]
]);
m = new RS.Math.Matrix4x4({
               xx:11, xy: 12, xz: 13, xw: 14,
               yx:21, yy: 22, yz: 23, yw: 24,
               zx:31, zy: 32, zz: 33, zw: 34,
               wx:41, wy: 42, wz: 43, ww: 44
});

Members

ww Number

The ww component of the vector

wx Number

The wx component of the vector

wy Number

The wy component of the vector

wz Number

The wz component of the vector

xw Number

The xw component of the vector

xx Number

The xx component of the vector

xy Number

The xy component of the vector

xz Number

The xz component of the vector

yw Number

The yw component of the vector

yx Number

The yx component of the vector

yy Number

The yy component of the vector

yz Number

The yz component of the vector

zw Number

The zw component of the vector

zx Number

The zx component of the vector

zy Number

The zy component of the vector

zz Number

The zz component of the vector

Methods

clear ()

Clear this matrix by setting all elements to 0.

Returns a copy of this matrix.

Returns:
Type Description
RS.Math.Matrix4x4

equal (rhs, tolerance)Boolean

Returns whether this matrix is equal to another matrix.

Name Type Description
rhs RS.Math.Matrix4x4

the matrix to compare to

tolerance Number optional

if provided then this level of tolerance is used.

Returns:
Type Description
Boolean true if equal, false if not

equal_with_tolerance (rhs, tolerance)Boolean

Returns whether this matrix is equal to another matrix within a tolerance.

Name Type Description
rhs RS.Math.Matrix4x4

the matrix to compare to

tolerance Number optional

if provided then this level of tolerance is used, otherwise tolerance is 10e-5

Returns:
Type Description
Boolean true if equal, false if not

get_determinant ()Number

Returns the determinant of this matrix.

Returns:
Type Description
Number

Sets this matrix to it's inverse. Throws if the matrix cannot be inverted.

Returns:
Type Description
RS.Math.Matrix4x4 this

multiply (matrix)RS.Math.Matrix4x4

Multiples another matrix on the left side of this matrix. Equivalent to this = matrix * this

Name Type Description
matrix RS.Math.Matrix4x4

The matrix on the left hand side of the multiplication

Returns:
Type Description
RS.Math.Matrix4x4 this

set (source)

Sets this matrix. The source may be of the following types:

  • RS.Math.Matrix4x4
  • an Array with 16 or more Number members which will set the matrix in row major order.
  • an Array of 4 or more Array members (each of length 4 or more) which will set the rows of the matrix.
  • an Object.
  • a single Number which will set the array diagonal to that value.
  • 16 or more individual Numbers which will set the matrix in row major order.

In the case of an object being supplied it should have the members xx, xy, xz, xw,yx, yy, yz, yw, zx, zy, zz, zw, wx, wy, wz, ww.

Name Type Description
source RS.Math.Matrix4x4 | Array | Object | Number

the object to set from or a set of numbers.

Example
const m = new RS.Math.Matrix4x4();
m.set(1); // sets the identify matrix
// the following are equivalent
m.set(11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34, 41, 42, 43, 44);
m.set([11, 12, 13, 14, 21, 22, 23, 24, 31, 32, 33, 34, 41, 42, 43, 44]);
m.set([[11, 12, 13, 14],
       [21, 22, 23, 24],
       [31, 32, 33, 34],
       [41, 42, 43, 44]]);
m.set({xx:11, xy:12, xz:13, wz:14,
       yx:21, yy:22, yz:23, yw:24,
       zx:31, zy:32, zz:33, zw:34,
       wx:41, wy:42, wz:43, ww:44});

set_identity ()

Sets this matrix to the identity matrix.

set_rotation (axis, angle)

Sets this matrix to be a rotation matrix.

Name Type Description
axis RS.Math.Vector4 | RS.Math.Vector3

The vector to rotate around.

angle Number

The angle to rotate around the axis in radians.

set_scaling (x, y, z)

Sets this matrix to a scaling matrix.

Name Type Description
x Number

The amount to scale in the x axis.

y Number

The amount to scale in the y axis.

z Number

The amount to scale in the z axis.

set_translation (x, y, z)

Sets the translation elements of this matrix while leaving the rest of the matrix untouched.

Name Type Description
x Number

The x value

y Number

The y value

z Number

The z value

toString ()String

Returns a string describing this Object.

Returns:
Type Description
String A String describing this Object.

translate (dx, dy, dz)

Increases the translation elements of this matrix while leaving the rest of the matrix untouched.

Name Type Description
dx Number

The x value to add

dy Number

The y value to add

dz Number

The z value to add

transpose ()RS.Math.Matrix4x4

Sets this matrix to it's transpose.

Returns:
Type Description
RS.Math.Matrix4x4 this