Rivet API documentation

Rivet 4.1.3
Matrix3.hh
1#ifndef RIVET_MATH_MATRIX3
2#define RIVET_MATH_MATRIX3
3
4#include "Rivet/Math/MathConstants.hh"
5#include "Rivet/Math/MathUtils.hh"
6#include "Rivet/Math/MatrixN.hh"
7#include "Rivet/Math/Vector3.hh"
8
9namespace Rivet {
10
11
13 class Matrix3 : public Matrix<3> {
14 public:
15
16 Matrix3() = default;
17
18 Matrix3(const Matrix<3>& m3)
19 : Matrix<3>::Matrix(m3) { }
20
21 Matrix3(const Vector3& axis, const double angle) {
22 const Vector3 normaxis = axis.unit();
23 _matrix = RivetEigen::AngleAxis<double>(angle, normaxis._vec);
24 }
25
26 Matrix3(const Vector3& from, const Vector3& to) {
27 setAsRotation(from, to);
28 }
29
30 static Matrix3 mkXRotation(const double angle) {
31 return Matrix3(Vector3(1, 0, 0), angle);
32 }
33
34 static Matrix3 mkYRotation(const double angle) {
35 return Matrix3(Vector3(0, 1, 0), angle);
36 }
37
38 static Matrix3 mkZRotation(const double angle) {
39 return Matrix3(Vector3(0, 0, 1), angle);
40 }
41
42 Matrix3& setAsRotation(const Vector3& from, const Vector3& to) {
43 const double theta = angle(from, to);
44 if (Rivet::isZero(theta)) {
45 _matrix = EMatrix::Identity();
46 }
47 else {
48 const Vector3 normaxis = cross(from, to).unit();
49 _matrix = RivetEigen::AngleAxis<double>(theta, normaxis._vec);
50 }
51 return *this;
52 }
53
54 static Matrix3 mkRotation(const Vector3& from, const Vector3& to) {
55 Matrix3 rtn;
56 rtn.setAsRotation(from, to);
57 return rtn;
58 }
59 };
60
61
62}
63
64#endif
Three-dimensional specialisation of Vector.
Definition Vector3.hh:39
Vector3 unit() const
Synonym for unitVec.
Definition Vector3.hh:154
Definition LHCbCommon.hh:9
std::enable_if_t< std::is_floating_point_v< NUM >, bool > isZero(NUM val, double tolerance=1e-8)
Compare a number to zero.
Definition MathUtils.hh:23
Vector3 cross(const Vector3 &a, const Vector3 &b)
Unbound cross-product function.
Definition Vector3.hh:310
double angle(const Vector2 &a, const Vector2 &b)
Angle (in radians) between two 2-vectors.
Definition Vector2.hh:194