rotmatrix.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef PLANCK_ROTMATRIX_H
00035 #define PLANCK_ROTMATRIX_H
00036
00037 #include <iostream>
00038 #include "cxxutils.h"
00039 #include "vec3.h"
00040
00041
00042
00043
00044
00045 class rotmatrix
00046 {
00047 public:
00048 double entry[3][3];
00049
00050 rotmatrix () {}
00051
00052
00053 rotmatrix (double a00, double a01, double a02,
00054 double a10, double a11, double a12,
00055 double a20, double a21, double a22)
00056 {
00057 entry[0][0]=a00; entry[0][1]=a01; entry[0][2]=a02;
00058 entry[1][0]=a10; entry[1][1]=a11; entry[1][2]=a12;
00059 entry[2][0]=a20; entry[2][1]=a21; entry[2][2]=a22;
00060 }
00061
00062
00063
00064
00065
00066 rotmatrix (const vec3 &a, const vec3 &b, const vec3 &c);
00067
00068
00069 void SetToIdentity ();
00070
00071 void SetToZero ();
00072
00073 void Transpose ();
00074
00075
00076
00077 void toAxisAngle (vec3 &axis, double &angle) const;
00078
00079
00080
00081 void Make_Axis_Rotation_Transform (const vec3 &axis, double angle)
00082 {
00083 double sa=sin(angle), ca=cos(angle);
00084 double ica=1-ca;
00085 entry[0][0] = axis.x*axis.x*ica + ca;
00086 entry[1][1] = axis.y*axis.y*ica + ca;
00087 entry[2][2] = axis.z*axis.z*ica + ca;
00088 double t1 = axis.x*axis.y*ica, t2 = axis.z*sa;
00089 entry[1][0] = t1 + t2;
00090 entry[0][1] = t1 - t2;
00091 t1 = axis.x*axis.z*ica; t2 = axis.y*sa;
00092 entry[2][0] = t1 - t2;
00093 entry[0][2] = t1 + t2;
00094 t1 = axis.y*axis.z*ica; t2 = axis.x*sa;
00095 entry[1][2] = t1 - t2;
00096 entry[2][1] = t1 + t2;
00097 }
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 void Make_CPAC_Euler_Matrix (double alpha, double beta, double gamma);
00111
00112
00113
00114
00115
00116 void Extract_CPAC_Euler_Angles
00117 (double &alpha, double &beta, double &gamma) const;
00118
00119
00120 vec3 Transform (const vec3 &vec) const
00121 {
00122 return vec3
00123 (vec.x*entry[0][0] + vec.y*entry[0][1] + vec.z*entry[0][2],
00124 vec.x*entry[1][0] + vec.y*entry[1][1] + vec.z*entry[1][2],
00125 vec.x*entry[2][0] + vec.y*entry[2][1] + vec.z*entry[2][2]);
00126 }
00127
00128 void Transform (const vec3 &vec, vec3 &vec2) const
00129 {
00130 vec2.x = vec.x*entry[0][0] + vec.y*entry[0][1] + vec.z*entry[0][2];
00131 vec2.y = vec.x*entry[1][0] + vec.y*entry[1][1] + vec.z*entry[1][2];
00132 vec2.z = vec.x*entry[2][0] + vec.y*entry[2][1] + vec.z*entry[2][2];
00133 }
00134 };
00135
00136
00137
00138 rotmatrix operator* (const rotmatrix &a, const rotmatrix &b);
00139
00140
00141 inline void matmult (const rotmatrix &a, const rotmatrix &b, rotmatrix &res)
00142 {
00143 for (int i=0; i<3; ++i)
00144 for (int j=0; j<3; ++j)
00145 res.entry[i][j] = a.entry[i][0] * b.entry[0][j]
00146 + a.entry[i][1] * b.entry[1][j]
00147 + a.entry[i][2] * b.entry[2][j];
00148 }
00149
00150
00151
00152 void TransposeTimes (const rotmatrix &a, const rotmatrix &b, rotmatrix &res);
00153
00154
00155
00156 std::ostream &operator<< (std::ostream &os, const rotmatrix &mat);
00157
00158
00159
00160 #endif