Changeset 5668 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Nov 21, 2005, 11:51:29 AM (19 years ago)
- Location:
- trunk/src/lib/math
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/math/matrix.cc
r5667 r5668 5 5 6 6 7 Vector Matrix:: eigenValues() const7 Vector Matrix::getEigenValues() const 8 8 { 9 9 Vector eigVl; … … 65 65 else if (Q > 0) 66 66 { 67 printf(" A is multiple ofIdentity matrix (lambda * I3))\n");67 printf("This Matrix is a multiple of the Identity matrix (lambda * I3))\n"); 68 68 eigVl.x = eigVl.y = eigVl.z = 1; 69 69 } … … 73 73 } 74 74 75 void Matrix:: eigenVectors(Vector& a, Vector& b, Vector& c) const75 void Matrix::getEigenVectors(Vector& a, Vector& b, Vector& c) const 76 76 { 77 Vector eigVl = this-> eigenValues();77 Vector eigVl = this->getEigenValues(); 78 78 79 float eigVc[9]; 79 float eigVal[3] = { eigVl.x, eigVl.y, eigVl.z }; 80 81 Vector eigVc[3]; 82 /* eigenvec test */ 83 for(int i = 0; i < 3; i++) 84 { 85 eigVc[i].x = -1/this->m13*(this->m33 - eigVal[i]) + (this->m32*(-this->m31*this->m32 + this->m12*this->m33 - this->m12*eigVal[i])) / 86 this->m13*(-this->m13*this->m22 - this->m12*this->m23 + this->m13*eigVal[i]); 87 88 eigVc[i].y = -( -this->m13*this->m23 + this->m12*this->m33 - this->m12*eigVal[i]) / 89 (-this->m31*this->m22 + this->m12*this->m23 + this->m13*eigVal[i]); 90 91 eigVc[i].z = 1.0f; 92 93 94 printf("home brew: %f, %f, %f\n", eigVc[i].x, eigVc[i].y, eigVc[i].z); 95 } 96 97 80 98 // EigenVectors 81 for (int i = 0; i < 3; ++i) 82 { 83 printf (":: i = %d\n", i); 84 Matrix M = *this - Matrix::identity() * eigVl.x; 85 Vector m1, m2, m3; 99 // for (int i = 0; i < 3; ++i) 100 // { 101 // printf (":: i = %d\n", i); 102 // Matrix M = *this - Matrix::identity() * eigVal[i]; 103 // Vector m1, m2, m3; 104 // 105 // M.getTransposed().toVectors(m1, m2, m3); 106 // Matrix U ( M.m22*M.m33 - M.m23*M.m23, M.m13*M.m23 - M.m12*M.m33, M.m12*M.m23 - M.m13*M.m22, 107 // M.m13*M.m23 - M.m12*M.m33, M.m11*M.m33 - M.m13*M.m13, M.m12*M.m13 - M.m23*M.m11, 108 // M.m12*M.m23 - M.m13*M.m22, M.m13*M.m12 - M.m23*M.m11, M.m11*M.m22 - M.m12*M.m12); 109 // U.debug(); 110 // 111 // Vector u1, u2, u3; 112 // U.toVectors(u1, u2, u3); 113 // 114 // /* 115 // u1 = m2.cross(m3); 116 // u2 = m3.cross(m1); 117 // u3 = m1.cross(m2); 118 // */ 119 // 120 // u1 /= u1.len(); 121 // u2 /= u2.len(); 122 // u3 /= u3.len(); 123 // 124 // 125 // printf("%f, %f, %f\n", u1.x, u1.y, u1.z); 126 // printf("%f, %f, %f\n", u2.x, u2.y, u2.z); 127 // printf("%f, %f, %f\n", u3.x, u3.y, u3.z); 86 128 87 M.getTransposed().toVectors(m1, m2, m3);88 129 89 Vector u1, u2, u3;90 91 u1 = m2.cross(m3); u1 /= u1.len();92 u2 = m3.cross(m1); u2 /= u2.len();93 u3 = m1.cross(m2); u3 /= u3.len();94 95 printf("%f, %f, %f\n", u1.x, u1.y, u1.z);96 printf("%f, %f, %f\n", u2.x, u2.y, u2.z);97 printf("%f, %f, %f\n", u3.x, u3.y, u3.z);98 130 99 131 // u1 = M*u1; … … 105 137 // printf("%f, %f, %f\n", u3.x, u3.y, u3.z); 106 138 // printf("\n\n"); 107 } 108 109 //Vector eigVc[3]; 110 /* eigenvec test */ 111 /* 112 for(int i = 0; i < 3; i++) 113 { 114 eigVc[i].x =-1/this->m13*(this->m33 - eigValue[i]) + (this->m32*(-this->m31*this->m32 + this->m12*this->m33 - this->m12*eigVl[i])) / 115 this->m13*(-this->m13*this->m22 - this->m12*this->m23 + this->m13*eigVl[i]); 116 eigVc[i].y = -( -this->m13*this->m23 + this->m12*this->m33 - this->m12*eigVl[i]) / 117 (-this->m31*this->m22 + this->m12*this->m23 + this->m13*eigVl[i]); 118 eigVc[i].z = 1.0f; 119 120 121 printf("home brewn: %f, %f, %f\n", eigVc[i].x, eigVc[i].y, eigVc[i].z); 122 123 }*/ 139 // } 124 140 125 141 … … 128 144 } 129 145 130 131 146 void Matrix::debug() const 132 147 { 133 printf(" input:| %f | %f | %f |\n", this->m11, this->m12, this->m13 );134 printf(" 135 printf(" 148 printf("| %f | %f | %f |\n", this->m11, this->m12, this->m13 ); 149 printf("| %f | %f | %f |\n", this->m21, this->m22, this->m23 ); 150 printf("| %f | %f | %f |\n", this->m31, this->m32, this->m33 ); 136 151 137 152 } -
trunk/src/lib/math/matrix.h
r5665 r5668 51 51 this->m21*v.x + this->m22*v.y + this->m23*v.z, 52 52 this->m31*v.x + this->m32*v.y + this->m33*v.z ); 53 54 53 } 55 54 … … 67 66 } 68 67 69 Vector eigenValues() const;70 void eigenVectors(Vector& a, Vector& b, Vector& c) const;68 Vector getEigenValues() const; 69 void getEigenVectors(Vector& a, Vector& b, Vector& c) const; 71 70 72 71 /// @todo optimize -
trunk/src/lib/math/test.cc
r5666 r5668 4 4 int main (int argc, char** argv) 5 5 { 6 7 Matrix matrix( 0, 1, -1,8 1, 1, 0,9 -1, 0, 1);10 6 11 matrix.eigVl(matrix); 7 Matrix matrix( 0, 1, -1, 8 1, 1, 0, 9 -1, 0, 1); 10 11 Vector eigVc[3]; 12 13 // matrix.getEigenValues(); 14 matrix.getEigenVectors(eigVc[0], eigVc[1], eigVc[2]); 12 15 } 13 16
Note: See TracChangeset
for help on using the changeset viewer.