00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef OB_MATRIX3x3_H
00021 #define OB_MATRIX3x3_H
00022
00023 #include "oberror.h"
00024
00025 #if HAVE_IOSTREAM
00026 #include <iostream>
00027 #elif HAVE_IOSTREAM_H
00028 #include <iostream.h>
00029 #endif
00030
00031 #if HAVE_FSTREAM
00032 #include <fstream>
00033 #elif HAVE_FSTREAM_H
00034 #include <fstream.h>
00035 #endif
00036
00037 #include <math.h>
00038
00039 #include "obutil.h"
00040 #include "math/vector3.h"
00041
00042 #ifndef PI
00043 #define PI 3.1415926535897932384626433
00044 #endif
00045
00046 #ifndef RAD_TO_DEG
00047 #define RAD_TO_DEG 180.0/PI
00048 #endif
00049
00050 #ifndef DEG_TO_RAD
00051 #define DEG_TO_RAD PI/180.0
00052 #endif
00053
00054 namespace OpenBabel
00055 {
00056
00057
00058 class OBAPI matrix3x3
00059 {
00061
00063 double ele[3][3];
00064
00065 public:
00067 matrix3x3(void)
00068 {
00069 ele[0][0] = 0.0;
00070 ele[0][1] = 0.0;
00071 ele[0][2] = 0.0;
00072 ele[1][0] = 0.0;
00073 ele[1][1] = 0.0;
00074 ele[1][2] = 0.0;
00075 ele[2][0] = 0.0;
00076 ele[2][1] = 0.0;
00077 ele[2][2] = 0.0;
00078 }
00079
00081 matrix3x3(double s)
00082 {
00083 ele[0][0] = s;
00084 ele[0][1] = 0.0;
00085 ele[0][2] = 0.0;
00086 ele[1][0] = 0.0;
00087 ele[1][1] = s;
00088 ele[1][2] = 0.0;
00089 ele[2][0] = 0.0;
00090 ele[2][1] = 0.0;
00091 ele[2][2] = s;
00092 }
00093
00095 matrix3x3(vector3 row1,vector3 row2,vector3 row3)
00096 {
00097 ele[0][0] = row1.x();
00098 ele[0][1] = row1.y();
00099 ele[0][2] = row1.z();
00100 ele[1][0] = row2.x();
00101 ele[1][1] = row2.y();
00102 ele[1][2] = row2.z();
00103 ele[2][0] = row3.x();
00104 ele[2][1] = row3.y();
00105 ele[2][2] = row3.z();
00106 }
00107
00109
00111 matrix3x3(double d[3][3])
00112 {
00113 ele[0][0] = d[0][0];
00114 ele[0][1] = d[0][1];
00115 ele[0][2] = d[0][2];
00116 ele[1][0] = d[1][0];
00117 ele[1][1] = d[1][1];
00118 ele[1][2] = d[1][2];
00119 ele[2][0] = d[2][0];
00120 ele[2][1] = d[2][1];
00121 ele[2][2] = d[2][2];
00122 }
00123
00125
00128 void GetArray(double *m)
00129 {
00130 m[0] = ele[0][0];
00131 m[1] = ele[0][1];
00132 m[2] = ele[0][2];
00133 m[3] = ele[1][0];
00134 m[4] = ele[1][1];
00135 m[5] = ele[1][2];
00136 m[6] = ele[2][0];
00137 m[7] = ele[2][1];
00138 m[8] = ele[2][2];
00139 }
00140
00142 matrix3x3 inverse(void) const throw(OBError);
00143
00145 matrix3x3 transpose(void) const;
00146
00148 void randomRotation(OBRandom &rnd);
00149
00151 double determinant() const;
00152
00154 bool isSymmetric(void) const;
00155
00157
00169 bool isOrthogonal(void) const
00170 {
00171 return (*this * transpose()).isUnitMatrix();
00172 };
00173
00175 bool isDiagonal(void) const;
00176
00178 bool isUnitMatrix(void) const;
00179
00181
00187 double Get(int row,int column) const
00188 {
00189 if (row >= 0 && row <= 2 && column >= 0 && column <= 2)
00190 return(ele[row][column]);
00191 else
00192 return 0.0f;
00193 }
00194
00196
00202 void Set(int row,int column, double v)
00203 {
00204 if (row >= 0 && row <= 2 && column >= 0 && column <= 2)
00205 ele[row][column]= v;
00206 }
00207
00209
00211 void SetColumn(int column, const vector3 &v) throw(OBError);
00212
00214
00216 void SetRow(int row, const vector3 &v) throw(OBError);
00217
00219
00221 vector3 GetColumn(unsigned int col) const throw(OBError);
00222
00224
00226 vector3 GetRow(unsigned int row) const throw(OBError);
00227
00228
00230 matrix3x3 &operator/=(const double &c);
00231
00232 void SetupRotMat(double,double,double);
00233
00235 void PlaneReflection(const vector3 &norm);
00236
00238 void RotAboutAxisByAngle(const vector3 &axis, const double angle);
00239
00240 void FillOrth(double,double,double,double,double,double);
00241
00243 matrix3x3 findEigenvectorsIfSymmetric(vector3 &eigenvals) const throw(OBError);
00244
00246 friend OBAPI vector3 operator *(const matrix3x3 &,const vector3 &);
00247
00249 friend OBAPI matrix3x3 operator *(const matrix3x3 &,const matrix3x3 &);
00250
00251 friend OBAPI std::ostream& operator<< ( std::ostream&, const matrix3x3 & ) ;
00252
00254 static void jacobi(unsigned int n, double *a, double *d, double *v);
00255 };
00256
00257 OBAPI vector3 center_coords(double*,int);
00258 }
00259
00260 #endif // OB_MATRIX3x3_H
00261