The equals()
method in the Matrix3
class in three.js
library is used to check if this matrix and another matrix passed as a parameter are equal, with a tolerance of epsilon for each component.
.equals(matrix: Matrix3, epsilon?: number): boolean
The method takes the following parameters:
matrix
: An instance of Matrix3
. Matrix to compare to the current matrix.epsilon (optional)
: A floating-point value representing the tolerance level for the comparison.The method returns a boolean value true
if the two matrices are equal within the given tolerance or false
otherwise.
let matrix1 = new THREE.Matrix3().set(1, 2, 3, 4, 5, 6, 7, 8, 9);
let matrix2 = new THREE.Matrix3().set(1.001, 2.002, 3.002, 4, 5, 6, 7, 8, 9);
console.log(matrix1.equals(matrix2, 0.01)); // true
matrix2 = new THREE.Matrix3().set(1.1, 2.2, 3.3, 4, 5, 6, 7, 8, 9);
console.log(matrix1.equals(matrix2, 0.01)); // false
In this example, we create two Matrix3
objects, matrix1
and matrix2
, with slightly different values. We then compare these two matrices using the equals()
method with a tolerance level of 0.01
. Since the differences between the two matrices are within this tolerance level, the method returns true
. Then, we update the values of matrix2
to be significantly different from matrix1
. Again, we use the equals()
method with a tolerance level of 0.01
. This time, the differences between the two matrices are greater than the tolerance level, so the method returns false
.