The Matrix4.equals()
method in Three.js is used to compare two matrix objects for equality.
equals(matrix: Matrix4): boolean;
matrix
: The matrix object to compare to.boolean
: True if the matrix objects are equal, else false.The equals()
method compares the matrix with another matrix object to check if they have the exact same elements in the same order. If they match, the method returns true, else false.
import { Matrix4 } from 'three';
const matrix1 = new Matrix4(1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 );
const matrix2 = new Matrix4(1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 );
console.log(matrix1.equals(matrix2)); // true
matrix2.elements[0] = 2;
console.log(matrix1.equals(matrix2)); // false
In this example, we create two identical matrix objects and compare them using the equals()
method. The method returns true, indicating that they are equal.
We then modify an element of matrix2
and compare again. This time, the method returns false as the two matrices no longer match.
Note that the equals()
method only compares the elements of the matrices, not their types or other properties.