Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5675 in orxonox.OLD for trunk/src/lib


Ignore:
Timestamp:
Nov 21, 2005, 9:59:09 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: optimisations

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

Legend:

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

    r5673 r5675  
    1919
    2020
    21 Vector Matrix::getEigenValues() const
     21int Matrix::getEigenValues(Vector& eigenValues) const
    2222{
    23   Vector eigVl;
    24 
     23  int retVal = -1;
    2524  float a = 0;
    2625  float b = 0;
     
    6160    float p = sqrt((b/2.0)*(b/2.0) - Q);
    6261
    63     eigVl.x = c[2]/3.0 + 2 * pow(p, 1/3.0) * cos(psi/3.0);
    64     eigVl.y = c[2]/3.0 - pow(p, 1/3.0) * (cos(psi/3.0)
     62    eigenValues.x = c[2]/3.0 + 2 * pow(p, 1/3.0) * cos(psi/3.0);
     63    eigenValues.y = c[2]/3.0 - pow(p, 1/3.0) * (cos(psi/3.0)
    6564        + sqrt(3.0) * sin(psi/3.0));
    66     eigVl.z = c[2]/3.0 - pow(p, 1/3.0) * (cos(psi/3.0)
     65    eigenValues.z = c[2]/3.0 - pow(p, 1/3.0) * (cos(psi/3.0)
    6766        - sqrt(3.0) * sin(psi/3.0));
    68 
     67    retVal = 3;
    6968  }
    7069  // 2 Distinct Roots
    7170  else if (Q == 0)
    7271  {
    73     eigVl.x = c[2]/3.0 + pow(b/2.0, 1.0/3.0);
    74     eigVl.y = c[2]/3.0 + pow(b/2.0, 1.0/3.0);
    75     eigVl.z = c[2]/3.0 + 2* pow(b/2.0, 1.0/3.0);
     72    eigenValues.x = eigenValues.y = c[2]/3.0 + pow(b/2.0, 1.0/3.0);
     73    eigenValues.z = c[2]/3.0 + 2* pow(b/2.0, 1.0/3.0);
     74    retVal = 2;
    7675  }
    7776  // 1 Root (not calculating anything.)
    7877  else if (Q > 0)
    7978  {
    80     printf("This Matrix is a multiple of the Identity matrix (lambda * I3))\n");
    81     eigVl.x = eigVl.y = eigVl.z = 1;
     79    eigenValues.x = eigenValues.y = eigenValues.z = 1;
     80    retVal = 1;
    8281  }
    83   return eigVl;
     82  return retVal;
    8483}
    8584
    86 void Matrix::getEigenVectors(Vector& a, Vector& b, Vector& c) const
     85void Matrix::getEigenVectors(Vector& eigVc1, Vector& eigVc2, Vector& eigVc3) const
    8786{
    88   Vector eigVl = this->getEigenValues();
     87  Vector eigenValues;
     88  int eigenValuesCount = this->getEigenValues(eigenValues);
    8989
    90   float eigVal[3] = { eigVl.x, eigVl.y, eigVl.z };
     90  /* eigenvec creation */
     91  eigVc1.x = -1/this->m13*(this->m33 - eigenValues.x) +
     92      (this->m32*(-this->m31*this->m32 + this->m12*this->m33 - this->m12*eigenValues.x)) /
     93      this->m13*(-this->m13*this->m22 - this->m12*this->m23 + this->m13*eigenValues.x);
    9194
    92   Vector eigVc[3];
    93   /* eigenvec test */
    94   for(int i = 0; i < 2; i++)
    95   {
    96     eigVc[i].x = -1/this->m13*(this->m33 - eigVal[i]) + (this->m32*(-this->m31*this->m32 + this->m12*this->m33 - this->m12*eigVal[i])) /
    97         this->m13*(-this->m13*this->m22 - this->m12*this->m23 + this->m13*eigVal[i]);
     95  eigVc1.y = -( -this->m13*this->m23 + this->m12*this->m33 - this->m12*eigenValues.x) /
     96      (-this->m31*this->m22 + this->m12*this->m23 + this->m13*eigenValues.x);
    9897
    99     eigVc[i].y = -( -this->m13*this->m23 + this->m12*this->m33 - this->m12*eigVal[i]) /
    100         (-this->m31*this->m22 + this->m12*this->m23 + this->m13*eigVal[i]);
     98  eigVc1.z = 1.0f;
    10199
    102     eigVc[i].z = 1.0f;
     100  eigVc2.x = -1/this->m13*(this->m33 - eigenValues.y) +
     101      (this->m32*(-this->m31*this->m32 + this->m12*this->m33 - this->m12*eigenValues.y)) /
     102      this->m13*(-this->m13*this->m22 - this->m12*this->m23 + this->m13*eigenValues.y);
    103103
    104     eigVc[i] /= eigVc[i].len();
    105   }
    106   eigVc[2] = eigVc[0].cross(eigVc[1]);
     104  eigVc2.y = -( -this->m13*this->m23 + this->m12*this->m33 - this->m12*eigenValues.y) /
     105      (-this->m31*this->m22 + this->m12*this->m23 + this->m13*eigenValues.y);
    107106
    108   a = eigVc[0];
    109   b = eigVc[1];
    110   c = eigVc[2];
     107  eigVc2.z = 1.0f;
     108
     109  eigVc3 = eigVc1.cross(eigVc2);
     110
     111  eigVc1.normalize();
     112  eigVc2.normalize();
     113  eigVc3.normalize();
    111114}
    112115
  • trunk/src/lib/math/matrix.h

    r5673 r5675  
    5858    }
    5959
    60     Vector getEigenValues() const;
     60    int getEigenValues(Vector& eigenVectors) const;
    6161    void getEigenVectors(Vector& a, Vector& b, Vector& c) const;
    6262
Note: See TracChangeset for help on using the changeset viewer.