* Inverts this matrix, using the [analytic method](https://en.wikipedia.org/wiki/Invertible_matrix#Analytic_solution). * You can not invert with a determinant of zero. If you attempt this, the method produces * a zero matrix instead. * * @return {Matrix3} A reference to this matrix.
()
| 291 | * @return {Matrix3} A reference to this matrix. |
| 292 | */ |
| 293 | invert() { |
| 294 | |
| 295 | const te = this.elements, |
| 296 | |
| 297 | n11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ], |
| 298 | n12 = te[ 3 ], n22 = te[ 4 ], n32 = te[ 5 ], |
| 299 | n13 = te[ 6 ], n23 = te[ 7 ], n33 = te[ 8 ], |
| 300 | |
| 301 | t11 = n33 * n22 - n32 * n23, |
| 302 | t12 = n32 * n13 - n33 * n12, |
| 303 | t13 = n23 * n12 - n22 * n13, |
| 304 | |
| 305 | det = n11 * t11 + n21 * t12 + n31 * t13; |
| 306 | |
| 307 | if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0 ); |
| 308 | |
| 309 | const detInv = 1 / det; |
| 310 | |
| 311 | te[ 0 ] = t11 * detInv; |
| 312 | te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv; |
| 313 | te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv; |
| 314 | |
| 315 | te[ 3 ] = t12 * detInv; |
| 316 | te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv; |
| 317 | te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv; |
| 318 | |
| 319 | te[ 6 ] = t13 * detInv; |
| 320 | te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv; |
| 321 | te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv; |
| 322 | |
| 323 | return this; |
| 324 | |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * Transposes this matrix in place. |
no test coverage detected