00001 00002 00008 00011 00012 00013 #ifndef MATRIX_H 00014 #define MATRIX_H 00015 00016 #include <iostream.h> 00017 #include <cammva.h> 00018 namespace O_SESSAME { 00019 00020 const int MatrixIndexBase = 1; 00021 const int VectorIndexBase = 1; 00022 const int MatrixRowsIndex = 1; 00023 const int MatrixColsIndex = 2; 00024 typedef CAMdoubleMatrix Matrix; 00025 typedef CAMdoubleVector Vector; 00031 inline Matrix eye(int _rowColumns) 00032 { 00033 Matrix eyeOutput(_rowColumns,_rowColumns); 00034 eyeOutput.setToValue(0.0); 00035 for(int ii = MatrixIndexBase;ii < _rowColumns + MatrixIndexBase; ++ii) 00036 eyeOutput(ii,ii) = 1.0; 00037 return eyeOutput; 00038 } 00039 00044 inline double trace(const Matrix &_inMatrix) 00045 { 00046 double Sum = 0; 00047 for(int ii = MatrixIndexBase;ii < _inMatrix[MatrixRowsIndex].getIndexCount() + MatrixIndexBase; ++ii) 00048 Sum += _inMatrix(ii,ii); 00049 return Sum; 00050 } 00051 00057 inline double norm2(const Vector &_inVector) 00058 { 00059 double Sum = 0; 00060 for(int ii = VectorIndexBase;ii < _inVector.getIndexCount() + VectorIndexBase; ++ii) 00061 Sum += _inVector(ii) * _inVector(ii); 00062 return sqrt(Sum); 00063 } 00064 00069 inline void normalize(Vector &_inVector) 00070 { 00071 _inVector /= norm2(_inVector); 00072 return; 00073 } 00074 00080 inline double normInf(const Vector &_inVector) 00081 { 00082 return _inVector.maxAbs(); 00083 } 00084 00099 inline Matrix skew(const Vector &_inVector) 00100 { 00101 Matrix Rout(3,3); 00102 Rout.setToValue(0.0); 00103 Rout(MatrixIndexBase+0,MatrixIndexBase+1) = 00104 -_inVector(VectorIndexBase+2); 00105 Rout(MatrixIndexBase+0,MatrixIndexBase+2) = 00106 _inVector(VectorIndexBase+1); 00107 Rout(MatrixIndexBase+1,MatrixIndexBase+0) = 00108 _inVector(VectorIndexBase+2); 00109 Rout(MatrixIndexBase+1,MatrixIndexBase+2) = 00110 -_inVector(VectorIndexBase+0); 00111 Rout(MatrixIndexBase+2,MatrixIndexBase+0) = 00112 -_inVector(VectorIndexBase+1); 00113 Rout(MatrixIndexBase+2,MatrixIndexBase+1) = 00114 _inVector(VectorIndexBase+0); 00115 return Rout; 00116 } 00117 00124 inline Vector crossP(const Vector &_v1, const Vector &_v2) 00125 { 00126 return skew(_v1) * _v2; 00127 } 00128 } 00129 #endif 00130 00131