From: Michael Orlitzky Date: Sun, 2 Oct 2011 21:54:30 +0000 (-0400) Subject: Use the cleaner formula for 'det'. X-Git-Tag: 0.0.1~115 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=9220b061771e4ac6d2bd3adad3d926479b77f7c8;p=spline3.git Use the cleaner formula for 'det'. --- diff --git a/src/Tetrahedron.hs b/src/Tetrahedron.hs index e84b091..2342ba1 100644 --- a/src/Tetrahedron.hs +++ b/src/Tetrahedron.hs @@ -281,16 +281,24 @@ c _ _ _ _ _ = error "coefficient index out of bounds" +-- | Compute the determinant of the 4x4 matrix, +-- +-- [1] +-- [x] +-- [y] +-- [z] +-- +-- where [1] = [1, 1, 1, 1], +-- [x] = [x1,x2,x3,x4], +-- +-- et cetera. +-- det :: Point -> Point -> Point -> Point -> Double det p0 p1 p2 p3 = --- Both of these results are just copy/pasted from Sage. One of them --- might be more numerically stable, faster, or both. --- --- x1*y2*z4 - x1*y2*z3 + x1*y3*z2 - x1*y3*z4 - x1*y4*z2 + x1*y4*z3 + --- x2*y1*z3 - x2*y1*z4 - x2*y3*z1 + x2*y3*z4 + --- x2*y4*z1 - x2*y4*z3 - x3*y1*z2 + x3*y1*z4 + x3*y2*z1 - x3*y2*z4 - x3*y4*z1 + --- x3*y4*z2 + x4*y1*z2 - x4*y1*z3 - x4*y2*z1 + x4*y2*z3 + x4*y3*z1 - x4*y3*z2 - -((x2 - x3)*y1 - (x1 - x3)*y2 + (x1 - x2)*y3)*z4 + ((x2 - x4)*y1 - (x1 - x4)*y2 + (x1 - x2)*y4)*z3 + ((x3 - x4)*y2 - (x2 - x4)*y3 + (x2 - x3)*y4)*z1 - ((x3 - x4)*y1 - (x1 - x4)*y3 + (x1 - x3)*y4)*z2 + x1*y2*z4 - x1*y2*z3 + x1*y3*z2 - x1*y3*z4 - x1*y4*z2 + x1*y4*z3 + + x2*y1*z3 - x2*y1*z4 - x2*y3*z1 + x2*y3*z4 + x2*y4*z1 + x3*y1*z4 + + x3*y2*z1 - x3*y2*z4 - x3*y4*z1 - x2*y4*z3 - x3*y1*z2 + x3*y4*z2 + + x4*y1*z2 - x4*y1*z3 - x4*y2*z1 + x4*y2*z3 + x4*y3*z1 - x4*y3*z2 where (x1, y1, z1) = p0 (x2, y2, z2) = p1