|
31 | 31 | end
|
32 | 32 |
|
33 | 33 | @inline function _inv(::Size{(4,4)}, A)
|
34 |
| - idet = 1/det(A) |
35 |
| - B = @SMatrix [ |
36 |
| - (A[2,3]*A[3,4]*A[4,2] - A[2,4]*A[3,3]*A[4,2] + A[2,4]*A[3,2]*A[4,3] - A[2,2]*A[3,4]*A[4,3] - A[2,3]*A[3,2]*A[4,4] + A[2,2]*A[3,3]*A[4,4]) * idet |
37 |
| - (A[2,4]*A[3,3]*A[4,1] - A[2,3]*A[3,4]*A[4,1] - A[2,4]*A[3,1]*A[4,3] + A[2,1]*A[3,4]*A[4,3] + A[2,3]*A[3,1]*A[4,4] - A[2,1]*A[3,3]*A[4,4]) * idet |
38 |
| - (A[2,2]*A[3,4]*A[4,1] - A[2,4]*A[3,2]*A[4,1] + A[2,4]*A[3,1]*A[4,2] - A[2,1]*A[3,4]*A[4,2] - A[2,2]*A[3,1]*A[4,4] + A[2,1]*A[3,2]*A[4,4]) * idet |
39 |
| - (A[2,3]*A[3,2]*A[4,1] - A[2,2]*A[3,3]*A[4,1] - A[2,3]*A[3,1]*A[4,2] + A[2,1]*A[3,3]*A[4,2] + A[2,2]*A[3,1]*A[4,3] - A[2,1]*A[3,2]*A[4,3]) * idet |
| 34 | + # https://www.geometrictools.com/Documentation/LaplaceExpansionTheorem.pdf |
40 | 35 |
|
41 |
| - (A[1,4]*A[3,3]*A[4,2] - A[1,3]*A[3,4]*A[4,2] - A[1,4]*A[3,2]*A[4,3] + A[1,2]*A[3,4]*A[4,3] + A[1,3]*A[3,2]*A[4,4] - A[1,2]*A[3,3]*A[4,4]) * idet |
42 |
| - (A[1,3]*A[3,4]*A[4,1] - A[1,4]*A[3,3]*A[4,1] + A[1,4]*A[3,1]*A[4,3] - A[1,1]*A[3,4]*A[4,3] - A[1,3]*A[3,1]*A[4,4] + A[1,1]*A[3,3]*A[4,4]) * idet |
43 |
| - (A[1,4]*A[3,2]*A[4,1] - A[1,2]*A[3,4]*A[4,1] - A[1,4]*A[3,1]*A[4,2] + A[1,1]*A[3,4]*A[4,2] + A[1,2]*A[3,1]*A[4,4] - A[1,1]*A[3,2]*A[4,4]) * idet |
44 |
| - (A[1,2]*A[3,3]*A[4,1] - A[1,3]*A[3,2]*A[4,1] + A[1,3]*A[3,1]*A[4,2] - A[1,1]*A[3,3]*A[4,2] - A[1,2]*A[3,1]*A[4,3] + A[1,1]*A[3,2]*A[4,3]) * idet |
| 36 | + s0 = A[1] * A[6] - A[2] * A[5] |
| 37 | + s1 = A[1] * A[10] - A[2] * A[9] |
| 38 | + s2 = A[1] * A[14] - A[2] * A[13] |
| 39 | + s3 = A[5] * A[10] - A[6] * A[9] |
| 40 | + s4 = A[5] * A[14] - A[6] * A[13] |
| 41 | + s5 = A[9] * A[14] - A[10] * A[13] |
45 | 42 |
|
46 |
| - (A[1,3]*A[2,4]*A[4,2] - A[1,4]*A[2,3]*A[4,2] + A[1,4]*A[2,2]*A[4,3] - A[1,2]*A[2,4]*A[4,3] - A[1,3]*A[2,2]*A[4,4] + A[1,2]*A[2,3]*A[4,4]) * idet |
47 |
| - (A[1,4]*A[2,3]*A[4,1] - A[1,3]*A[2,4]*A[4,1] - A[1,4]*A[2,1]*A[4,3] + A[1,1]*A[2,4]*A[4,3] + A[1,3]*A[2,1]*A[4,4] - A[1,1]*A[2,3]*A[4,4]) * idet |
48 |
| - (A[1,2]*A[2,4]*A[4,1] - A[1,4]*A[2,2]*A[4,1] + A[1,4]*A[2,1]*A[4,2] - A[1,1]*A[2,4]*A[4,2] - A[1,2]*A[2,1]*A[4,4] + A[1,1]*A[2,2]*A[4,4]) * idet |
49 |
| - (A[1,3]*A[2,2]*A[4,1] - A[1,2]*A[2,3]*A[4,1] - A[1,3]*A[2,1]*A[4,2] + A[1,1]*A[2,3]*A[4,2] + A[1,2]*A[2,1]*A[4,3] - A[1,1]*A[2,2]*A[4,3]) * idet |
| 43 | + c5 = A[11] * A[16] - A[12] * A[15] |
| 44 | + c4 = A[7] * A[16] - A[8] * A[15] |
| 45 | + c3 = A[7] * A[12] - A[8] * A[11] |
| 46 | + c2 = A[3] * A[16] - A[4] * A[15] |
| 47 | + c1 = A[3] * A[12] - A[4] * A[11] |
| 48 | + c0 = A[3] * A[8] - A[4] * A[7] |
50 | 49 |
|
51 |
| - (A[1,4]*A[2,3]*A[3,2] - A[1,3]*A[2,4]*A[3,2] - A[1,4]*A[2,2]*A[3,3] + A[1,2]*A[2,4]*A[3,3] + A[1,3]*A[2,2]*A[3,4] - A[1,2]*A[2,3]*A[3,4]) * idet |
52 |
| - (A[1,3]*A[2,4]*A[3,1] - A[1,4]*A[2,3]*A[3,1] + A[1,4]*A[2,1]*A[3,3] - A[1,1]*A[2,4]*A[3,3] - A[1,3]*A[2,1]*A[3,4] + A[1,1]*A[2,3]*A[3,4]) * idet |
53 |
| - (A[1,4]*A[2,2]*A[3,1] - A[1,2]*A[2,4]*A[3,1] - A[1,4]*A[2,1]*A[3,2] + A[1,1]*A[2,4]*A[3,2] + A[1,2]*A[2,1]*A[3,4] - A[1,1]*A[2,2]*A[3,4]) * idet |
54 |
| - (A[1,2]*A[2,3]*A[3,1] - A[1,3]*A[2,2]*A[3,1] + A[1,3]*A[2,1]*A[3,2] - A[1,1]*A[2,3]*A[3,2] - A[1,2]*A[2,1]*A[3,3] + A[1,1]*A[2,2]*A[3,3]) * idet] |
55 |
| - return similar_type(A)(B) |
| 50 | + invdet = 1 / (s0 * c5 - s1 * c4 + s2 * c3 + s3 * c2 - s4 * c1 + s5 * c0) |
| 51 | + |
| 52 | + B = @SMatrix [ |
| 53 | + ( A[6] * c5 - A[10] * c4 + A[14] * c3) * invdet |
| 54 | + (-A[2] * c5 + A[10] * c2 - A[14] * c1) * invdet |
| 55 | + ( A[2] * c4 - A[6] * c2 + A[14] * c0) * invdet |
| 56 | + (-A[2] * c3 + A[6] * c1 - A[10] * c0) * invdet |
| 57 | + (-A[5] * c5 + A[9] * c4 - A[13] * c3) * invdet |
| 58 | + ( A[1] * c5 - A[9] * c2 + A[13] * c1) * invdet |
| 59 | + (-A[1] * c4 + A[5] * c2 - A[13] * c0) * invdet |
| 60 | + ( A[1] * c3 - A[5] * c1 + A[9] * c0) * invdet |
| 61 | + ( A[8] * s5 - A[12] * s4 + A[16] * s3) * invdet |
| 62 | + (-A[4] * s5 + A[12] * s2 - A[16] * s1) * invdet |
| 63 | + ( A[4] * s4 - A[8] * s2 + A[16] * s0) * invdet |
| 64 | + (-A[4] * s3 + A[8] * s1 - A[12] * s0) * invdet |
| 65 | + (-A[7] * s5 + A[11] * s4 - A[15] * s3) * invdet |
| 66 | + ( A[3] * s5 - A[11] * s2 + A[15] * s1) * invdet |
| 67 | + (-A[3] * s4 + A[7] * s2 - A[15] * s0) * invdet |
| 68 | + ( A[3] * s3 - A[7] * s1 + A[11] * s0) * invdet] |
| 69 | + return similar_type(A)(B) |
56 | 70 | end
|
57 | 71 |
|
58 | 72 | @generated function _inv(::Size{S}, A) where S
|
|
0 commit comments