Capítulo 357 de 859

Chapter 357: Matrix3

Core Idea

Represents a 3x3 matrix.

A Note on Row-Major and Column-Major Ordering:

The constructor and Matrix3#set method take arguments in row-major order, while internally they are stored in the Matrix3#elements array in column-major order. This means that calling:

const m = new THREE.Matrix();
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.

Key Concepts

  • elements : Array.<number>: A column-major list of matrix values.

Reference Tables

Constructor

Signature
new Matrix3( n11 : number, n12 : number, n13 : number, n21 : number, n22 : number, n23 : number, n31 : number, n32 : number, n33 : number )

Properties

PropertyDescription
.elements : Array.<number>A column-major list of matrix values.

Methods

MethodDescription
.clone() : Matrix3Returns a matrix with copied values from this instance.
.copy( m : Matrix3 ) : Matrix3Copies the values of the given matrix to this instance.
.determinant() : numberComputes and returns the determinant of this matrix.
.equals( matrix : Matrix3 ) : booleanReturns true if this matrix is equal with the given one.
.extractBasis( xAxis : Vector3, yAxis : Vector3, zAxis : Vector3 ) : Matrix3Extracts the basis of this matrix into the three axis vectors provided.
.fromArray( array : Array.<number>, offset : number ) : Matrix3Sets the elements of the matrix from the given array.
.getNormalMatrix( matrix4 : Matrix4 ) : Matrix3Computes the normal matrix which is the inverse transpose of the upper left 3x3 portion of the given 4x4 matrix.
.identity() : Matrix3Sets this matrix to the 3x3 identity matrix.
.invert() : Matrix3Inverts this matrix, using the analytic method. You can not invert with a determinant of zero. If you attempt this, the method pro…
.makeRotation( theta : number ) : Matrix3Sets this matrix as a 2D rotational transformation.
.makeScale( x : number, y : number ) : Matrix3Sets this matrix as a 2D scale transform.
`.makeTranslation( x : numberVector2, y : number ) : Matrix3`
.multiply( m : Matrix3 ) : Matrix3Post-multiplies this matrix by the given 3x3 matrix.
.multiplyMatrices( a : Matrix3, b : Matrix3 ) : Matrix3Multiples the given 3x3 matrices and stores the result in this matrix.
.multiplyScalar( s : number ) : Matrix3Multiplies every component of the matrix by the given scalar.
.premultiply( m : Matrix3 ) : Matrix3Pre-multiplies this matrix by the given 3x3 matrix.
.rotate( theta : number ) : Matrix3Rotates this matrix by the given angle.
.scale( sx : number, sy : number ) : Matrix3Scales this matrix with the given scalar values.
.set( n11 : number, n12 : number, n13 : number, n21 : number, n22 : number, n23 : number, n31 : number, n32 : number, n33 : number ) : Matrix3Sets the elements of the matrix.The arguments are supposed to be in row-major order.
.setFromMatrix4( m : Matrix4 ) : Matrix3Set this matrix to the upper 3x3 matrix of the given 4x4 matrix.
.setUvTransform( tx : number, ty : number, sx : number, sy : number, rotation : number, cx : number, cy : number ) : Matrix3Sets the UV transform matrix from offset, repeat, rotation, and center.
.toArray( array : Array.<number>, offset : number ) : Array.<number>Writes the elements of this matrix to the given array. If no array is provided, the method returns a new instance.
.translate( tx : number, ty : number ) : Matrix3Translates this matrix by the given scalar values.
.transpose() : Matrix3Transposes this matrix in place.
.transposeIntoArray( r : Array.<number> ) : Matrix3Transposes this matrix into the supplied array, and returns itself unchanged.

Key Takeaways

  1. Most relevant properties: elements.
  2. Key methods: clone, copy, determinant, equals.

Connects To