$search
00001 #ifndef MAT3X3_HH 00002 #define MAT3X3_HH 00003 00004 /* 00005 James R. Diebel 00006 Stanford University 00007 00008 Started: 3 December 2004 00009 00010 vec3d.hh - Class definition of basic 3d vector class 00011 00012 Depends on Vec3d class (vec3d.hh) 00013 */ 00014 00015 #include <math.h> 00016 #include <stdlib.h> 00017 #include <iostream> 00018 #include "vec3d.hh" 00019 #ifndef PI 00020 #define PI 3.14159265358979323846 00021 #endif 00022 00023 00024 using namespace std; 00025 00026 namespace bmtk { 00027 00028 // little support class used to facilitate efficient [] referencing 00029 class Row1x3 { 00030 public: 00031 float* x; 00032 00033 float operator [] (const int index) const; 00034 float& operator [] (const int index); 00035 }; 00036 00037 class Mat3x3 { 00038 public: // everything is public 00039 00040 // data is a 1D array of size 9 00041 float x[9]; 00042 Row1x3 r[3]; 00043 00044 // Constructors 00045 Mat3x3(); 00046 Mat3x3(bool inf); 00047 Mat3x3(float x11, float x12, float x13, 00048 float x21, float x22, float x23, 00049 float x31, float x32, float x33); 00050 Mat3x3(const float a); 00051 Mat3x3(const float* x); 00052 Mat3x3(const Vec3d& v); 00053 Mat3x3(const Vec3d& v0, const Vec3d& v1); 00054 Mat3x3(const Vec3d& v0, const Vec3d& v1, const Vec3d& v2); 00055 Mat3x3(const Vec3d& v0, const Vec3d& v1, const Vec3d& v2, 00056 const Vec3d& lambda); 00057 00058 00059 // Assignments 00060 Mat3x3 operator = (const Mat3x3& m); 00061 00062 // Reference operator: zero-based square bracket referencing 00063 Row1x3 operator [] (const int index) const; 00064 Row1x3& operator [] (const int index); 00065 00066 // Addition and subtraction: <matrix> +/- <matrix> 00067 Mat3x3 operator + (const Mat3x3& m) const; 00068 void operator += (const Mat3x3& m); 00069 Mat3x3 operator - (const Mat3x3& m) const; 00070 void operator -= (const Mat3x3& m); 00071 00072 // Multiplication and division: <matrix> *// <scalar> 00073 Mat3x3 operator * (const float a) const; 00074 void operator *= (const float a); 00075 Mat3x3 operator / (const float a) const; 00076 void operator /= (const float a); 00077 00078 // Multiplication: <matrix> * <vector> 00079 Vec3d operator * (const Vec3d& v) const; 00080 00081 // Multiplication: <matrix> * <vector> 00082 Mat3x3 operator * (const Mat3x3& m) const; 00083 void operator *= (const Mat3x3& m); 00084 00085 // Determinant, inverse, transpose, etc. 00086 float det() const; 00087 Mat3x3 inv() const; 00088 void transIt(); 00089 Mat3x3 trans() const; 00090 static Mat3x3 outer(const Vec3d& v0, const Vec3d& v1); 00091 static Mat3x3 eigenReconst(const Vec3d& v0, const Vec3d& v1, 00092 const Vec3d& v2, const Vec3d& l); 00093 // output functions 00094 void print(); 00095 }; 00096 00097 // Define a few global operators to handle cases where 00098 // a Mat3x3 is the second argument in a binary operator 00099 Mat3x3 operator * (const float a, const Mat3x3 &m); 00100 Vec3d operator * (const Vec3d& v, const Mat3x3 &m); 00101 void operator *= (Vec3d& v, const Mat3x3& m); 00102 00103 // Define << operator to handle output to screen 00104 ostream& operator << (ostream& os, const Mat3x3 &m); 00105 00106 } // namespace bmtk 00107 00108 #endif