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 /// @brief Specialisation of MatrixN to aid 3 dimensional rotations. 00013 class Matrix3 : public Matrix<3> { 00014 public: 00015 Matrix3() { } 00016 00017 Matrix3(const Matrix<3>& m3) : Matrix<3>::Matrix(m3) { } 00018 00019 Matrix3(const Vector3& axis, const double angle) { 00020 const Vector3 normaxis = axis.unit(); 00021 _matrix.loadRotation3(angle, normaxis._vec); 00022 } 00023 00024 Matrix3(const Vector3& from, const Vector3& to) { 00025 setAsRotation(from, to); 00026 } 00027 00028 public: 00029 static Matrix3 mkXRotation(const double angle) { 00030 return Matrix3(Vector3(1,0,0), angle); 00031 } 00032 00033 static Matrix3 mkYRotation(const double angle) { 00034 return Matrix3(Vector3(0,1,0), angle); 00035 } 00036 00037 static Matrix3 mkZRotation(const double angle) { 00038 return Matrix3(Vector3(0,0,1), angle); 00039 } 00040 00041 public: 00042 Matrix3& setAsRotation(const Vector3& from, const Vector3& to) { 00043 const double theta = angle(from, to); 00044 if (Rivet::isZero(theta)) { 00045 _matrix.loadIdentity(); 00046 } else { 00047 const Vector3 normaxis = cross(from, to).unit(); 00048 _matrix.loadRotation3(theta, normaxis._vec); 00049 } 00050 return *this; 00051 } 00052 00053 }; 00054 00055 00056 } 00057 00058 #endif Generated on Thu Feb 6 2014 17:38:45 for The Rivet MC analysis system by ![]() |