matrixMul :: Matrix3x3 -> Vector3 -> Vector3
matrixMul (r1, r2, r3) v
= (dotProduct r1 v,
dotProduct r2 v,
dotProduct r3 v)
dotProduct :: Vector3 -> Vector3 -> Float
dotProduct (a,b,c) (x,y,z) = a*x + b*y + c*z
inverse :: Matrix3x3 -> Matrix3x3
inverse ((a,b,c), (d,e,f), (g,h,i))
= let det = determinant3 ((a,b,c), (d,e,f), (g,h,i))
a' = determinant2 ((e,f), (h,i)) / det
b' = determinant2 ((c,b), (i,h)) / det
c' = determinant2 ((b,c), (e,f)) / det
d' = determinant2 ((f,d), (i,g)) / det
e' = determinant2 ((a,c), (g,i)) / det
f' = determinant2 ((c,a), (f,d)) / det
g' = determinant2 ((d,e), (g,h)) / det
h' = determinant2 ((b,a), (h,g)) / det
i' = determinant2 ((a,b), (d,e)) / det
in ((a',b',c'), (d',e',f'), (g',h',i'))
determinant3 :: Matrix3x3 -> Float
determinant3 ((a,b,c), (d,e,f), (g,h,i))
= let aei = a * e * i
afh = a * f * h
bdi = b * d * i
cdh = c * d * h
bfg = b * f * g
ceg = c * e * g
in aei - afh - bdi + cdh + bfg - ceg
determinant2 :: Matrix2x2 -> Float
determinant2 ((a,b), (c,d))
= a * d - b * c |