BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
RotMatrix Class Reference

Description

Rotation matrix in three dimensions. Represents group SO(3). Internal parameterization based on quaternions.

Definition at line 25 of file RotMatrix.h.

Public Member Functions

 RotMatrix ()
 Constructs unit transformation. More...
 
 ~RotMatrix ()=default
 Destructor. More...
 
std::optional< double > angleAroundCoordAxis (int iAxis) const
 
template<class T >
counterTransformed (const T &v) const
 Return transformed vector v. More...
 
RotMatrix Inverse () const
 Returns the inverse transformation. More...
 
bool isIdentity () const
 Determine if the transformation is trivial (identity) More...
 
bool isXRotation () const
 
bool isYRotation () const
 
bool isZRotation () const
 
RotMatrix operator* (const RotMatrix &) const
 Composes two transformations. More...
 
bool operator== (const RotMatrix &) const
 Provides equality operator. More...
 
template<class T >
transformed (const T &v) const
 Return transformed vector v. More...
 
std::array< double, 3 > zxzEulerAngles () const
 Calculates the Euler angles corresponding to the rotation. More...
 

Static Public Member Functions

static RotMatrix AroundX (double phi)
 Creates rotation around x-axis. More...
 
static RotMatrix AroundY (double phi)
 Creates rotation around y-axis. More...
 
static RotMatrix AroundZ (double phi)
 Creates rotation around z-axis. More...
 
static RotMatrix EulerZXZ (double alpha, double beta, double gamma)
 Creates rotation defined by Euler angles. More...
 

Private Member Functions

 RotMatrix (double x_, double y_, double z_, double s_)
 

Private Attributes

double s
 
double x
 
double y
 
double z
 

Constructor & Destructor Documentation

◆ RotMatrix() [1/2]

RotMatrix::RotMatrix ( )

Constructs unit transformation.

Definition at line 25 of file RotMatrix.cpp.

26  : RotMatrix(0, 0, 0, 1)
27 {
28 }
RotMatrix()
Constructs unit transformation.
Definition: RotMatrix.cpp:25

◆ ~RotMatrix()

RotMatrix::~RotMatrix ( )
default

Destructor.

◆ RotMatrix() [2/2]

RotMatrix::RotMatrix ( double  x_,
double  y_,
double  z_,
double  s_ 
)
private

Definition at line 17 of file RotMatrix.cpp.

18  : x(x_)
19  , y(y_)
20  , z(z_)
21  , s(s_)
22 {
23 }
double y
Definition: RotMatrix.h:77
double x
Definition: RotMatrix.h:77
double s
Definition: RotMatrix.h:77
double z
Definition: RotMatrix.h:77

Member Function Documentation

◆ angleAroundCoordAxis()

std::optional< double > RotMatrix::angleAroundCoordAxis ( int  iAxis) const

Definition at line 131 of file RotMatrix.cpp.

132 {
133  if (iAxis == 0 && isXRotation())
134  return 2 * atan2(x, s);
135  if (iAxis == 1 && isYRotation())
136  return 2 * atan2(y, s);
137  if (iAxis == 2 && isZRotation())
138  return 2 * atan2(z, s);
139  return {};
140 }
bool isZRotation() const
Definition: RotMatrix.cpp:126
bool isXRotation() const
Definition: RotMatrix.cpp:116
bool isYRotation() const
Definition: RotMatrix.cpp:121

References isXRotation(), isYRotation(), isZRotation(), s, x, y, and z.

Referenced by IRotation::createRotation().

Here is the call graph for this function:

◆ AroundX()

RotMatrix RotMatrix::AroundX ( double  phi)
static

Creates rotation around x-axis.

Definition at line 30 of file RotMatrix.cpp.

31 {
32  return {sin(phi / 2), 0, 0, cos(phi / 2)};
33 }

Referenced by EulerZXZ(), and RotationX::rotMatrix().

◆ AroundY()

RotMatrix RotMatrix::AroundY ( double  phi)
static

Creates rotation around y-axis.

Definition at line 35 of file RotMatrix.cpp.

36 {
37  return {0, sin(phi / 2), 0, cos(phi / 2)};
38 }

Referenced by RotationY::rotMatrix().

◆ AroundZ()

RotMatrix RotMatrix::AroundZ ( double  phi)
static

Creates rotation around z-axis.

Definition at line 40 of file RotMatrix.cpp.

41 {
42  return {0, 0, sin(phi / 2), cos(phi / 2)};
43 }

Referenced by EulerZXZ(), and RotationZ::rotMatrix().

◆ counterTransformed()

template<class T >
template C3 RotMatrix::counterTransformed< C3 > ( const T &  v) const

Return transformed vector v.

Definition at line 92 of file RotMatrix.cpp.

93 {
94  return Inverse().transformed(v);
95 }
RotMatrix Inverse() const
Returns the inverse transformation.
Definition: RotMatrix.cpp:70
T transformed(const T &v) const
Return transformed vector v.
Definition: RotMatrix.cpp:76

References Inverse(), and transformed().

Here is the call graph for this function:

◆ EulerZXZ()

RotMatrix RotMatrix::EulerZXZ ( double  alpha,
double  beta,
double  gamma 
)
static

Creates rotation defined by Euler angles.

Definition at line 45 of file RotMatrix.cpp.

