MCPcopy Index your code
hub / github.com/processing/p5.js / #invert3x3

Method #invert3x3

src/math/Matrices/Matrix.js:1971–2001  ·  view source on GitHub ↗

* Inverts a 3×3 matrix * @chainable * @private

()

Source from the content-addressed store, hash-verified

1969 * @private
1970 */
1971 #invert3x3() {
1972 const a00 = this.mat3[0];
1973 const a01 = this.mat3[1];
1974 const a02 = this.mat3[2];
1975 const a10 = this.mat3[3];
1976 const a11 = this.mat3[4];
1977 const a12 = this.mat3[5];
1978 const a20 = this.mat3[6];
1979 const a21 = this.mat3[7];
1980 const a22 = this.mat3[8];
1981 const b01 = a22 * a11 - a12 * a21;
1982 const b11 = -a22 * a10 + a12 * a20;
1983 const b21 = a21 * a10 - a11 * a20;
1984
1985 // Calculate the determinant
1986 let det = a00 * b01 + a01 * b11 + a02 * b21;
1987 if (!det) {
1988 return null;
1989 }
1990 det = 1.0 / det;
1991 this.mat3[0] = b01 * det;
1992 this.mat3[1] = (-a22 * a01 + a02 * a21) * det;
1993 this.mat3[2] = (a12 * a01 - a02 * a11) * det;
1994 this.mat3[3] = b11 * det;
1995 this.mat3[4] = (a22 * a00 - a02 * a20) * det;
1996 this.mat3[5] = (-a12 * a00 + a02 * a10) * det;
1997 this.mat3[6] = b21 * det;
1998 this.mat3[7] = (-a21 * a00 + a01 * a20) * det;
1999 this.mat3[8] = (a11 * a00 - a01 * a10) * det;
2000 return this;
2001 }
2002
2003 /**
2004 * inspired by Toji's mat4 determinant

Callers 1

invertMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected