From c932ae43999cc112f72c2020d25981b8aab9c0a9 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Thu, 20 Aug 2020 16:11:35 +0200 Subject: [PATCH] 2D and 3D variants of det --- hyperpoint.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/hyperpoint.cpp b/hyperpoint.cpp index 62e96b0a..742777ee 100644 --- a/hyperpoint.cpp +++ b/hyperpoint.cpp @@ -879,16 +879,25 @@ EX void orthonormalize(transmatrix& T) { } } +/** determinant 2x2 */ +EX ld det2(const transmatrix& T) { + return T[0][0] * T[1][1] - T[0][1] * T[1][0]; + } + +/** determinant 3x3 */ +EX ld det3(const transmatrix& T) { + ld det = 0; + for(int i=0; i<3; i++) + det += T[0][i] * T[1][(i+1)%3] * T[2][(i+2)%3]; + for(int i=0; i<3; i++) + det -= T[0][i] * T[1][(i+2)%3] * T[2][(i+1)%3]; + return det; + } + /** determinant */ EX ld det(const transmatrix& T) { - if(GDIM == 2) { - ld det = 0; - for(int i=0; i<3; i++) - det += T[0][i] * T[1][(i+1)%3] * T[2][(i+2)%3]; - for(int i=0; i<3; i++) - det -= T[0][i] * T[1][(i+2)%3] * T[2][(i+1)%3]; - return det; - } + if(GDIM == 2) + retrun det3(T); else { ld det = 1; transmatrix M = T;