-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeterminant.cpp
More file actions
63 lines (56 loc) · 1.36 KB
/
determinant.cpp
File metadata and controls
63 lines (56 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// Created by bpiranda on 23/11/2019.
//
#include "determinant.h"
void Matrix22::get2x2From3x3(const Matrix33 &mat33,int shadowLin, int shadowCol) {
int l=0;
for (int lig=0; lig<3; lig++) {
if (lig!=shadowLin) {
int c=0;
for (int col=0; col<3; col++) {
if (col!=shadowCol) {
m[l][c] = mat33.m[lig][col];
c++;
}
}
l++;
}
}
}
void Matrix33::get3x3From4x4(const Matrix44 &mat44,int shadowLin, int shadowCol) {
int l=0;
for (int lig=0; lig<4; lig++) {
if (lig!=shadowLin) {
int c=0;
for (int col=0; col<4; col++) {
if (col!=shadowCol) {
m[l][c] = mat44.m[lig][col];
c++;
}
}
l++;
}
}
}
float Matrix33::determinant() {
Matrix22 mat22;
float det=0;
float sign=1;
for (int i=0; i<3; i++) {
mat22.get2x2From3x3(*this,i,0);
det += sign*m[i][0]*mat22.determinant();
sign = -sign;
}
return det;
}
float Matrix44::determinant() {
Matrix33 mat33;
float det=0;
float sign=1;
for (int i=0; i<4; i++) {
mat33.get3x3From4x4(*this,i,0);
det += sign*m[i][0]*mat33.determinant();
sign = -sign;
}
return det;
}