@@ -1322,21 +1322,42 @@ cdef class Matrix33(Vector):
13221322 @ cython.cdivision (True )
13231323 cpdef Matrix33 inverse(self ):
13241324 cdef double * numbers = self .numbers
1325- cdef double s0 = numbers[0 ] * (numbers[4 ]* numbers[8 ] - numbers[7 ]* numbers[5 ])
1326- cdef double s1 = numbers[3 ] * (numbers[7 ]* numbers[2 ] - numbers[1 ]* numbers[8 ])
1327- cdef double s2 = numbers[6 ] * (numbers[1 ]* numbers[5 ] - numbers[4 ]* numbers[2 ])
1328- cdef double invdet = 1 / (s0 + s1 + s2)
1325+ cdef double invdet = 1 / self .det()
13291326 cdef Matrix33 result = Matrix33.__new__ (Matrix33)
13301327 cdef double * result_numbers = result._numbers
1331- result_numbers[0 ] = (numbers[4 ]* numbers[8 ] - numbers[7 ]* numbers[5 ]) * invdet
1328+ result_numbers[0 ] = (numbers[4 ]* numbers[8 ] - numbers[5 ]* numbers[7 ]) * invdet
13321329 result_numbers[1 ] = (numbers[2 ]* numbers[7 ] - numbers[1 ]* numbers[8 ]) * invdet
13331330 result_numbers[2 ] = (numbers[1 ]* numbers[5 ] - numbers[2 ]* numbers[4 ]) * invdet
13341331 result_numbers[3 ] = (numbers[5 ]* numbers[6 ] - numbers[3 ]* numbers[8 ]) * invdet
13351332 result_numbers[4 ] = (numbers[0 ]* numbers[8 ] - numbers[2 ]* numbers[6 ]) * invdet
1336- result_numbers[5 ] = (numbers[3 ]* numbers[2 ] - numbers[0 ]* numbers[5 ]) * invdet
1337- result_numbers[6 ] = (numbers[3 ]* numbers[7 ] - numbers[6 ]* numbers[4 ]) * invdet
1338- result_numbers[7 ] = (numbers[6 ]* numbers[1 ] - numbers[0 ]* numbers[7 ]) * invdet
1339- result_numbers[8 ] = (numbers[0 ]* numbers[4 ] - numbers[3 ]* numbers[1 ]) * invdet
1333+ result_numbers[5 ] = (numbers[2 ]* numbers[3 ] - numbers[0 ]* numbers[5 ]) * invdet
1334+ result_numbers[6 ] = (numbers[3 ]* numbers[7 ] - numbers[4 ]* numbers[6 ]) * invdet
1335+ result_numbers[7 ] = (numbers[1 ]* numbers[6 ] - numbers[0 ]* numbers[7 ]) * invdet
1336+ result_numbers[8 ] = (numbers[0 ]* numbers[4 ] - numbers[1 ]* numbers[3 ]) * invdet
1337+ result.numbers = result_numbers
1338+ result.length = 9
1339+ return result
1340+
1341+ cpdef double det(self ):
1342+ cdef double * numbers = self .numbers
1343+ cdef double s0 = numbers[0 ] * (numbers[4 ]* numbers[8 ] - numbers[7 ]* numbers[5 ])
1344+ cdef double s1 = numbers[3 ] * (numbers[7 ]* numbers[2 ] - numbers[1 ]* numbers[8 ])
1345+ cdef double s2 = numbers[6 ] * (numbers[1 ]* numbers[5 ] - numbers[4 ]* numbers[2 ])
1346+ return s0 + s1 + s2
1347+
1348+ cpdef Matrix33 cofactor(self ):
1349+ cdef double * numbers = self .numbers
1350+ cdef Matrix33 result = Matrix33.__new__ (Matrix33)
1351+ cdef double * result_numbers = result._numbers
1352+ result_numbers[0 ] = numbers[4 ]* numbers[8 ] - numbers[5 ]* numbers[7 ]
1353+ result_numbers[1 ] = numbers[5 ]* numbers[6 ] - numbers[3 ]* numbers[8 ]
1354+ result_numbers[2 ] = numbers[3 ]* numbers[7 ] - numbers[4 ]* numbers[6 ]
1355+ result_numbers[3 ] = numbers[2 ]* numbers[7 ] - numbers[1 ]* numbers[8 ]
1356+ result_numbers[4 ] = numbers[0 ]* numbers[8 ] - numbers[2 ]* numbers[6 ]
1357+ result_numbers[5 ] = numbers[1 ]* numbers[6 ] - numbers[0 ]* numbers[7 ]
1358+ result_numbers[6 ] = numbers[1 ]* numbers[5 ] - numbers[2 ]* numbers[4 ]
1359+ result_numbers[7 ] = numbers[2 ]* numbers[3 ] - numbers[0 ]* numbers[5 ]
1360+ result_numbers[8 ] = numbers[0 ]* numbers[4 ] - numbers[1 ]* numbers[3 ]
13401361 result.numbers = result_numbers
13411362 result.length = 9
13421363 return result
@@ -1925,6 +1946,23 @@ cdef class Matrix44(Vector):
19251946 result.length = 9
19261947 return result
19271948
1949+ cpdef Matrix33 matrix33_cofactor(self ):
1950+ cdef double * numbers = self .numbers
1951+ cdef Matrix33 result = Matrix33.__new__ (Matrix33)
1952+ cdef double * result_numbers = result._numbers
1953+ result_numbers[0 ] = numbers[5 ]* numbers[10 ] - numbers[6 ]* numbers[9 ]
1954+ result_numbers[1 ] = numbers[6 ]* numbers[8 ] - numbers[4 ]* numbers[10 ]
1955+ result_numbers[2 ] = numbers[4 ]* numbers[9 ] - numbers[5 ]* numbers[8 ]
1956+ result_numbers[3 ] = numbers[2 ]* numbers[9 ] - numbers[1 ]* numbers[10 ]
1957+ result_numbers[4 ] = numbers[0 ]* numbers[10 ] - numbers[2 ]* numbers[8 ]
1958+ result_numbers[5 ] = numbers[1 ]* numbers[8 ] - numbers[0 ]* numbers[9 ]
1959+ result_numbers[6 ] = numbers[1 ]* numbers[6 ] - numbers[2 ]* numbers[5 ]
1960+ result_numbers[7 ] = numbers[2 ]* numbers[4 ] - numbers[0 ]* numbers[6 ]
1961+ result_numbers[8 ] = numbers[0 ]* numbers[5 ] - numbers[1 ]* numbers[4 ]
1962+ result.numbers = result_numbers
1963+ result.length = 9
1964+ return result
1965+
19281966 def __repr__ (self ):
19291967 cdef list rows = []
19301968 cdef double * numbers = self .numbers
0 commit comments