1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-27 14:37:16 +00:00

inverse3 function

This commit is contained in:
Zeno Rogue 2020-08-08 16:05:49 +02:00
parent 4bddeedaf8
commit 191ef35d21

View File

@ -916,20 +916,23 @@ void inverse_error(const transmatrix& T) {
} }
/** inverse */ /** inverse */
EX transmatrix inverse(const transmatrix& T) { EX transmatrix inverse3(const transmatrix& T) {
if(MDIM == 3) { ld d = det(T);
ld d = det(T); transmatrix T2;
transmatrix T2; if(d == 0) {
if(d == 0) { inverse_error(T);
inverse_error(T); return Id;
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;
} }
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 { else {
transmatrix T1 = T; transmatrix T1 = T;
transmatrix T2 = Id; transmatrix T2 = Id;