BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Transform3D Class Reference

Vector transformations in three dimensions. More...

Public Types

enum  ERotationType { EULER , XAXIS , YAXIS , ZAXIS }
 

Public Member Functions

 Transform3D ()
 Constructs unit transformation. More...
 
 Transform3D (const Eigen::Matrix3d &matrix)
 Constructor from matrix (no checks if this is an element of SO(3)!) More...
 
 ~Transform3D ()
 Destructor. More...
 
void calculateEulerAngles (double *p_alpha, double *p_beta, double *p_gamma) const
 Calculates the Euler angles corresponding to the rotation. More...
 
double calculateRotateXAngle () const
 Calculates the rotation angle for a rotation around the x-axis alone Only meaningfull if the actual rotation is around the x-axis. More...
 
double calculateRotateYAngle () const
 Calculates the rotation angle for a rotation around the y-axis alone Only meaningfull if the actual rotation is around the y-axis. More...
 
double calculateRotateZAngle () const
 Calculates the rotation angle for a rotation around the z-axis alone Only meaningfull if the actual rotation is around the z-axis. More...
 
Transform3Dclone () const
 Clones the transformation. More...
 
Transform3D getInverse () const
 Returns the inverse transformation. More...
 
ERotationType getRotationType () const
 Retrieve the rotation type (general, around x, y or z-axis) More...
 
bool isIdentity () const
 Determine if the transformation is trivial (identity) More...
 
bool isXRotation () const
 
bool isYRotation () const
 
bool isZRotation () const
 
Transform3D operator* (const Transform3D &other) const
 Composes two transformations. More...
 
bool operator== (const Transform3D &other) const
 Provides equality operator. More...
 
void print (std::ostream &ostr) const
 
template<class ivector_t >
ivector_t transformed (const ivector_t &v) const
 Return transformed vector v. More...
 
template<class ivector_t >
ivector_t transformedInverse (const ivector_t &v) const
 Return transformed vector v. More...
 

Static Public Member Functions

static Transform3D createRotateEuler (double alpha, double beta, double gamma)
 Creates rotation defined by Euler angles. More...
 
static Transform3D createRotateX (double phi)
 Creates rotation around x-axis. More...
 
static Transform3D createRotateY (double phi)
 Creates rotation around y-axis. More...
 
static Transform3D createRotateZ (double phi)
 Creates rotation around z-axis. More...
 

Private Attributes

Eigen::Matrix3d m_inverse_matrix
 
Eigen::Matrix3d m_matrix
 

Friends

std::ostream & operator<< (std::ostream &ostr, const Transform3D &m)
 

Detailed Description

Vector transformations in three dimensions.

Definition at line 26 of file Transform3D.h.

Member Enumeration Documentation

◆ ERotationType

Enumerator
EULER 
XAXIS 
YAXIS 
ZAXIS 

Definition at line 28 of file Transform3D.h.

Constructor & Destructor Documentation

◆ Transform3D() [1/2]

Transform3D::Transform3D ( )

Constructs unit transformation.

Definition at line 18 of file Transform3D.cpp.

19 {
20  m_matrix.setIdentity();
21  m_inverse_matrix.setIdentity();
22 }
Eigen::Matrix3d m_inverse_matrix
Definition: Transform3D.h:107
Eigen::Matrix3d m_matrix
Definition: Transform3D.h:106

References m_inverse_matrix, and m_matrix.

Referenced by clone(), createRotateX(), createRotateY(), createRotateZ(), and operator*().

◆ Transform3D() [2/2]

Transform3D::Transform3D ( const Eigen::Matrix3d &  matrix)

Constructor from matrix (no checks if this is an element of SO(3)!)

Definition at line 24 of file Transform3D.cpp.

24  : m_matrix(matrix)
25 {
26  m_inverse_matrix = m_matrix.inverse();
27 }

References m_inverse_matrix, and m_matrix.

◆ ~Transform3D()

Transform3D::~Transform3D ( )
inline

Destructor.

Definition at line 39 of file Transform3D.h.

39 {}

Member Function Documentation

◆ calculateEulerAngles()