46 {
47  RotMatrix zrot = AroundZ(alpha);
48  RotMatrix xrot = AroundX(beta);
49  RotMatrix zrot2 = AroundZ(gamma);
50  return zrot * xrot * zrot2;
51 }
Rotation matrix in three dimensions. Represents group SO(3). Internal parameterization based on quate...
Definition: RotMatrix.h:25
static RotMatrix AroundZ(double phi)
Creates rotation around z-axis.
Definition: RotMatrix.cpp:40
static RotMatrix AroundX(double phi)
Creates rotation around x-axis.
Definition: RotMatrix.cpp:30
double beta(double z, double w)
double gamma(double x)

References AroundX(), AroundZ(), ROOT::Math::Cephes::beta(), and ROOT::Math::Cephes::gamma().

Referenced by RotationEuler::rotMatrix().

Here is the call graph for this function:

◆ Inverse()

RotMatrix RotMatrix::Inverse ( ) const

Returns the inverse transformation.

Definition at line 70 of file RotMatrix.cpp.

71 {
72  return {-x, -y, -z, s};
73 }

References s, x, y, and z.

Referenced by counterTransformed().

◆ isIdentity()

bool RotMatrix::isIdentity ( ) const

Determine if the transformation is trivial (identity)

Definition at line 111 of file RotMatrix.cpp.

112 {
113  return x == 0 && y == 0 && z == 0;
114 }

References x, y, and z.

Referenced by IRotation::createRotation(), and IRotation::isIdentity().

◆ isXRotation()

bool RotMatrix::isXRotation ( ) const

Definition at line 116 of file RotMatrix.cpp.

117 {
118  return y == 0 && z == 0;
119 }

References y, and z.

Referenced by angleAroundCoordAxis().

◆ isYRotation()

bool RotMatrix::isYRotation ( ) const

Definition at line 121 of file RotMatrix.cpp.

122 {
123  return z == 0 && x == 0;
124 }

References x, and z.

Referenced by angleAroundCoordAxis().

◆ isZRotation()

bool RotMatrix::isZRotation ( ) const

Definition at line 126 of file RotMatrix.cpp.

127 {
128  return x == 0 && y == 0;
129 }

References x, and y.

Referenced by angleAroundCoordAxis(), and IRotation::zInvariant().

◆ operator*()

RotMatrix RotMatrix::operator* ( const RotMatrix o) const

Composes two transformations.

Definition at line 100 of file RotMatrix.cpp.

101 {
102  return {s * o.x + x * o.s + y * o.z - z * o.y, s * o.y + y * o.s + z * o.x - x * o.z,
103  s * o.z + z * o.s + x * o.y - y * o.x, s * o.s - x * o.x - y * o.y - z * o.z};
104 }

References s, x, y, and z.

◆ operator==()

bool RotMatrix::operator== ( const RotMatrix o) const

Provides equality operator.

Definition at line 106 of file RotMatrix.cpp.

107 {
108  return x == o.x && y == o.y && z == o.z && s == o.s;
109 }

References s, x, y, and z.

◆ transformed()

template<class T >
template C3 RotMatrix::transformed< C3 > ( const T &  v) const

Return transformed vector v.

Definition at line 76 of file RotMatrix.cpp.

77 {
78  auto xf = (-1 + 2 * x * x + 2 * s * s) * v.x() + 2 * (x * y - z * s) * v.y()
79  + 2 * (x * z + y * s) * v.z();
80  auto yf = (-1 + 2 * y * y + 2 * s * s) * v.y() + 2 * (y * z - x * s) * v.z()
81  + 2 * (y * x + z * s) * v.x();
82  auto zf = (-1 + 2 * z * z + 2 * s * s) * v.z() + 2 * (z * x - y * s) * v.x()
83  + 2 * (z * y + x * s) * v.y();
84 
85  return T(xf, yf, zf);
86 }

References s, x, y, and z.

Referenced by counterTransformed(), Lattice3D::rotated(), MagneticMaterialImpl::rotatedMaterial(), IRotation::transformed(), and WavevectorInfo::transformed().

◆ zxzEulerAngles()

std::array< double, 3 > RotMatrix::zxzEulerAngles ( ) const

Calculates the Euler angles corresponding to the rotation.

Definition at line 53 of file RotMatrix.cpp.

54 {
55  double m00 = (-1 + 2 * x * x + 2 * s * s);
56  double m02 = 2 * (x * z + y * s);
57  double m10 = 2 * (y * x + z * s);
58  double m12 = 2 * (y * z - x * s);
59  double m20 = 2 * (z * x - y * s);
60  double m21 = 2 * (z * y + x * s);
61  double m22 = (-1 + 2 * z * z + 2 * s * s);
62 
63  const double beta = std::acos(m22);
64 
65  if (std::abs(m22) == 1.0) // second z angle is zero or pi
66  return {std::atan2(m10, m00), beta, 0.};
67  return {std::atan2(m02, -m12), beta, std::atan2(m20, m21)};
68 }

References ROOT::Math::Cephes::beta(), s, x, y, and z.

Referenced by IRotation::createRotation().

Here is the call graph for this function:

Member Data Documentation

◆ s

double RotMatrix::s
private

◆ x

double RotMatrix::x
private

◆ y

double RotMatrix::y
private

◆ z

double RotMatrix::z
private

The documentation for this class was generated from the following files: