Matrix3.hh

Go to the documentation of this file.
00001 #ifndef RIVET_MATH_MATRIX3
00002 #define RIVET_MATH_MATRIX3
00003 
00004 #include "Rivet/Math/MathHeader.hh"
00005 #include "Rivet/Math/MathUtils.hh"
00006 #include "Rivet/Math/MatrixN.hh"
00007 #include "Rivet/Math/Vector3.hh"
00008 
00009 namespace Rivet {
00010 
00011 
00012 class Matrix3 : public Matrix<3> {
00013 public:
00014   Matrix3() { }
00015 
00016   Matrix3(const Matrix<3>& m3) :  Matrix<3>::Matrix<3>(m3) { }
00017 
00018   Matrix3(const Vector3& axis, const double angle) {
00019     const Vector3 normaxis = axis.unit();
00020     _matrix.loadRotation3(angle, normaxis._vec);
00021   }
00022 
00023   Matrix3(const Vector3& from, const Vector3& to) {
00024     setAsRotation(from, to);
00025   }
00026 
00027 public:
00028   static Matrix3 mkXRotation(const double angle) {
00029     return Matrix3(Vector3(1,0,0), angle);
00030   }
00031 
00032   static Matrix3 mkYRotation(const double angle) {
00033     return Matrix3(Vector3(0,1,0), angle);
00034   }
00035 
00036   static Matrix3 mkZRotation(const double angle) {
00037     return Matrix3(Vector3(0,0,1), angle);
00038   }
00039 
00040 public:
00041   Matrix3& setAsRotation(const Vector3& from, const Vector3& to) {
00042     const double theta = angle(from, to);
00043     if (Rivet::isZero(theta)) {
00044       _matrix.loadIdentity();
00045     } else {
00046       const Vector3 normaxis = cross(from, to).unit();
00047       _matrix.loadRotation3(theta, normaxis._vec);
00048     }
00049     return *this;
00050   }
00051 
00052 };
00053 
00054 
00055 }
00056 
00057 #endif