00001 /********************************************************************** 00002 matrix3x3.cpp - Handle 3D Rotation matrix. 00003 00004 Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc. 00005 Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison 00006 Some portions Copyright (C) 2006 by Benoit Jacob 00007 00008 This file is part of the Open Babel project. 00009 For more information, see <http://openbabel.org/> 00010 00011 This program is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU General Public License as published by 00013 the Free Software Foundation version 2 of the License. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 ***********************************************************************/ 00020 00021 #ifndef OB_MATRIX3x3_H 00022 #define OB_MATRIX3x3_H 00023 00024 #include <ostream> 00025 00026 #include <openbabel/math/vector3.h> // includes rand.h, which includes <math.h> 00027 #include <openbabel/oberror.h> 00028 00029 #ifndef RAD_TO_DEG 00030 #define RAD_TO_DEG (180.0/M_PI) 00031 #endif 00032 00033 #ifndef DEG_TO_RAD 00034 #define DEG_TO_RAD (M_PI/180.0) 00035 #endif 00036 00037 namespace OpenBabel 00038 { 00039 class OBRandom; // class introduction in rand.h 00040 00041 // class introduction in matrix3x3.cpp 00042 class OBAPI matrix3x3 00043 { 00045 00047 double ele[3][3]; 00048 00049 public: 00051 matrix3x3(void) 00052 { 00053 // Loops are typically unrolled and/or vectorized 00054 for (unsigned int i = 0; i < 3; ++i) 00055 for (unsigned int j = 0; j < 3; ++j) 00056 ele[i][j] = 0.0; 00057 } 00058 00060 matrix3x3(double s) 00061 { 00062 // Loops are typically unrolled and/or vectorized 00063 for (unsigned int i = 0; i < 3; ++i) 00064 for (unsigned int j = 0; j < 3; ++j) 00065 ele[i][j] = 0.0; 00066 00067 for (unsigned int i = 0; i < 3; ++i) 00068 ele[i][i] = s; 00069 } 00070 00072 matrix3x3(vector3 row1,vector3 row2,vector3 row3) 00073 { 00074 ele[0][0] = row1.x(); 00075 ele[0][1] = row1.y(); 00076 ele[0][2] = row1.z(); 00077 ele[1][0] = row2.x(); 00078 ele[1][1] = row2.y(); 00079 ele[1][2] = row2.z(); 00080 ele[2][0] = row3.x(); 00081 ele[2][1] = row3.y(); 00082 ele[2][2] = row3.z(); 00083 } 00084 00086 00087 matrix3x3(double d[3][3]) 00088 { 00089 // Loops are typically unrolled and/or vectorized 00090 for (unsigned int i = 0; i < 3; ++i) 00091 for (unsigned int j = 0; j < 3; ++j) 00092 ele[i][j] = d[i][j]; 00093 00094 // We could also potentially use memcpy here 00095 } 00096 00098 ~matrix3x3() {} 00099 00101 00104 void GetArray(double *m) 00105 { 00106 for (unsigned int i = 0; i < 3; ++i) 00107 for (unsigned int j = 0; j < 3; ++j) 00108 m[3*i+j] = ele[i][j]; 00109 } 00110 00113 const double & operator() (int row, int column ) const 00114 { 00115 return ele[row][column]; 00116 } 00117 00120 double & operator() (int row, int column ) 00121 { 00122 return ele[row][column]; 00123 } 00124 00126 matrix3x3 inverse(void) const 00127 #ifdef OB_OLD_MATH_CHECKS 00128 throw(OBError) 00129 #endif 00130 ; 00131 00133 matrix3x3 transpose(void) const; 00134 00136 void randomRotation(OBRandom &rnd); 00137 00139 double determinant() const; 00140 00142 bool isSymmetric(void) const; 00143 00145 00159 bool isOrthogonal(void) const 00160 { 00161 return (*this * transpose()).isUnitMatrix(); 00162 }; 00163 00165 bool isDiagonal(void) const; 00166 00168 bool isUnitMatrix(void) const; 00169 00171 00174 double Get(int row,int column) const 00175 { 00176 #ifdef OB_OLD_MATH_CHECKS 00177 if (row >= 0 && row <= 2 && column >= 0 && column <= 2) 00178 return(ele[row][column]); 00179 else 00180 return 0.0f; 00181 #else 00182 return(ele[row][column]); 00183 #endif 00184 } 00185 00187 00190 void Set(int row,int column, double v) 00191 { 00192 #ifdef OB_OLD_MATH_CHECKS 00193 if (row >= 0 && row <= 2 && column >= 0 && column <= 2) 00194 ele[row][column]= v; 00195 #else 00196 ele[row][column]= v; 00197 #endif 00198 } 00199 00201 00203 void SetColumn(int column, const vector3 &v) 00204 #ifdef OB_OLD_MATH_CHECKS 00205 throw(OBError) 00206 #endif 00207 ; 00208 00210 00212 void SetRow(int row, const vector3 &v) 00213 #ifdef OB_OLD_MATH_CHECKS 00214 throw(OBError) 00215 #endif 00216 ; 00217 00219 00221 vector3 GetColumn(unsigned int col) const 00222 #ifdef OB_OLD_MATH_CHECKS 00223 throw(OBError) 00224 #endif 00225 ; 00226 00228 00230 vector3 GetRow(unsigned int row) const 00231 #ifdef OB_OLD_MATH_CHECKS 00232 throw(OBError) 00233 #endif 00234 ; 00235 00237 matrix3x3 &operator*=(const double &c) 00238 { 00239 for( int i = 0; i < 3; i++ ) 00240 for( int j = 0; j < 3; j++ ) 00241 ele[i][j] *= c; 00242 return *this; 00243 } 00244 00246 matrix3x3 &operator/=(const double &c) 00247 { 00248 return( (*this) *= ( 1.0 / c ) ); 00249 } 00250 00253 void SetupRotMat(double x, double y, double z); 00254 00256 void PlaneReflection(const vector3 &norm); 00257 00260 void RotAboutAxisByAngle(const vector3 &axis, const double angle); 00261 00267 void FillOrth(double alpha, double beta, double gamma, 00268 double a, double b, double c); 00269 00271 matrix3x3 findEigenvectorsIfSymmetric(vector3 &eigenvals) const 00272 #ifdef OB_OLD_MATH_CHECKS 00273 throw(OBError) 00274 #endif 00275 ; 00276 00278 friend OBAPI vector3 operator *(const matrix3x3 &,const vector3 &); 00279 00281 friend OBAPI matrix3x3 operator *(const matrix3x3 &,const matrix3x3 &); 00282 00284 friend OBAPI std::ostream& operator<< ( std::ostream&, const matrix3x3 & ) ; 00285 00287 static void jacobi(unsigned int n, double *a, double *d, double *v); 00288 }; 00289 00290 #ifndef SWIG 00291 OBAPI vector3 center_coords(double*,int); 00292 #endif 00293 } 00294 00295 #endif // OB_MATRIX3x3_H 00296
This file is part of the documentation for Open Babel, version 2.3.