00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "Matrix.h"
00010 #include "Common.h"
00011
00012 RotationMatrix& RotationMatrix::fromKardanRPY
00013 (const double yaw, const double pitch, const double roll){
00014
00015 double cy=cos(yaw);
00016 double sy=sin(yaw);
00017 double cp=cos(pitch);
00018 double sp=sin(pitch);
00019 double cr=cos(roll);
00020 double sr=sin(roll);
00021
00022 c[0].x=cr*cp ;
00023 c[0].y=-sr*cy+cr*sp*sy ;
00024 c[0].z=sr*sy+cr*sp*cy ;
00025 c[1].x=sr*cp ;
00026 c[1].y=cr*cy+sr*sp*sy ;
00027 c[1].z=-cr*sy+sr*sp*cy ;
00028 c[2].x=-sp ;
00029 c[2].y=cp*sy ;
00030 c[2].z=cp*cy ;
00031
00032 return *this;
00033 }
00034
00035 RotationMatrix& RotationMatrix::rotateX(const double angle)
00036 {
00037 double c = cos(angle),
00038 s = sin(angle);
00039 *this *= RotationMatrix(Vector3<double>(1,0,0),
00040 Vector3<double>(0,c,s),
00041 Vector3<double>(0,-s,c));
00042 return *this;
00043 }
00044
00045 RotationMatrix& RotationMatrix::rotateY(const double angle)
00046 {
00047 double c = cos(angle),
00048 s = sin(angle);
00049 *this *= RotationMatrix(Vector3<double>(c,0,-s),
00050 Vector3<double>(0,1,0),
00051 Vector3<double>(s,0,c));
00052 return *this;
00053 }
00054
00055 RotationMatrix& RotationMatrix::rotateZ(const double angle)
00056 {
00057 double c = cos(angle),
00058 s = sin(angle);
00059 *this *= RotationMatrix(Vector3<double>(c,s,0),
00060 Vector3<double>(-s,c,0),
00061 Vector3<double>(0,0,1));
00062 return *this;
00063 }
00064
00065 double RotationMatrix::getXAngle() const
00066 {
00067 double h = sqrt(c[2].y * c[2].y + c[2].z * c[2].z);
00068 return h ? acos(c[2].z / h) * (c[2].y > 0 ? -1 : 1) : 0;
00069 }
00070
00071 double RotationMatrix::getYAngle() const
00072 {
00073 double h = sqrt(c[0].x * c[0].x + c[0].z * c[0].z);
00074 return h ? acos(c[0].x / h) * (c[0].z > 0 ? -1 : 1) : 0;
00075 }
00076
00077 double RotationMatrix::getZAngle() const
00078 {
00079 double h = sqrt(c[0].x * c[0].x + c[0].y * c[0].y);
00080 return h ? acos(c[0].x / h) * (c[0].y < 0 ? -1 : 1) : 0;
00081 }
00082
00083 template <class V> In& operator>>(In& stream, Matrix3x3<V>& matrix3x3)
00084 {
00085 stream >> matrix3x3.c[0];
00086 stream >> matrix3x3.c[1];
00087 stream >> matrix3x3.c[2];
00088 return stream;
00089 }
00090
00091 template <class V> Out& operator<<(Out& stream, const Matrix3x3<V>& matrix3x3)
00092 {
00093 stream << matrix3x3.c[0];
00094 stream << matrix3x3.c[1];
00095 stream << matrix3x3.c[2];
00096 return stream;
00097 }
00098
00099 In& operator>>(In& stream, RotationMatrix& rotationMatrix)
00100 {
00101 stream >> rotationMatrix.c[0];
00102 stream >> rotationMatrix.c[1];
00103 stream >> rotationMatrix.c[2];
00104 return stream;
00105 }
00106
00107 Out& operator<<(Out& stream, const RotationMatrix& rotationMatrix)
00108 {
00109 stream << rotationMatrix.c[0];
00110 stream << rotationMatrix.c[1];
00111 stream << rotationMatrix.c[2];
00112 return stream;
00113 }
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148