The Matrix4.invert()
method is used to calculate the inverse matrix of a given 4x4 transformation matrix.
matrix4.invert();
The Matrix4.invert()
method does not take any parameters.
The Matrix4.invert()
method returns the inverted matrix as a new Matrix4
object.
The Matrix4.invert()
method is used to calculate the inverse of a given 4x4 transformation matrix. The inverse matrix is used for several purposes, including calculating the transformation required to undo a previous transformation, such as when reversing the orientation of a model, and for performing calculations such as collision detection.
const matrix4 = new THREE.Matrix4(); // Create a new identity matrix
matrix4.makeRotationX(Math.PI/2); // Rotate the matrix by 90 degrees about the x-axis
const inverseMatrix = matrix4.invert(); // Calculate the inverse of the matrix
In this example, a new Matrix4
object is created and rotated about the x-axis by 90 degrees using the makeRotationX()
method. The Matrix4.invert()
method is then used to calculate the inverse of the matrix, which is returned as a new Matrix4
object and stored in the inverseMatrix
variable.
const originalMatrix = new THREE.Matrix4(); // Create a new identity matrix
originalMatrix.makeTranslation(10, 5, 0); // Translate the matrix by (10, 5, 0)
const inverseMatrix = originalMatrix.invert(); // Calculate the inverse of the matrix
const undoMatrix = inverseMatrix.multiply(originalMatrix); // Calculate the undo matrix
In this example, a new Matrix4
object is created and translated by (10, 5, 0) using the makeTranslation()
method. The Matrix4.invert()
method is then used to calculate the inverse of the original matrix, which is stored in the inverseMatrix
variable. The multiply()
method is then used to calculate the undo matrix, which is the product of the inverse matrix and the original matrix. The resulting undoMatrix
object can be used to reverse the translation and return the object to its original position.
Matrix4
class used to represent 4x4 transformation matrices in Three.js.multiply()
method used to multiply two Matrix4
objects together.Matrix4.invert()
in earlier versions of Three.js.