BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

Matrix4.invert()

The Matrix4.invert() method is used to calculate the inverse matrix of a given 4x4 transformation matrix.

Syntax

matrix4.invert();

Parameters

The Matrix4.invert() method does not take any parameters.

Return Value

The Matrix4.invert() method returns the inverted matrix as a new Matrix4 object.

Description

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.

Examples

Example 1: Inverting a matrix

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.

Example 2: Undoing a transformation

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.

See Also

  • Matrix4 - The Matrix4 class used to represent 4x4 transformation matrices in Three.js.
  • Matrix4.multiply() - The multiply() method used to multiply two Matrix4 objects together.
  • Matrix4.getInverse() - The equivalent method to Matrix4.invert() in earlier versions of Three.js.