Class Matrix3

A class representing a 3x3 matrix.

Example

const m = new Matrix3();

Remark

A Note on Row-Major and Column-Major Ordering The set() method takes arguments in row-major order, while internally they are stored in the elements array in column-major order.

This means that calling

m.set( 11, 12, 13,
21, 22, 23,
31, 32, 33 );

will result in the elements array containing:

m.elements = [ 11, 21, 31,
12, 22, 32,
13, 23, 33 ];

and internally all calculations are performed using column-major ordering. However, as the actual ordering makes no difference mathematically and most people are used to thinking about matrices in row-major order, the three.js documentation shows matrices in row-major order. Just bear in mind that if you are reading the source code, you'll have to take the transpose of any matrices outlined here to make sense of the calculations.

Hierarchy

  • Base
    • Matrix3

Implements

Constructors

  • Creates and initializes the Matrix3 to the 3x3 identity matrix.

    Returns Matrix3

Properties

elements: number[]

A column-major list of matrix values.

Default

[1, 0, 0, 0, 1, 0, 0, 0, 1]

Accessors

  • get isBox2(): boolean
  • Returns boolean

  • get isBox3(): boolean
  • Returns boolean

  • get isColor(): boolean
  • Returns boolean

  • get isCylindrical(): boolean
  • Returns boolean

  • get isEuler(): boolean
  • Returns boolean

  • get isLine3(): boolean
  • Returns boolean

  • get isMatrix(): boolean
  • Read-only flag to check if a given object is of type Matrix.

    Returns boolean

  • get isMatrix3(): boolean
  • Read-only flag to check if a given object is of type Matrix3.

    Returns boolean

  • get isMatrix4(): boolean
  • Returns boolean

  • get isPlane(): boolean
  • Returns boolean

  • get isQuaternion(): boolean
  • Returns boolean

  • get isRay(): boolean
  • Returns boolean

  • get isSphere(): boolean
  • Returns boolean

  • get isSpherical(): boolean
  • Returns boolean

  • get isTriangle(): boolean
  • Returns boolean

  • get isVector2(): boolean
  • Returns boolean

  • get isVector3(): boolean
  • Returns boolean

  • get isVector4(): boolean
  • Returns boolean

Methods

  • Computes the determinant of this matrix.

    Returns

    A float.

    Returns number

  • Test if this instance is equivalent to another matrix.

    Returns

    True if this matrix and m are equal.

    Parameters

    Returns boolean

  • Extracts the basis of this matrix into the three axis vectors provided. If this matrix is:

    a, b, c,
    d, e, f,
    g, h, i

    then the xAxis, yAxis, zAxis will be set to:

    xAxis = (a, d, g)
    yAxis = (b, e, h)
    zAxis = (c, f, i)

    Returns

    This instance.

    Parameters

    Returns Matrix3

  • Sets the elements of this matrix based on an array in column-major format.

    Returns

    This instance.

    Parameters

    • array: number[]

      the array to read the elements from.

    • Optional offset: number

      index of first element in the array. Default is 0.

    Returns Matrix3

  • Sets this matrix as the upper left 3x3 of the normal matrix of the passed matrix4. The normal matrix is the inverse transpose of the matrix m.

    Returns

    This instance.

    Parameters

    Returns Matrix3

  • Resets this matrix to the 3x3 identity matrix:

    1, 0, 0
    0, 1, 0
    0, 0, 1

    Returns

    This instance.

    Returns Matrix3

  • Inverts this matrix, using the analytic method. You can not invert with a determinant of zero. If you attempt this, the method produces a zero matrix instead.

    Returns

    This instance

    Returns Matrix3

  • Sets this matrix as a 2D rotational transformation by theta radians. The resulting matrix will be: cos(θ) -sin(θ) 0 sin(θ) cos(θ) 0 0 0 1

    Returns

    This instance.

    Parameters

    • theta: number

      — Rotation angle in radians. Positive values rotate counterclockwise

    Returns Matrix3

  • Sets this matrix as a 2D scale transform x, 0, 0, 0, y, 0, 0, 0, 1

    Returns

    This instance.

    Parameters

    • x: number

      the amount to scale in the X axis

    • y: number

      the amount to scale in the Y axis

    Returns Matrix3

  • Sets this matrix as a 2D translation transform: 1, 0, x, 0, 1, y, 0, 0, 1

    Returns

    This instance.

    Parameters

    • x: number
    • y: number

    Returns Matrix3

  • Multiplies every component of the matrix by the scalar value s.

    Returns

    This instance.

    Parameters

    • s: number

    Returns Matrix3

  • Rotates this matrix by the given angle (in radians).

    Returns

    This instance.

    Parameters

    • theta: number

      The angle in radians to rotate

    Returns Matrix3

  • Scales this matrix with the given scalar values.

    Returns

    This instance.

    Parameters

    • sx: number

      x scale factor

    • sy: number

      y scale factor

    Returns Matrix3

  • Sets the 3x3 matrix values to the given row-major sequence of values.

    Returns

    This instance.

    Parameters

    • n11: number
    • n12: number
    • n13: number
    • n21: number
    • n22: number
    • n23: number
    • n31: number
    • n32: number
    • n33: number

    Returns Matrix3

  • Set this matrix to the upper 3x3 matrix of the Matrix4 m.

    Returns

    This instance.

    Parameters

    • tx: number

      offset x

    • ty: number

      offset y

    • sx: number

      repeat x

    • sy: number

      repeat y

    • rotation: number

      rotation, in radians. Positive values rotate counterclockwise

    • cx: number

      center x of rotation

    • cy: number

      center y of rotation

    Returns Matrix3

  • Writes the elements of this matrix to an array in column-major format.

    Returns

    The array param or a new instance

    Parameters

    • Optional array: number[]

      array to store the resulting vector in. If not given a new array will be created.

    • Optional offset: number

      offset in the array at which to put the result.

    Returns number[]

  • Translates this matrix by the given scalar values.

    Returns

    This instance.

    Parameters

    • tx: number

      The x direction translation

    • ty: number

      The y direction translation

    Returns Matrix3

  • Transposes this matrix in place.

    Returns

    This instance.

    Returns Matrix3

  • Transposes this matrix into the supplied array, and returns itself unchanged.

    Returns

    This instance.

    Parameters

    • r: number[]

      array to store the resulting vector in.

    Returns Matrix3