BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
RotMatrix.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Base/Vector/RotMatrix.h
6 //! @brief Declares class RotMatrix.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_BASE_VECTOR_ROTMATRIX_H
16 #define BORNAGAIN_BASE_VECTOR_ROTMATRIX_H
17 
18 #include <array>
19 #include <heinz/Vectors3D.h>
20 #include <optional>
21 
22 //! Rotation matrix in three dimensions. Represents group SO(3).
23 //! Internal parameterization based on quaternions.
24 
25 class RotMatrix {
26 public:
27  //! Constructs unit transformation
28  RotMatrix();
29 
30  //! Destructor
31  ~RotMatrix() = default;
32 
33  //! Creates rotation around x-axis
34  static RotMatrix AroundX(double phi);
35 
36  //! Creates rotation around y-axis
37  static RotMatrix AroundY(double phi);
38 
39  //! Creates rotation around z-axis
40  static RotMatrix AroundZ(double phi);
41 
42  //! Creates rotation defined by Euler angles
43  static RotMatrix EulerZXZ(double alpha, double beta, double gamma);
44 
45  //! Calculates the Euler angles corresponding to the rotation
46  std::array<double, 3> zxzEulerAngles() const;
47 
48  //! Returns the inverse transformation.
49  RotMatrix Inverse() const;
50 
51  //! Return transformed vector _v_.
52  template <class T>
53  T transformed(const T& v) const;
54 
55  //! Return transformed vector _v_.
56  template <class T>
57  T counterTransformed(const T& v) const;
58 
59  //! Composes two transformations
60  RotMatrix operator*(const RotMatrix&) const;
61 
62  //! Provides equality operator
63  bool operator==(const RotMatrix&) const;
64 
65  //! Determine if the transformation is trivial (identity)
66  bool isIdentity() const;
67 
68  bool isXRotation() const;
69  bool isYRotation() const;
70  bool isZRotation() const;
71 
72  std::optional<double> angleAroundCoordAxis(int iAxis) const;
73 
74 private:
75  RotMatrix(double x_, double y_, double z_, double s_);
76 
77  double x, y, z, s;
78 };
79 
80 #endif // BORNAGAIN_BASE_VECTOR_ROTMATRIX_H
Rotation matrix in three dimensions. Represents group SO(3). Internal parameterization based on quate...
Definition: RotMatrix.h:25
double y
Definition: RotMatrix.h:77
T counterTransformed(const T &v) const
Return transformed vector v.
Definition: RotMatrix.cpp:92
RotMatrix()
Constructs unit transformation.
Definition: RotMatrix.cpp:25
static RotMatrix EulerZXZ(double alpha, double beta, double gamma)
Creates rotation defined by Euler angles.
Definition: RotMatrix.cpp:45
static RotMatrix AroundZ(double phi)
Creates rotation around z-axis.
Definition: RotMatrix.cpp:40
static RotMatrix AroundY(double phi)
Creates rotation around y-axis.
Definition: RotMatrix.cpp:35
RotMatrix operator*(const RotMatrix &) const
Composes two transformations.
Definition: RotMatrix.cpp:100
static RotMatrix AroundX(double phi)
Creates rotation around x-axis.
Definition: RotMatrix.cpp:30
bool isIdentity() const
Determine if the transformation is trivial (identity)
Definition: RotMatrix.cpp:111
~RotMatrix()=default
Destructor.
RotMatrix Inverse() const
Returns the inverse transformation.
Definition: RotMatrix.cpp:70
bool isZRotation() const
Definition: RotMatrix.cpp:126
std::optional< double > angleAroundCoordAxis(int iAxis) const
Definition: RotMatrix.cpp:131
bool isXRotation() const
Definition: RotMatrix.cpp:116
double x
Definition: RotMatrix.h:77
double s
Definition: RotMatrix.h:77
double z
Definition: RotMatrix.h:77
std::array< double, 3 > zxzEulerAngles() const
Calculates the Euler angles corresponding to the rotation.
Definition: RotMatrix.cpp:53
T transformed(const T &v) const
Return transformed vector v.
Definition: RotMatrix.cpp:76
bool operator==(const RotMatrix &) const
Provides equality operator.
Definition: RotMatrix.cpp:106
bool isYRotation() const
Definition: RotMatrix.cpp:121
double beta(double z, double w)
double gamma(double x)