void Transform3D::calculateEulerAngles ( double *  p_alpha,
double *  p_beta,
double *  p_gamma 
) const

Calculates the Euler angles corresponding to the rotation.

Definition at line 76 of file Transform3D.cpp.

77 {
78  *p_beta = std::acos(m_matrix(2, 2));
79  // First check if second angle is zero or pi
80  if (std::abs(m_matrix(2, 2)) == 1.0) {
81  *p_alpha = std::atan2(m_matrix(1, 0), m_matrix(0, 0));
82  *p_gamma = 0.0;
83  } else {
84  *p_alpha = std::atan2(m_matrix(0, 2), -m_matrix(1, 2));
85  *p_gamma = std::atan2(m_matrix(2, 0), m_matrix(2, 1));
86  }
87 }

References m_matrix.

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

◆ calculateRotateXAngle()

double Transform3D::calculateRotateXAngle ( ) const

Calculates the rotation angle for a rotation around the x-axis alone Only meaningfull if the actual rotation is around the x-axis.

Definition at line 89 of file Transform3D.cpp.

90 {
91  return std::atan2(m_matrix(2, 1), m_matrix(1, 1));
92 }

References m_matrix.

Referenced by IRotation::createRotation().

◆ calculateRotateYAngle()

double Transform3D::calculateRotateYAngle ( ) const

Calculates the rotation angle for a rotation around the y-axis alone Only meaningfull if the actual rotation is around the y-axis.

Definition at line 94 of file Transform3D.cpp.

95 {
96  return std::atan2(m_matrix(0, 2), m_matrix(2, 2));
97 }

References m_matrix.

Referenced by IRotation::createRotation().

◆ calculateRotateZAngle()

double Transform3D::calculateRotateZAngle ( ) const

Calculates the rotation angle for a rotation around the z-axis alone Only meaningfull if the actual rotation is around the z-axis.

Definition at line 99 of file Transform3D.cpp.

100 {
101  return std::atan2(m_matrix(1, 0), m_matrix(0, 0));
102 }

References m_matrix.

Referenced by IRotation::createRotation().

◆ clone()

Transform3D * Transform3D::clone ( ) const

Clones the transformation.

Definition at line 135 of file Transform3D.cpp.

136 {
137  return new Transform3D(m_matrix);
138 }
Transform3D()
Constructs unit transformation.
Definition: Transform3D.cpp:18

References Transform3D(), and m_matrix.

Here is the call graph for this function:

◆ createRotateEuler()

Transform3D Transform3D::createRotateEuler ( double  alpha,
double  beta,
double  gamma 
)
static

Creates rotation defined by Euler angles.

Definition at line 68 of file Transform3D.cpp.

69 {
70  Transform3D zrot = createRotateZ(alpha);
71  Transform3D xrot = createRotateX(beta);
72  Transform3D zrot2 = createRotateZ(gamma);
73  return zrot * xrot * zrot2;
74 }
Vector transformations in three dimensions.
Definition: Transform3D.h:26
static Transform3D createRotateX(double phi)
Creates rotation around x-axis.
Definition: Transform3D.cpp:29
static Transform3D createRotateZ(double phi)
Creates rotation around z-axis.
Definition: Transform3D.cpp:55

References createRotateX(), and createRotateZ().

Referenced by RotationEuler::getTransform3D().

Here is the call graph for this function:

◆ createRotateX()

Transform3D Transform3D::createRotateX ( double  phi)
static

Creates rotation around x-axis.

Definition at line 29 of file Transform3D.cpp.

30 {
31  double cosine = std::cos(phi);
32  double sine = std::sin(phi);
33  Eigen::Matrix3d matrix;
34  matrix.setIdentity();
35  matrix(1, 1) = cosine;
36  matrix(1, 2) = -sine;
37  matrix(2, 1) = sine;
38  matrix(2, 2) = cosine;
39  return Transform3D(matrix);
40 }

References Transform3D().

Referenced by createRotateEuler(), and RotationX::getTransform3D().

Here is the call graph for this function:

◆ createRotateY()

