- Timestamp:
- Nov 21, 2005, 10:17:56 AM (19 years ago)
- Location:
- trunk/src/lib/math
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/math/matrix.cc
r5664 r5665 5 5 6 6 7 void Matrix::eigVl(const Matrix& mat) 7 Vector Matrix::eigenValues() const 8 8 { 9 10 float eigValue[3]; 11 float eigVc[9]; 9 Vector eigVl; 12 10 13 11 float a = 0; … … 50 48 float p = sqrt((b/2.0)*(b/2.0) - Q); 51 49 52 eigV alue[0]= c[2]/3.0 + 2 * pow(p, 1/3.0) * cos(psi/3.0);53 eigV alue[1]= c[2]/3.0 - pow(p, 1/3.0) * (cos(psi/3.0)50 eigVl.x = c[2]/3.0 + 2 * pow(p, 1/3.0) * cos(psi/3.0); 51 eigVl.y = c[2]/3.0 - pow(p, 1/3.0) * (cos(psi/3.0) 54 52 + sqrt(3.0) * sin(psi/3.0)); 55 eigV alue[2]= c[2]/3.0 - pow(p, 1/3.0) * (cos(psi/3.0)53 eigVl.z = c[2]/3.0 - pow(p, 1/3.0) * (cos(psi/3.0) 56 54 - sqrt(3.0) * sin(psi/3.0)); 57 55 … … 60 58 else if (Q == 0) 61 59 { 62 eigV alue[0]= c[2]/3.0 + pow(b/2.0, 1.0/3.0);63 eigV alue[1]= c[2]/3.0 + pow(b/2.0, 1.0/3.0);64 eigV alue[2]= c[2]/3.0 + 2* pow(b/2.0, 1.0/3.0);60 eigVl.x = c[2]/3.0 + pow(b/2.0, 1.0/3.0); 61 eigVl.y = c[2]/3.0 + pow(b/2.0, 1.0/3.0); 62 eigVl.z = c[2]/3.0 + 2* pow(b/2.0, 1.0/3.0); 65 63 } 66 64 // 1 Root (not calculating anything.) … … 68 66 { 69 67 printf("A is multiple of Identity matrix (lambda * I3))\n"); 70 eigV alue[0] = eigValue[1] = eigValue[2]= 1;68 eigVl.x = eigVl.y = eigVl.z = 1; 71 69 } 70 printf("%f %f %f\n", eigVl.x, eigVl.y, eigVl.z); 71 return eigVl; 72 72 73 } 73 74 75 void Matrix::eigenVectors(Vector& a, Vector& b, Vector& c) const 76 { 77 Vector eigVl = this->eigenValues(); 78 79 float eigVc[9]; 74 80 // EigenVectors 75 81 for (int i = 0; i < 3; ++i) 76 82 { 77 83 printf (":: i = %d\n", i); 78 Matrix M = *this - Matrix::identity() * eigV alue[i];84 Matrix M = *this - Matrix::identity() * eigVl.x; 79 85 Vector m1, m2, m3; 80 86 … … 94 100 // u2 = M*u2; 95 101 // u3 = M*u3; 96 //102 // 97 103 // printf("%f, %f, %f\n", u1.x, u1.y, u1.z); 98 104 // printf("%f, %f, %f\n", u2.x, u2.y, u2.z); … … 102 108 103 109 this->debug(); 104 105 printf("%f %f %f\n", eigValue[0], eigValue[1], eigValue[2]);106 107 110 } 108 111 -
trunk/src/lib/math/matrix.h
r5664 r5665 29 29 }; 30 30 31 Matrix operator+ (const Matrix& m) {31 Matrix operator+ (const Matrix& m) const { 32 32 return Matrix (this->m11 + m.m11, this->m12 + m.m12, this->m13 + m.m13, 33 33 this->m21 + m.m21, this->m22 + m.m22, this->m23 + m.m23, … … 35 35 } 36 36 37 Matrix operator- (const Matrix& m) {37 Matrix operator- (const Matrix& m) const { 38 38 return Matrix (this->m11 - m.m11, this->m12 - m.m12, this->m13 - m.m13, 39 39 this->m21 - m.m21, this->m22 - m.m22, this->m23 - m.m23, … … 41 41 } 42 42 43 Matrix operator* (float k) {43 Matrix operator* (float k) const { 44 44 return Matrix(this->m11 - k, this->m12 - k, this->m13 - k, 45 45 this->m21 - k, this->m22 - k, this->m23 - k, … … 47 47 } 48 48 49 Vector operator* (const Vector& v) {49 Vector operator* (const Vector& v) const { 50 50 return Vector (this->m11*v.x + this->m12*v.y + this->m13*v.z, 51 51 this->m21*v.x + this->m22*v.y + this->m23*v.z, … … 55 55 56 56 57 Matrix getTransposed() {57 Matrix getTransposed() const { 58 58 return Matrix( this->m11, this->m21, this->m31, 59 59 this->m12, this->m22, this->m32, … … 61 61 } 62 62 63 void toVectors(Vector& m1, Vector& m2, Vector& m3) {63 void toVectors(Vector& m1, Vector& m2, Vector& m3) const { 64 64 m1 = Vector(this->m11, this->m12, this->m13); 65 65 m2 = Vector(this->m21, this->m22, this->m23); … … 67 67 } 68 68 69 Vector eigenValues() const; 70 void eigenVectors(Vector& a, Vector& b, Vector& c) const; 69 71 70 72 /// @todo optimize 71 73 static Matrix identity() { return Matrix (1,0,0, 0,1,0, 0,0,1); } 72 74 73 void eigVl(const Matrix& matrix);74 75 void debug() const; 75 76
Note: See TracChangeset
for help on using the changeset viewer.