File indexing completed on 2025-04-19 09:06:46
0001 #ifndef RIVET_MATH_MATRIX3
0002 #define RIVET_MATH_MATRIX3
0003
0004 #include "Rivet/Math/MathConstants.hh"
0005 #include "Rivet/Math/MathUtils.hh"
0006 #include "Rivet/Math/MatrixN.hh"
0007 #include "Rivet/Math/Vector3.hh"
0008
0009 namespace Rivet {
0010
0011
0012
0013 class Matrix3 : public Matrix<3> {
0014 public:
0015 Matrix3() = default;
0016
0017 Matrix3(const Matrix<3>& m3) : Matrix<3>::Matrix(m3) { }
0018
0019 Matrix3(const Vector3& axis, const double angle) {
0020 const Vector3 normaxis = axis.unit();
0021 _matrix = RivetEigen::AngleAxis<double>(angle, normaxis._vec);
0022 }
0023
0024 Matrix3(const Vector3& from, const Vector3& to) {
0025 setAsRotation(from, to);
0026 }
0027
0028 static Matrix3 mkXRotation(const double angle) {
0029 return Matrix3(Vector3(1,0,0), angle);
0030 }
0031
0032 static Matrix3 mkYRotation(const double angle) {
0033 return Matrix3(Vector3(0,1,0), angle);
0034 }
0035
0036 static Matrix3 mkZRotation(const double angle) {
0037 return Matrix3(Vector3(0,0,1), angle);
0038 }
0039
0040 Matrix3& setAsRotation(const Vector3& from, const Vector3& to) {
0041 const double theta = angle(from, to);
0042 if (Rivet::isZero(theta)) {
0043 _matrix = EMatrix::Identity();
0044 } else {
0045 const Vector3 normaxis = cross(from, to).unit();
0046 _matrix = RivetEigen::AngleAxis<double>(theta, normaxis._vec);
0047 }
0048 return *this;
0049 }
0050
0051 static Matrix3 mkRotation(const Vector3& from, const Vector3& to) {
0052 Matrix3 rtn;
0053 rtn.setAsRotation(from, to);
0054 return rtn;
0055 }
0056
0057 };
0058
0059
0060 }
0061
0062 #endif