Transform3D Transform3D::createRotateY ( double  phi)
static

Creates rotation around y-axis.

Definition at line 42 of file Transform3D.cpp.

43 {
44  double cosine = std::cos(phi);
45  double sine = std::sin(phi);
46  Eigen::Matrix3d matrix;
47  matrix.setIdentity();
48  matrix(0, 0) = cosine;
49  matrix(0, 2) = sine;
50  matrix(2, 0) = -sine;
51  matrix(2, 2) = cosine;
52  return Transform3D(matrix);
53 }

References Transform3D().

Referenced by RotationY::getTransform3D().

Here is the call graph for this function:

◆ createRotateZ()

Transform3D Transform3D::createRotateZ ( double  phi)
static

Creates rotation around z-axis.

Definition at line 55 of file Transform3D.cpp.

56 {
57  double cosine = std::cos(phi);
58  double sine = std::sin(phi);
59  Eigen::Matrix3d matrix;
60  matrix.setIdentity();
61  matrix(0, 0) = cosine;
62  matrix(0, 1) = -sine;
63  matrix(1, 0) = sine;
64  matrix(1, 1) = cosine;
65  return Transform3D(matrix);
66 }

References Transform3D().

Referenced by createRotateEuler(), and RotationZ::getTransform3D().

Here is the call graph for this function:

◆ getInverse()

Transform3D Transform3D::getInverse ( ) const

Returns the inverse transformation.

Definition at line 104 of file Transform3D.cpp.

105 {
107  return result;
108 }

References m_inverse_matrix.

Referenced by FormFactorDecoratorRotation::evaluate(), and FormFactorDecoratorRotation::evaluatePol().

◆ getRotationType()

Transform3D::ERotationType Transform3D::getRotationType ( ) const

Retrieve the rotation type (general, around x, y or z-axis)

Definition at line 151 of file Transform3D.cpp.

152 {
153  if (isXRotation())
154  return XAXIS;
155  if (isYRotation())
156  return YAXIS;
157  if (isZRotation())
158  return ZAXIS;
159  return EULER;
160 }
bool isYRotation() const
bool isXRotation() const
bool isZRotation() const

References EULER, isXRotation(), isYRotation(), isZRotation(), XAXIS, YAXIS, and ZAXIS.

Referenced by IRotation::createRotation().

Here is the call graph for this function:

◆ isIdentity()

bool Transform3D::isIdentity ( ) const

Determine if the transformation is trivial (identity)

Definition at line 162 of file Transform3D.cpp.

163 {
164  double alpha, beta, gamma;
165  calculateEulerAngles(&alpha, &beta, &gamma);
166  return (alpha == 0.0 && beta == 0.0 && gamma == 0.0);
167 }
void calculateEulerAngles(double *p_alpha, double *p_beta, double *p_gamma) const
Calculates the Euler angles corresponding to the rotation.
Definition: Transform3D.cpp:76

References calculateEulerAngles().

Referenced by IRotation::isIdentity().

Here is the call graph for this function:

◆ isXRotation()

bool Transform3D::isXRotation ( ) const

Definition at line 174 of file Transform3D.cpp.

175 {
176  if (m_matrix(0, 0) != 1.0)
177  return false;
178  if (m_matrix(0, 1) != 0.0)
179  return false;
180  if (m_matrix(0, 2) != 0.0)
181  return false;
182  if (m_matrix(1, 0) != 0.0)
183  return false;
184  if (m_matrix(2, 0) != 0.0)
185  return false;
186  return true;
187 }

References m_matrix.

Referenced by getRotationType().

◆ isYRotation()

bool Transform3D::isYRotation ( ) const

Definition at line 189 of file Transform3D.cpp.

190 {
191  if (m_matrix(1, 1) != 1.0)
192  return false;
193  if (m_matrix(0, 1) != 0.0)
194  return false;
195  if (m_matrix(1, 0) != 0.0)
196  return false;
197  if (m_matrix(1, 2) != 0.0)
198  return false;
199  if (m_matrix(2, 1) != 0.0)
200  return false;
201  return true;
202 }

References m_matrix.

