-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix.h
executable file
·75 lines (68 loc) · 2.21 KB
/
matrix.h
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
64
65
66
67
68
69
70
71
72
73
74
75
/*
ver.03.03
file matrix.h
*/
#pragma once
#include <string>
class MATRIX{
public:
MATRIX(void){};
MATRIX(MATRIX*){};
virtual ~MATRIX(){};
//virtual void Renew(unsigned row,unsigned col)=0;
//virtual void ZeroOut(void)=0;
//virtual void Identity(void)=0;
//virtual double* GetData(void)=0;
//virtual double* GetData(void)const=0;
//virtual void Print(std::string filename)=0;
virtual unsigned GetRow(void)const=0;
virtual unsigned GetCol(void)const=0;
virtual double& operator()(unsigned i,unsigned j)=0;
virtual double operator()(unsigned i,unsigned j)const=0;
virtual double& operator[](unsigned i)=0;
MATRIX& operator=(MATRIX& right){return *this;};
};
class MATRIX33:virtual public MATRIX{
public:
MATRIX33(void){};
MATRIX33(MATRIX* src){};
virtual ~MATRIX33(){};
MATRIX33& operator=(MATRIX33& right){
for(unsigned i=0;i<9;i++)
(*this)[i]=right[i];
return *this;
};
virtual double det(void)const{
return
(*this)(0,0)*(*this)(1,1)*(*this)(2,2) +
(*this)(0,1)*(*this)(1,2)*(*this)(2,0) +
(*this)(0,2)*(*this)(1,0)*(*this)(2,1) -
(*this)(0,2)*(*this)(1,1)*(*this)(2,0) -
(*this)(0,0)*(*this)(1,2)*(*this)(2,1) -
(*this)(0,1)*(*this)(1,0)*(*this)(2,2);
};
double I1(void)const{
return (*this)(0,0)+(*this)(1,1)+(*this)(2,2);
};
double I2(void)const{
double sum=0;
for(unsigned i=0;i<3;i++)
for(unsigned j=0;j<3;j++)
sum+=(*this)(i,j)*(*this)(j,i);
double I1=this->I1();
return (I1*I1-sum)*.5;
};
void Inv(MATRIX33& dest){
double mdet=det();
dest[0]=((*this)(1,1)*(*this)(2,2) - (*this)(1,2)*(*this)(2,1))/mdet;
dest[1]=((*this)(0,2)*(*this)(2,1) - (*this)(0,1)*(*this)(2,2))/mdet;
dest[2]=((*this)(0,1)*(*this)(1,2) - (*this)(0,2)*(*this)(1,1))/mdet;
dest[3]=((*this)(1,2)*(*this)(2,0) - (*this)(1,0)*(*this)(2,2))/mdet;
dest[4]=((*this)(0,0)*(*this)(2,2) - (*this)(0,2)*(*this)(2,0))/mdet;
dest[5]=((*this)(0,2)*(*this)(1,0) - (*this)(0,0)*(*this)(1,2))/mdet;
dest[6]=((*this)(1,0)*(*this)(2,1) - (*this)(1,1)*(*this)(2,0))/mdet;
dest[7]=((*this)(0,1)*(*this)(2,0) - (*this)(0,0)*(*this)(2,1))/mdet;
dest[8]=((*this)(0,0)*(*this)(1,1) - (*this)(0,1)*(*this)(1,0))/mdet;
};
private:
};