Rivet: /Users/chrisg/software/rivet/include/Rivet/Math/Matrix3.hh Source File

| Rivet 3.1.9

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 Matrix3() = default;
16
17 Matrix3(const Matrix<3>& m3) : Matrix<3>::Matrix(m3) { }
18
19 Matrix3(const Vector3& axis, const double angle) {
20 const Vector3 normaxis = axis.unit();
21 _matrix = RivetEigen::AngleAxis<double>(angle, normaxis._vec);
22 }
23
24 Matrix3(const Vector3& from, const Vector3& to) {
25 setAsRotation(from, to);
26 }
27
28 static Matrix3 mkXRotation(const double angle) {
29 return Matrix3(Vector3(1,0,0), angle);
30 }
31
32 static Matrix3 mkYRotation(const double angle) {
33 return Matrix3(Vector3(0,1,0), angle);
34 }
35
36 static Matrix3 mkZRotation(const double angle) {
37 return Matrix3(Vector3(0,0,1), angle);
38 }
39
40 Matrix3& setAsRotation(const Vector3& from, const Vector3& to) {
41 const double theta = angle(from, to);
42 if (Rivet::isZero(theta)) {
43 _matrix = EMatrix::Identity();
44 } else {
45 const Vector3 normaxis = cross(from, to).unit();
46 _matrix = RivetEigen::AngleAxis<double>(theta, normaxis._vec);
47 }
48 return *this;
49 }
50
51 static Matrix3 mkRotation(const Vector3& from, const Vector3& to) {
52 Matrix3 rtn;
53 rtn.setAsRotation(from, to);
54 return rtn;
55 }
56
57 };
58
59
60}
61
62#endif
Rivet::Matrix3
Specialisation of MatrixN to aid 3 dimensional rotations.
Definition Matrix3.hh:13
Rivet::Matrix
General -dimensional mathematical matrix object.
Definition MatrixN.hh:30
Rivet::Vector3
Three-dimensional specialisation of Vector.
Definition Vector3.hh:40
Rivet::Vector3::unit
Vector3 unit() const
Synonym for unitVec.
Definition Vector3.hh:124
Rivet
Definition MC_Cent_pPb.hh:10
Rivet::cross
Vector3 cross(const Vector3 &a, const Vector3 &b)
Unbound cross-product function.
Definition Vector3.hh:272
Rivet::isZero
std::enable_if< std::is_floating_point< NUM >::value, bool >::type isZero(NUM val, double tolerance=1e-8)
Compare a number to zero.
Definition MathUtils.hh:24
Rivet::angle
double angle(const Vector2 &a, const Vector2 &b)
Angle (in radians) between two 2-vectors.
Definition Vector2.hh:177