1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-11-19 15:15:12 +00:00

2D and 3D variants of det

This commit is contained in:
Zeno Rogue
2020-08-20 16:11:35 +02:00
parent 58aba3eb37
commit c932ae4399

View File

@@ -879,9 +879,13 @@ EX void orthonormalize(transmatrix& T) {
} }
} }
/** determinant */ /** determinant 2x2 */
EX ld det(const transmatrix& T) { EX ld det2(const transmatrix& T) {
if(GDIM == 2) { return T[0][0] * T[1][1] - T[0][1] * T[1][0];
}
/** determinant 3x3 */
EX ld det3(const transmatrix& T) {
ld det = 0; ld det = 0;
for(int i=0; i<3; i++) for(int i=0; i<3; i++)
det += T[0][i] * T[1][(i+1)%3] * T[2][(i+2)%3]; det += T[0][i] * T[1][(i+1)%3] * T[2][(i+2)%3];
@@ -889,6 +893,11 @@ EX ld det(const transmatrix& T) {
det -= T[0][i] * T[1][(i+2)%3] * T[2][(i+1)%3]; det -= T[0][i] * T[1][(i+2)%3] * T[2][(i+1)%3];
return det; return det;
} }
/** determinant */
EX ld det(const transmatrix& T) {
if(GDIM == 2)
retrun det3(T);
else { else {
ld det = 1; ld det = 1;
transmatrix M = T; transmatrix M = T;