Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Tools/Math/Matrix.cpp

Go to the documentation of this file.
00001 /**
00002  * @file Matrix.cpp
00003  * Implements RotationMatrix
00004  *
00005  * @author <a href="mailto:martin.kallnik@gmx.de" > Martin Kallnik</a>
00006  * @author Max Risler
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 * Change log :
00118 * 
00119 * $Log: Matrix.cpp,v $
00120 * Revision 1.1.1.1  2004/05/22 17:37:11  cvsadm
00121 * created new repository GT2004_WM
00122 *
00123 * Revision 1.2  2003/12/02 13:44:55  cesarz
00124 * added streaming operators
00125 *
00126 * Revision 1.1  2003/10/07 10:13:24  cvsadm
00127 * Created GT2004 (M.J.)
00128 *
00129 * Revision 1.1.1.1  2003/07/02 09:40:28  cvsadm
00130 * created new repository for the competitions in Padova from the 
00131 * tamara CVS (Tuesday 2:00 pm)
00132 *
00133 * removed unused solutions
00134 *
00135 * Revision 1.4  2002/11/19 15:43:04  dueffert
00136 * doxygen comments corrected
00137 *
00138 * Revision 1.3  2002/11/12 23:00:47  dueffert
00139 * started restore greenhills compatibility
00140 *
00141 * Revision 1.2  2002/09/22 18:40:52  risler
00142 * added new math functions, removed GTMath library
00143 *
00144 * Revision 1.1  2002/09/22 13:10:50  risler
00145 * new Math headers added
00146 *
00147 *
00148 */

Generated on Thu Sep 23 19:57:39 2004 for GT2004 by doxygen 1.3.6