Matrix

class Matrix()

Object representing the 4x4 Matrix. More information can be found [here](https://docs.techsoft3d.com/communicator/latest/prog_guide/viewing/model_attributes/matrices.html).

Constructors

Properties


Constructors

Matrix.constructor()

Creates a new matrix set to the identity matrix.

Return type:Matrix

Properties

Matrix.m
Type:Matrix16

Methods

assign

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

Sets the value of this matrix to another.

Returns:This matrix object.
Return type:this

copy

Matrix.copy()

Creates a copy of this matrix.

Returns:Copy of this matrix.
Return type:Matrix

equals

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

Strictly compares this matrix with another.

Returns:True if the values of this matrix equal those of the other.
Return type:boolean

equalsWithTolerance

Matrix.equalsWithTolerance(other, tolerance)
Arguments:
  • other (Matrix()) – Matrix to compare with.
  • tolerance (number()) – Tolerance to be used in the comparison.

Compares this matrix with another using a tolerance.

Returns:True if the values of this matrix equal those of the other.
Return type:boolean

inverseAndDeterminant

Matrix.inverseAndDeterminant()

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

Returns:An array containing the inverse (or null if not invertible) followed by the determinant
Return type:(null | Matrix, number)

isIdentity

Matrix.isIdentity()
Return type:boolean

loadIdentity

Matrix.loadIdentity()

Sets the matrix to the identity matrix.

Returns:This matrix object.
Return type:this

multiplyByScalar

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

Multiply the matrix by given scalar.

Returns:This matrix object.
Return type:this

normalMatrix

Matrix.normalMatrix()
Returns:the version of this matrix suitable for applying to normals, i.e. the inverse transpose of the upper-left 3x3 submatrix.
Return type:null | Matrix

setScaleComponent

Matrix.setScaleComponent(x, y, z)
Arguments:
  • x (number()) – X scale value.
  • y (number()) – Y scale value.
  • z (number()) – Z scale value.

Sets the scale components of this matrix.

Returns:This matrix object.
Return type:this

setTranslationComponent

Matrix.setTranslationComponent(x, y, z)
Arguments:
  • x (number()) – X translation value.
  • y (number()) – Y translation value.
  • z (number()) – Z translation value.

Sets the translation components of this matrix.

Returns:This matrix object.
Return type:this

toJson

Matrix.toJson()

Creates an object ready for JSON serialization.

Returns:The prepared object.
Return type:[number]

transform

Matrix.transform(point[, result])
Arguments:
  • point (Point3()) – The point to be transformed.
  • result (Point3()) – optional A Point3 which can hold the result of the transformation.

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

Returns:A new point if result is undefined, result otherwise.
Return type:Point3

transform4

Matrix.transform4(point[, result])
Arguments:
  • point (Point4()) – The point to be transformed.
  • result (Point4()) – optional A Point3 which can hold the result of the transformation.

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

Returns:A new point if result is undefined, result otherwise.
Return type:Point4

transformArray

Matrix.transformArray(inPoints, outPoints)
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.

Transforms an array of points according to this matrix.

Return type:void

transformBox

Matrix.transformBox(inBox)
Arguments:
Return type:

Box

transpose

Matrix.transpose()

Sets this matrix equal to its transpose.

Returns:This matrix object.
Return type:this

upperLeft3x3Determinant

Matrix.upperLeft3x3Determinant()

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

Return type:number

static createFromArray

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

Creates a matrix from an array of numbers.

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

static createFromBasis

Matrix.createFromBasis(xAxis, yAxis, zAxis)
Arguments:

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

Return type:Matrix

static createFromOffAxisRotation

Matrix.createFromOffAxisRotation(axis, degrees)
Arguments:
  • axis (Point3()) – Axis to rotate about.
  • degrees (number()) – Amount of degrees to rotate about the provided axis.

Creates a rotation matrix from an arbitrary axis.

Returns:Rotation matrix which represents the rotation about the supplied axis.
Return type:Matrix

static fromJson

Matrix.fromJson(obj)
Arguments:
  • obj (unknown()) – None

Creates a new [[Matrix]] from an object given by [[toJson]].

Returns:The prepared object.
Return type:Matrix

static inverse

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

Computes the inverse of a matrix if possible.

Returns:Matrix set to the inverse of the supplied matrix.
Return type:null | Matrix

static multiply

Matrix.multiply(m1, m2)
Arguments:

Multiplies two matrices.

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

Returns:Matrix which is the result of the multiplication.
Return type:Matrix

static xAxisRotation

Matrix.xAxisRotation(degrees)
Arguments:
  • degrees (number()) – The degrees of the rotation.

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

Returns:The rotation matrix.
Return type:Matrix

static yAxisRotation

Matrix.yAxisRotation(degrees)
Arguments:
  • degrees (number()) – The degrees of the rotation.

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

Returns:The rotation matrix.
Return type:Matrix

static zAxisRotation

Matrix.zAxisRotation(degrees)
Arguments:
  • degrees (number()) – The degrees of the rotation.

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

Returns:The rotation matrix.
Return type:Matrix