Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5696 in orxonox.OLD for trunk/src/lib/math


Ignore:
Timestamp:
Nov 22, 2005, 1:35:33 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: documented matrix.h

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

Legend:

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

    r5677 r5696  
    1414*/
    1515#include "matrix.h"
    16 
     16#include <math.h>
     17
     18#ifdef DEBUG
     19#include "debug.h"
     20#else
    1721#include <stdio.h>
    18 #include <math.h>
    19 
    20 
     22#define PRINT(x) printf
     23#endif
     24
     25/**
     26 * constructs a Matrix from all Parameters in a Row
     27 * @param m11 [0][0]
     28 * @param m12 [0][1]
     29 * @param m13 [0][2]
     30 * @param m21 [1][0]
     31 * @param m22 [1][1]
     32 * @param m23 [1][2]
     33 * @param m31 [2][0]
     34 * @param m32 [2][1]
     35 * @param m33 [2][2]
     36 */
     37Matrix::Matrix ( float m11, float m12, float m13,
     38             float m21, float m22, float m23,
     39             float m31, float m32, float m33 )
     40{
     41  this->m11 = m11; this->m12 = m12; this->m13 = m13;
     42  this->m21 = m21; this->m22 = m22; this->m23 = m23;
     43  this->m31 = m31; this->m32 = m32; this->m33 = m33;
     44};
     45
     46/**
     47 * creates a Matrix out of an Array of floats with size [3][3]
     48 * @param m the Matrix stored in an Array
     49 */
     50Matrix::Matrix(const float m[3][3])
     51{
     52  this->m11 = m[0][0]; this->m12 = m[0][1]; this->m13 = m[0][2];
     53  this->m21 = m[1][0]; this->m22 = m[1][1]; this->m23 = m[1][2];
     54  this->m31 = m[2][0]; this->m32 = m[2][1]; this->m33 = m[2][2];
     55};
     56
     57
     58/**
     59 * adds a Matrix to this one returning the result
     60 * @param m the Matrix to add to this one
     61 * @returns a copy of this Matrix added m
     62 */
     63Matrix Matrix::operator+ (const Matrix& m) const
     64{
     65  return Matrix (this->m11 + m.m11, this->m12 + m.m12, this->m13 + m.m13,
     66                 this->m21 + m.m21, this->m22 + m.m22, this->m23 + m.m23,
     67                 this->m31 + m.m31, this->m32 + m.m32, this->m33 + m.m33);
     68}
     69
     70/**
     71 * sustracts a Matrix from this one returning the result
     72 * @param m the Matrix to substract from this one
     73 * @returns a copy of this Matrix substracted m
     74 */
     75Matrix Matrix::operator- (const Matrix& m) const
     76{
     77  return Matrix (this->m11 - m.m11, this->m12 - m.m12, this->m13 - m.m13,
     78                 this->m21 - m.m21, this->m22 - m.m22, this->m23 - m.m23,
     79                 this->m31 - m.m31, this->m32 - m.m32, this->m33 - m.m33);
     80}
     81
     82/**
     83 * multiplies each value of a copu of this Matrix by k
     84 * @param k the multiplication factor
     85 * @returns a copy of this Matrix multiplied by k
     86 */
     87Matrix Matrix::operator* (float k) const
     88{
     89  return Matrix(this->m11 * k, this->m12 * k, this->m13 * k,
     90                this->m21 * k, this->m22 * k, this->m23 * k,
     91                this->m31 * k, this->m32 * k, this->m33 * k);
     92}
     93
     94/**
     95 * multiplies the Matrix by a Vector returning a Vector of the result
     96 * @param v the Vector the matrix will be multiplied with
     97 * @returns the result of the Multiplication
     98 */
     99Vector Matrix::operator* (const Vector& v) const
     100{
     101  return Vector (this->m11*v.x + this->m12*v.y + this->m13*v.z,
     102                 this->m21*v.x + this->m22*v.y + this->m23*v.z,
     103                 this->m31*v.x + this->m32*v.y + this->m33*v.z );
     104}
     105
     106/**
     107 * @returns a Transposed copy of this Matrix
     108 */
     109Matrix Matrix::getTransposed() const
     110{
     111  return Matrix( this->m11, this->m21, this->m31,
     112                 this->m12, this->m22, this->m32,
     113                 this->m13, this->m23, this->m33);
     114}
     115
     116/**
     117 * converts the Matrix into 3 Vector, and returns them in m1, m2 and m3
     118 * @param m1 the first Column of the Matrix as a Vector
     119 * @param m2 the second Column of the Matrix as a Vector
     120 * @param m3 the third Column of the Matrix as a Vector
     121 */
     122void Matrix::toVectors(Vector& m1, Vector& m2, Vector& m3) const
     123{
     124  m1 = Vector(this->m11, this->m21, this->m31);
     125  m2 = Vector(this->m12, this->m22, this->m32);
     126  m3 = Vector(this->m13, this->m23, this->m33);
     127}
     128
     129/**
     130 * @returns the Determinant of this Matrix
     131 */
     132float Matrix::getDeterminant() const
     133{
     134  return this->m11*(this->m22*this->m33 - this->m23*this->m32) -
     135      this->m12*(this->m21*this->m33 - this->m23*this->m31) +
     136      this->m13*(this->m21*this->m32 - this->m22*this->m31);
     137}
     138
     139/**
     140 * calculates an returns the EingenValues of this Matrix.
     141 * @param eigneValues the Values calculated in a Vector
     142 * @returns the Count of found eigenValues
     143 *
     144 * This Function calculates the EigenValues of a 3x3-Matrix explicitly.
     145 * the Returned value eigenValues has the Values stored in Vector form
     146 * The Vector will be filled upside down, meaning if the count of found
     147 * eingenValues is 1 the only value will be located in eigneValues.x
     148 */
    21149int Matrix::getEigenValues(Vector& eigenValues) const
    22150{
     
    83211}
    84212
     213/**
     214 * calculates and returns the EigenVectors of this function as Vectors.
     215 * @param eigVc1 the first eigenVector will be stored here.
     216 * @param eigVc2 the second eigenVector will be stored here.
     217 * @param eigVc3 the third eigenVector will be stored here.
     218 */
    85219void Matrix::getEigenVectors(Vector& eigVc1, Vector& eigVc2, Vector& eigVc3) const
    86220{
     
    122256}
    123257
     258/**
     259 * prints out some nice debug information
     260 */
    124261void Matrix::debug() const
    125262{
  • trunk/src/lib/math/matrix.h

    r5694 r5696  
    77#include "vector.h"
    88
    9 
     9//! Matrix is a 3x3 Matrix class with most important functions
    1010class Matrix
    1111{
    12 
    1312  public:
    1413    Matrix() : m11(0), m12(0), m13(0), m21(0), m22(0), m23(0), m31(0), m32(0), m33(0) { };
     
    1615    Matrix ( float m11, float m12, float m13,
    1716             float m21, float m22, float m23,
    18              float m31, float m32, float m33 )
    19     {
    20       this->m11 = m11; this->m12 = m12; this->m13 = m13;
    21       this->m21 = m21; this->m22 = m22; this->m23 = m23;
    22       this->m31 = m31; this->m32 = m32; this->m33 = m33;
    23     };
    24     Matrix(const float m[3][3]) {
    25       this->m11 = m[0][0]; this->m12 = m[0][1]; this->m13 = m[0][2];
    26       this->m21 = m[1][0]; this->m22 = m[1][1]; this->m23 = m[1][2];
    27       this->m31 = m[2][0]; this->m32 = m[2][1]; this->m33 = m[2][2];
    28     };
     17             float m31, float m32, float m33 );
     18    Matrix(const float m[3][3]);
    2919
    30     Matrix operator+ (const Matrix& m) const {
    31       return Matrix (this->m11 + m.m11, this->m12 + m.m12, this->m13 + m.m13,
    32                      this->m21 + m.m21, this->m22 + m.m22, this->m23 + m.m23,
    33                      this->m31 + m.m31, this->m32 + m.m32, this->m33 + m.m33);
    34     }
     20    Matrix operator+ (const Matrix& m) const;
     21    Matrix operator- (const Matrix& m) const;
     22    Matrix operator* (float k) const;
     23    Vector operator* (const Vector& v) const;
    3524
    36     Matrix operator- (const Matrix& m) const {
    37       return Matrix (this->m11 - m.m11, this->m12 - m.m12, this->m13 - m.m13,
    38                      this->m21 - m.m21, this->m22 - m.m22, this->m23 - m.m23,
    39                      this->m31 - m.m31, this->m32 - m.m32, this->m33 - m.m33);
    40     }
     25    Matrix getTransposed() const;
     26    void toVectors(Vector& m1, Vector& m2, Vector& m3) const;
    4127
    42     Matrix operator* (float k) const {
    43       return Matrix(this->m11 - k, this->m12 - k, this->m13 - k,
    44                     this->m21 - k, this->m22 - k, this->m23 - k,
    45                     this->m31 - k, this->m32 - k, this->m33 - k);
    46     }
    47 
    48     Vector operator* (const Vector& v) const {
    49       return Vector (this->m11*v.x + this->m12*v.y + this->m13*v.z,
    50                      this->m21*v.x + this->m22*v.y + this->m23*v.z,
    51                      this->m31*v.x + this->m32*v.y + this->m33*v.z );
    52     }
    53 
    54 
    55     Matrix getTransposed() const {
    56       return Matrix( this->m11, this->m21, this->m31,
    57                      this->m12, this->m22, this->m32,
    58                      this->m13, this->m23, this->m33);
    59     }
    60 
    61     void toVectors(Vector& m1, Vector& m2, Vector& m3) const {
    62       m1 = Vector(this->m11, this->m12, this->m13);
    63       m2 = Vector(this->m21, this->m22, this->m23);
    64       m3 = Vector(this->m31, this->m32, this->m33);
    65     }
     28    float getDeterminant() const;
    6629
    6730    int getEigenValues(Vector& eigenVectors) const;
     
    7336    void debug() const;
    7437
    75 
    7638  public:
    7739    float m11;    float m12;     float m13;
    7840    float m21;    float m22;     float m23;
    7941    float m31;    float m32;     float m33;
    80 
    8142};
Note: See TracChangeset for help on using the changeset viewer.