Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Nov 21, 2005, 3:10:20 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: created a simple matrix class

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

Legend:

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

    r5661 r5662  
    22#include <stdio.h>
    33#include <math.h>
     4#include "matrix.h"
    45
    5 void eigVl(float mat[3][3])
     6
     7class Vector
     8{
     9  public:
     10    Vector (float x, float y, float z) { this->x=x; this->y = y; this->z = z; };
     11  float x, y, z;
     12  inline Vector cross (const Vector& v) const { return Vector(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x ); }
     13};
     14
     15void Matrix::eigVl(const Matrix& mat)
    616{
    717
     
    1525
    1626  // c[0] is the determinante of mat
    17   c[0] = mat[0][0] * mat[1][1] * mat[2][2] +
    18       2* mat[0][1] * mat[0][2] * mat[1][2] -
    19       mat[0][0] * mat[1][2] * mat[1][2] -
    20       mat[1][1] * mat[0][2] * mat[0][2] -
    21       mat[2][2] * mat[0][1] * mat[0][1];
     27  c[0] = this->m11 * this->m22 * this->m33 +
     28      2* this->m12 * this->m13 * this->m23 -
     29      this->m11 * this->m23 * this->m23 -
     30      this->m22 * this->m13 * this->m13 -
     31      this->m33 * this->m12 * this->m12;
    2232
    2333  // c[1] is the trace of a
    24   c[1] = mat[0][0] * mat[1][1] -
    25       mat[0][1] * mat[0][1] +
    26       mat[0][0] * mat[2][2] -
    27       mat[0][2] * mat[0][2] +
    28       mat[1][1] * mat[2][2] -
    29       mat[1][2] * mat[1][2];
     34  c[1] = this->m11 * this->m22 -
     35      this->m12 * this->m12 +
     36      this->m11 * this->m33 -
     37      this->m13 * this->m13 +
     38      this->m22 * this->m33 -
     39      this->m23 * this->m23;
    3040
    3141  // c[2] is the sum of the diagonal elements
    32   c[2] = mat[0][0] +
    33       mat[1][1] +
    34       mat[2][2];
     42  c[2] = this->m11 +
     43      this->m22 +
     44      this->m33;
    3545
    3646
     
    4151  float Q = b*b/4.0 + a*a*a/27.0;
    4252
     53  // 3 distinct Roots
    4354  if (Q < 0)
    4455  {
     
    5465
    5566  }
     67  // 2 Distinct Roots
    5668  else if (Q == 0)
    5769  {
     
    6072    eigValue[2] = c[2]/3.0 + 2* pow(b/2.0, 1.0/3.0);
    6173  }
     74  // 1 Root (not calculating anything.)
    6275  else if (Q > 0)
    6376  {
     
    6679  }
    6780
    68   printf("input: | %f | %f | %f |\n", mat[0][0], mat[0][1], mat[0][2] );
    69   printf("       | %f | %f | %f |\n", mat[1][0], mat[1][1], mat[1][2] );
    70   printf("       | %f | %f | %f |\n", mat[2][0], mat[2][1], mat[2][2] );
     81  Matrix M;
     82
     83  float u11, u12, u13, u22, u23, u33;
     84
     85  this->debug();
    7186
    7287  printf("%f %f %f\n", eigValue[0], eigValue[1], eigValue[2]);
    7388
     89}
    7490
    7591
     92void Matrix::debug() const
     93{
     94  printf("input: | %f | %f | %f |\n", this->m11, this->m12, this->m13 );
     95  printf("       | %f | %f | %f |\n", this->m21, this->m22, this->m23 );
     96  printf("       | %f | %f | %f |\n", this->m31, this->m32, this->m33 );
    7697
    7798}
     99
  • trunk/src/lib/math/matrix.h

    r5661 r5662  
    1 void eigVl(float mat[3][3]);
     1
     2
     3
     4class Matrix
     5{
     6  public:
     7    float m11;    float m12;     float m13;
     8    float m21;    float m22;     float m23;
     9    float m31;    float m32;     float m33;
     10
     11    void eigVl(const Matrix& matrix);
     12    void debug() const;
     13};
  • trunk/src/lib/math/vector.cc

    r5420 r5662  
    2222
    2323#include "vector.h"
     24#ifdef DEBUG
    2425#include "debug.h"
     26#else
     27#define PRINT(x) printf
     28#endif
    2529
    2630using namespace std;
Note: See TracChangeset for help on using the changeset viewer.