Matrix

class Communicator.Matrix()

Object representing the 4x4 Matrix. More information can be found here.

Constructors

Properties


Constructors

Matrix.constructor()

Creates a new matrix set to the identity matrix.

Return type

Matrix()

Properties

Matrix.m
Type

SC.Matrix16

Methods

assign

Matrix.assign(matrix)

Sets the value of this matrix to another.

Arguments
  • matrix (Matrix()) – the matrix whose values will be set.

Return type

Matrix()

Returns

This matrix object.

copy

Matrix.copy()

Creates a copy of this matrix.

Return type

Matrix()

Returns

Copy of this matrix.

equals

Matrix.equals(other)

Strictly compares this matrix with another.

Arguments
  • other (Matrix()) – Matrix to compare with.

Return type

boolean

Returns

True if the values of this matrix equal those of the other.

equalsWithTolerance

Matrix.equalsWithTolerance(other, tolerance)

Compares this matrix with another using a tolerance.

Arguments
  • other (Matrix()) – Matrix to compare with.

  • tolerance (number()) – Tolerance to be used in the comparison.

Return type

boolean

Returns

True if the values of this matrix equal those of the other.

forJson

Matrix.forJson()
Deprecated

Use toJson instead.

Return type

Object

inverseAndDeterminant

Matrix.inverseAndDeterminant()

Computes the determinant and inverse of a matrix, if possible.

Return type

(Matrix() | null, number)

Returns

An array containing the inverse (or null if not invertible) followed by the determinant

isIdentity

Matrix.isIdentity()
Return type

boolean

loadIdentity

Matrix.loadIdentity()

Sets the matrix to the identity matrix.

Return type

Matrix()

Returns

This matrix object.

multiplyByScalar

Matrix.multiplyByScalar(scalar)

Multiply the matrix by given scalar.

Arguments
  • scalar (number()) – Scalar to multiply the matrix with.

Return type

Matrix()

Returns

This matrix object.

normalMatrix

Matrix.normalMatrix()
Return type

Matrix() | null

Returns

the version of this matrix suitable for applying to normals, i.e. the inverse transpose of the upper-left 3x3 submatrix.

scale

Matrix.scale(k)

Scales all elements of the matrix.

Deprecated

For multiplying all elements by a scalar see scalarMultiply For setting scale component see setScaleComponent

Arguments
  • k (number()) – Constant value to scale elements by.

Return type

Matrix()

Returns

This matrix object.

setScaleComponent

Matrix.setScaleComponent(x, y, z)

Sets the scale components of this matrix.

Arguments
  • x (number()) – X scale value.

  • y (number()) – Y scale value.

  • z (number()) – Z scale value.

Return type

Matrix()

Returns

This matrix object.

setTranslationComponent

Matrix.setTranslationComponent(x, y, z)

Sets the translation components of this matrix.

Arguments
  • x (number()) – X translation value.

  • y (number()) – Y translation value.

  • z (number()) – Z translation value.

Return type

Matrix()

Returns

This matrix object.

toJson

Matrix.toJson()

Creates an object ready for JSON serialization.

Return type

[number]

Returns

The prepared object.

transform

Matrix.transform(point, result)

Transforms a point according to this matrix. The source and destination points are allowed to be the same object.

Arguments
  • point (Point3()) – The point to be transformed.

  • result (Point3()) – Point which will hold the result of the transformation.

Return type

void

Matrix.transform(point)

Transforms a point according to this matrix.

Arguments
  • point (Point3()) – The point to be transformed.

Return type

Point3()

Returns

A new point which will hold the result of the transformation.

transform4

Matrix.transform4(point, result)

Transforms a point according to this matrix. The source and destination points are allowed to be the same object.

Arguments
  • point (Point4()) – The point to be transformed.

  • result (Point4()) – Point which will hold the result of the transformation.

Return type

void

Matrix.transform4(point)

Transforms a point according to this matrix.

Arguments
  • point (Point4()) – The point to be transformed.

Return type

Point4()

Returns

A new point which will hold the result of the transformation.

transformArray

Matrix.transformArray(inPoints, outPoints)

Transforms an array of points according to this matrix.

Arguments
  • inPoints ([Point3()]) – an array of points to be transformed.

  • outPoints ([Point3()]) – an array that will be populated with transformed points. Note that the results will be pushed onto the end of the array.

Return type

void

transformBox

Matrix.transformBox(inBox)
Arguments
Return type

Box()

transpose

Matrix.transpose()

Sets this matrix equal to its transpose.

Return type

Matrix()

Returns

This matrix object.

upperLeft3x3Determinant

Matrix.upperLeft3x3Determinant()

Computes the determinant of the upper-left 3x3 subsection of this matrix.

Return type

number

static construct

Matrix.construct(obj)
Deprecated

Use fromJson instead.

Arguments
  • obj (any()) –

Return type

Matrix()

static createFromArray

Matrix.createFromArray(arr)

Creates a matrix from an array of numbers.

Arguments
  • arr ([number]()) – 16 element array of numbers.

Return type

Matrix()

Returns

New matrix with elements set to the values of the array parameter. Array elements will be in column-major order.

static createFromBasis

Matrix.createFromBasis(xAxis, yAxis, zAxis)

Creates a matrix from three [[Point3]]s, which will be used as the columns of the matrix.

Arguments
Return type

Matrix()

static createFromOffAxisRotation

Matrix.createFromOffAxisRotation(axis, degrees)

Creates a rotation matrix from an arbitrary axis.

Arguments
  • axis (Point3()) – Axis to rotate about.

  • degrees (Degrees) – Amount of degrees to rotate about the provided axis.

Return type

Matrix()

Returns

Rotation matrix which represents the rotation about the supplied axis.

static fromJson

Matrix.fromJson(obj)

Creates a new Matrix from an object given by toJson

Arguments
  • obj (any()) –

Return type

Matrix()

Returns

The prepared object.

static inverse

Matrix.inverse(matrix)

Computes the inverse of a matrix if possible.

Arguments
  • matrix (Matrix()) – Matrix whose inverse will be computed.

Return type

Matrix() | null

Returns

Matrix set to the inverse of the supplied matrix.

static multiply

Matrix.multiply(m1, m2)

Multiplies two matrices.

(p’ = ABp <=> p’ = multiply(B, A).transform(p))

Arguments
Return type

Matrix()

Returns

Matrix which is the result of the multiplication.

(p’ = ABp <=> p’ = multiply(B, A).transform(p))

static xAxisRotation

Matrix.xAxisRotation(degrees)

Returns the matrix for a clockwise rotation around the X-axis.

Arguments
  • degrees (Degrees) – The degrees of the rotation.

Return type

Matrix()

Returns

The rotation matrix.

static yAxisRotation

Matrix.yAxisRotation(degrees)

Returns the matrix for a clockwise rotation around the Y-axis.

Arguments
  • degrees (Degrees) – The degrees of the rotation.

Return type

Matrix()

Returns

The rotation matrix.

static zAxisRotation

Matrix.zAxisRotation(degrees)

Returns the matrix for a clockwise rotation around the Z-axis.

Arguments
  • degrees (Degrees) – The degrees of the rotation.

Return type

Matrix()

Returns

The rotation matrix.