Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5665 in orxonox.OLD


Ignore:
Timestamp:
Nov 21, 2005, 10:17:56 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: optimized matrix

Location:
trunk/src/lib/math
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/math/matrix.cc

    r5664 r5665  
    55
    66
    7 void Matrix::eigVl(const Matrix& mat)
     7Vector Matrix::eigenValues() const
    88{
    9 
    10   float eigValue[3];
    11   float eigVc[9];
     9  Vector eigVl;
    1210
    1311  float a = 0;
     
    5048    float p = sqrt((b/2.0)*(b/2.0) - Q);
    5149
    52     eigValue[0] = c[2]/3.0 + 2 * pow(p, 1/3.0) * cos(psi/3.0);
    53     eigValue[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)
    5452        + sqrt(3.0) * sin(psi/3.0));
    55     eigValue[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)
    5654        - sqrt(3.0) * sin(psi/3.0));
    5755
     
    6058  else if (Q == 0)
    6159  {
    62     eigValue[0] = c[2]/3.0 + pow(b/2.0, 1.0/3.0);
    63     eigValue[1] = c[2]/3.0 + pow(b/2.0, 1.0/3.0);
    64     eigValue[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);
    6563  }
    6664  // 1 Root (not calculating anything.)
     
    6866  {
    6967    printf("A is multiple of Identity matrix (lambda * I3))\n");
    70     eigValue[0] = eigValue[1] = eigValue[2] = 1;
     68    eigVl.x = eigVl.y = eigVl.z = 1;
    7169  }
     70  printf("%f %f %f\n", eigVl.x, eigVl.y, eigVl.z);
     71  return eigVl;
    7272
     73}
    7374
     75void Matrix::eigenVectors(Vector& a, Vector& b, Vector& c) const
     76{
     77  Vector eigVl = this->eigenValues();
     78
     79  float eigVc[9];
    7480  // EigenVectors
    7581  for (int i = 0; i < 3; ++i)
    7682  {
    7783    printf (":: i = %d\n", i);
    78     Matrix M = *this -  Matrix::identity() * eigValue[i];
     84    Matrix M = *this -  Matrix::identity() * eigVl.x;
    7985    Vector m1, m2, m3;
    8086
     
    94100//     u2 = M*u2;
    95101//     u3 = M*u3;
    96 //
     102    //
    97103//     printf("%f, %f, %f\n", u1.x, u1.y, u1.z);
    98104//     printf("%f, %f, %f\n", u2.x, u2.y, u2.z);
     
    102108
    103109  this->debug();
    104 
    105   printf("%f %f %f\n", eigValue[0], eigValue[1], eigValue[2]);
    106 
    107110}
    108111
  • trunk/src/lib/math/matrix.h

    r5664 r5665  
    2929    };
    3030
    31     Matrix operator+ (const Matrix& m) {
     31    Matrix operator+ (const Matrix& m) const {
    3232      return Matrix (this->m11 + m.m11, this->m12 + m.m12, this->m13 + m.m13,
    3333                     this->m21 + m.m21, this->m22 + m.m22, this->m23 + m.m23,
     
    3535    }
    3636
    37     Matrix operator- (const Matrix& m) {
     37    Matrix operator- (const Matrix& m) const {
    3838      return Matrix (this->m11 - m.m11, this->m12 - m.m12, this->m13 - m.m13,
    3939                     this->m21 - m.m21, this->m22 - m.m22, this->m23 - m.m23,
     
    4141    }
    4242
    43     Matrix operator* (float k) {
     43    Matrix operator* (float k) const {
    4444      return Matrix(this->m11 - k, this->m12 - k, this->m13 - k,
    4545                    this->m21 - k, this->m22 - k, this->m23 - k,
     
    4747    }
    4848
    49     Vector operator* (const Vector& v) {
     49    Vector operator* (const Vector& v) const {
    5050      return Vector (this->m11*v.x + this->m12*v.y + this->m13*v.z,
    5151                     this->m21*v.x + this->m22*v.y + this->m23*v.z,
     
    5555
    5656
    57     Matrix getTransposed() {
     57    Matrix getTransposed() const {
    5858      return Matrix( this->m11, this->m21, this->m31,
    5959                     this->m12, this->m22, this->m32,
     
    6161    }
    6262
    63     void toVectors(Vector& m1, Vector& m2, Vector& m3) {
     63    void toVectors(Vector& m1, Vector& m2, Vector& m3) const {
    6464      m1 = Vector(this->m11, this->m12, this->m13);
    6565      m2 = Vector(this->m21, this->m22, this->m23);
     
    6767    }
    6868
     69    Vector eigenValues() const;
     70    void eigenVectors(Vector& a, Vector& b, Vector& c) const;
    6971
    7072    /// @todo optimize
    7173    static Matrix identity() { return Matrix (1,0,0, 0,1,0, 0,0,1); }
    7274
    73     void eigVl(const Matrix& matrix);
    7475    void debug() const;
    7576
Note: See TracChangeset for help on using the changeset viewer.