Referenced by getRotationType().

◆ isZRotation()

bool Transform3D::isZRotation ( ) const

Definition at line 204 of file Transform3D.cpp.

205 {
206  if (m_matrix(2, 2) != 1.0)
207  return false;
208  if (m_matrix(0, 2) != 0.0)
209  return false;
210  if (m_matrix(1, 2) != 0.0)
211  return false;
212  if (m_matrix(2, 0) != 0.0)
213  return false;
214  if (m_matrix(2, 1) != 0.0)
215  return false;
216  return true;
217 }

References m_matrix.

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

◆ operator*()

Transform3D Transform3D::operator* ( const Transform3D other) const

Composes two transformations.

Definition at line 140 of file Transform3D.cpp.

141 {
142  Eigen::Matrix3d product_matrix = this->m_matrix * other.m_matrix;
143  return Transform3D(product_matrix);
144 }

References Transform3D(), and m_matrix.

Here is the call graph for this function:

◆ operator==()

bool Transform3D::operator== ( const Transform3D other) const

Provides equality operator.

Definition at line 146 of file Transform3D.cpp.

147 {
148  return this->m_matrix == other.m_matrix;
149 }

References m_matrix.

◆ print()

void Transform3D::print ( std::ostream &  ostr) const

Definition at line 169 of file Transform3D.cpp.

170 {
171  ostr << "Transform3D: " << m_matrix;
172 }

References m_matrix.

◆ transformed()

template<class ivector_t >
template cvector_t Transform3D::transformed< cvector_t > ( const ivector_t v) const

Return transformed vector v.

Definition at line 110 of file Transform3D.cpp.

111 {
112  auto x = m_matrix(0, 0) * v.x() + m_matrix(0, 1) * v.y() + m_matrix(0, 2) * v.z();
113  auto y = m_matrix(1, 0) * v.x() + m_matrix(1, 1) * v.y() + m_matrix(1, 2) * v.z();
114  auto z = m_matrix(2, 0) * v.x() + m_matrix(2, 1) * v.y() + m_matrix(2, 2) * v.z();
115  return ivector_t(x, y, z);
116 }
BasicVector3D< int > ivector_t
Definition: Vectors3D.h:20
T z() const
Returns z-component in cartesian coordinate system.
Definition: BasicVector3D.h:67
T y() const
Returns y-component in cartesian coordinate system.
Definition: BasicVector3D.h:65
T x() const
Returns x-component in cartesian coordinate system.
Definition: BasicVector3D.h:63

References m_matrix, BasicVector3D< T >::x(), BasicVector3D< T >::y(), and BasicVector3D< T >::z().

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

Here is the call graph for this function:

◆ transformedInverse()

template<class ivector_t >
template cvector_t Transform3D::transformedInverse< cvector_t > ( const ivector_t v) const

Return transformed vector v.

Definition at line 121 of file Transform3D.cpp.

122 {
123  auto x = m_inverse_matrix(0, 0) * v.x() + m_inverse_matrix(0, 1) * v.y()
124  + m_inverse_matrix(0, 2) * v.z();
125  auto y = m_inverse_matrix(1, 0) * v.x() + m_inverse_matrix(1, 1) * v.y()
126  + m_inverse_matrix(1, 2) * v.z();
127  auto z = m_inverse_matrix(2, 0) * v.x() + m_inverse_matrix(2, 1) * v.y()
128  + m_inverse_matrix(2, 2) * v.z();
129  return ivector_t(x, y, z);
130 }

References m_inverse_matrix, BasicVector3D< T >::x(), BasicVector3D< T >::y(), and BasicVector3D< T >::z().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  ostr,
const Transform3D m 
)
friend

Definition at line 92 of file Transform3D.h.

93  {
94  m.print(ostr);
95  return ostr;
96  }
void print(std::ostream &ostr) const

Member Data Documentation

◆ m_inverse_matrix

Eigen::Matrix3d Transform3D::m_inverse_matrix
private

Definition at line 107 of file Transform3D.h.

Referenced by Transform3D(), getInverse(), and transformedInverse().

◆ m_matrix


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