From 191ef35d212010823aa703355188662e5e9a57de Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 8 Aug 2020 16:05:49 +0200 Subject: [PATCH] inverse3 function --- hyperpoint.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/hyperpoint.cpp b/hyperpoint.cpp index 5becb400..5bcbe3b0 100644 --- a/hyperpoint.cpp +++ b/hyperpoint.cpp @@ -916,20 +916,23 @@ void inverse_error(const transmatrix& T) { } /** inverse */ -EX transmatrix inverse(const transmatrix& T) { - if(MDIM == 3) { - ld d = det(T); - transmatrix T2; - if(d == 0) { - inverse_error(T); - return Id; - } - - for(int i=0; i<3; i++) - for(int j=0; j<3; j++) - T2[j][i] = (T[(i+1)%3][(j+1)%3] * T[(i+2)%3][(j+2)%3] - T[(i+1)%3][(j+2)%3] * T[(i+2)%3][(j+1)%3]) / d; - return T2; +EX transmatrix inverse3(const transmatrix& T) { + ld d = det(T); + transmatrix T2; + if(d == 0) { + inverse_error(T); + return Id; } + + for(int i=0; i<3; i++) + for(int j=0; j<3; j++) + T2[j][i] = (T[(i+1)%3][(j+1)%3] * T[(i+2)%3][(j+2)%3] - T[(i+1)%3][(j+2)%3] * T[(i+2)%3][(j+1)%3]) / d; + return T2; + } + +EX transmatrix inverse(const transmatrix& T) { + if(MDIM == 3) + return inverse3(T); else { transmatrix T1 = T; transmatrix T2 = Id;