BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Transform3D Class Reference
Collaboration diagram for Transform3D:

Public Types

enum  ERotationType { EULER , XAXIS , YAXIS , ZAXIS }
 

Public Member Functions

 Transform3D ()
 
 Transform3D (const Eigen::Matrix3d &matrix)
 
 ~Transform3D ()
 
Transform3Dclone () const
 
void calculateEulerAngles (double *p_alpha, double *p_beta, double *p_gamma) const
 
double calculateRotateXAngle () const
 
double calculateRotateYAngle () const
 
double calculateRotateZAngle () const
 
Transform3D getInverse () const
 
template<class ivector_t >
ivector_t transformed (const ivector_t &v) const
 
template<class ivector_t >
ivector_t transformedInverse (const ivector_t &v) const
 
Transform3D operator* (const Transform3D &other) const
 
bool operator== (const Transform3D &other) const
 
ERotationType getRotationType () const
 
bool isIdentity () const
 
void print (std::ostream &ostr) const
 
bool isXRotation () const
 
bool isYRotation () const
 
bool isZRotation () const
 

Static Public Member Functions

static Transform3D createIdentity ()
 
static Transform3D createRotateX (double phi)
 
static Transform3D createRotateY (double phi)
 
static Transform3D createRotateZ (double phi)
 
static Transform3D createRotateEuler (double alpha, double beta, double gamma)
 

Private Attributes

Eigen::Matrix3d m_matrix
 
Eigen::Matrix3d m_inverse_matrix
 

Friends

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

Detailed Description

Vector transformations in three dimensions.

Definition at line 27 of file Transform3D.h.

Member Enumeration Documentation

◆ ERotationType

Enumerator
EULER 
XAXIS 
YAXIS 
ZAXIS 

Definition at line 30 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:112
Eigen::Matrix3d m_matrix
Definition: Transform3D.h:111

References m_inverse_matrix, and m_matrix.

Referenced by clone(), createIdentity(), 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 41 of file Transform3D.h.

41 {}

Member Function Documentation

◆ clone()

Transform3D * Transform3D::clone ( ) const

Clones the transformation.

Definition at line 140 of file Transform3D.cpp.

141 {
142  return new Transform3D(m_matrix);
143 }
Transform3D()
Constructs unit transformation.
Definition: Transform3D.cpp:18

References m_matrix, and Transform3D().

Here is the call graph for this function:

◆ createIdentity()

Transform3D Transform3D::createIdentity ( )
static

Creates identity transformation (default)

Definition at line 29 of file Transform3D.cpp.

30 {
31  return Transform3D();
32 }

References Transform3D().

Referenced by IdentityRotation::getTransform3D().

Here is the call graph for this function:

◆ createRotateX()

Transform3D Transform3D::createRotateX ( double  phi)
static

Creates rotation around x-axis.

Definition at line 34 of file Transform3D.cpp.

35 {
36  double cosine = std::cos(phi);
37  double sine = std::sin(phi);
38  Eigen::Matrix3d matrix;
39  matrix.setIdentity();
40  matrix(1, 1) = cosine;
41  matrix(1, 2) = -sine;
42  matrix(2, 1) = sine;
43  matrix(2, 2) = cosine;
44  return Transform3D(matrix);
45 }

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 47 of file Transform3D.cpp.

48 {
49  double cosine = std::cos(phi);
50  double sine = std::sin(phi);
51  Eigen::Matrix3d matrix;
52  matrix.setIdentity();
53  matrix(0, 0) = cosine;
54  matrix(0, 2) = sine;
55  matrix(2, 0) = -sine;
56  matrix(2, 2) = cosine;
57  return Transform3D(matrix);
58 }

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 60 of file Transform3D.cpp.

61 {
62  double cosine = std::cos(phi);
63  double sine = std::sin(phi);
64  Eigen::Matrix3d matrix;
65  matrix.setIdentity();
66  matrix(0, 0) = cosine;
67  matrix(0, 1) = -sine;
68  matrix(1, 0) = sine;
69  matrix(1, 1) = cosine;
70  return Transform3D(matrix);
71 }

References Transform3D().

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

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 73 of file Transform3D.cpp.

74 {
75  Transform3D zrot = createRotateZ(alpha);
76  Transform3D xrot = createRotateX(beta);
77  Transform3D zrot2 = createRotateZ(gamma);
78  return zrot * xrot * zrot2;
79 }
Vector transformations in three dimensions.
Definition: Transform3D.h:28
static Transform3D createRotateX(double phi)
Creates rotation around x-axis.
Definition: Transform3D.cpp:34
static Transform3D createRotateZ(double phi)
Creates rotation around z-axis.
Definition: Transform3D.cpp:60

References createRotateX(), and createRotateZ().

Referenced by RotationEuler::getTransform3D().

Here is the call graph for this function:

◆ 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 81 of file Transform3D.cpp.

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

References m_matrix.

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

◆ 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 94 of file Transform3D.cpp.

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

References m_matrix.

Referenced by IRotation::createRotation(), and SampleToPython::setRotationInformation().

◆ 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 99 of file Transform3D.cpp.

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

References m_matrix.

Referenced by IRotation::createRotation(), and SampleToPython::setRotationInformation().

◆ 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 104 of file Transform3D.cpp.

105 {
106  return std::atan2(m_matrix(1, 0), m_matrix(0, 0));
107 }

References m_matrix.

Referenced by IRotation::createRotation(), and SampleToPython::setRotationInformation().

◆ getInverse()

Transform3D Transform3D::getInverse ( ) const

Returns the inverse transformation.

Definition at line 109 of file Transform3D.cpp.

110 {
112  return result;
113 }

References m_inverse_matrix.

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

◆ transformed()

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

Return transformed vector v.

Definition at line 115 of file Transform3D.cpp.

116 {
117  auto x = m_matrix(0, 0) * v.x() + m_matrix(0, 1) * v.y() + m_matrix(0, 2) * v.z();
118  auto y = m_matrix(1, 0) * v.x() + m_matrix(1, 1) * v.y() + m_matrix(1, 2) * v.z();
119  auto z = m_matrix(2, 0) * v.x() + m_matrix(2, 1) * v.y() + m_matrix(2, 2) * v.z();
120  return ivector_t(x, y, z);
121 }
BasicVector3D< int > ivector_t
Definition: Vectors3D.h:20
T z() const
Returns z-component in cartesian coordinate system.
Definition: BasicVector3D.h:68
T y() const
Returns y-component in cartesian coordinate system.
Definition: BasicVector3D.h:66
T x() const
Returns x-component in cartesian coordinate system.
Definition: BasicVector3D.h:64

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

Referenced by Lattice::createTransformedLattice(), MagneticMaterialImpl::rotatedMaterial(), IRotation::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 126 of file Transform3D.cpp.

127 {
128  auto x = m_inverse_matrix(0, 0) * v.x() + m_inverse_matrix(0, 1) * v.y()
129  + m_inverse_matrix(0, 2) * v.z();
130  auto y = m_inverse_matrix(1, 0) * v.x() + m_inverse_matrix(1, 1) * v.y()
131  + m_inverse_matrix(1, 2) * v.z();
132  auto z = m_inverse_matrix(2, 0) * v.x() + m_inverse_matrix(2, 1) * v.y()
133  + m_inverse_matrix(2, 2) * v.z();
134  return ivector_t(x, y, z);
135 }

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

Here is the call graph for this function:

◆ operator*()

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

Composes two transformations.

Definition at line 145 of file Transform3D.cpp.

146 {
147  Eigen::Matrix3d product_matrix = this->m_matrix * other.m_matrix;
148  return Transform3D(product_matrix);
149 }

References m_matrix, and Transform3D().

Here is the call graph for this function:

◆ operator==()

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

Provides equality operator.

Definition at line 151 of file Transform3D.cpp.

152 {
153  return this->m_matrix == other.m_matrix;
154 }

References m_matrix.

◆ getRotationType()

Transform3D::ERotationType Transform3D::getRotationType ( ) const

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

Definition at line 156 of file Transform3D.cpp.

157 {
158  if (isXRotation())
159  return XAXIS;
160  if (isYRotation())
161  return YAXIS;
162  if (isZRotation())
163  return ZAXIS;
164  return EULER;
165 }
bool isYRotation() const
bool isXRotation() const
bool isZRotation() const

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

Referenced by IRotation::createRotation(), and SampleToPython::setRotationInformation().

Here is the call graph for this function:

◆ isIdentity()

bool Transform3D::isIdentity ( ) const

Determine if the transformation is trivial (identity)

Definition at line 167 of file Transform3D.cpp.

168 {
169  double alpha, beta, gamma;
170  calculateEulerAngles(&alpha, &beta, &gamma);
171  return (alpha == 0.0 && beta == 0.0 && gamma == 0.0);
172 }
void calculateEulerAngles(double *p_alpha, double *p_beta, double *p_gamma) const
Calculates the Euler angles corresponding to the rotation.
Definition: Transform3D.cpp:81

References calculateEulerAngles().

Referenced by IRotation::isIdentity().

Here is the call graph for this function:

◆ print()

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

Definition at line 174 of file Transform3D.cpp.

175 {
176  ostr << "Transform3D: " << m_matrix;
177 }

References m_matrix.

◆ isXRotation()

bool Transform3D::isXRotation ( ) const

Definition at line 179 of file Transform3D.cpp.

180 {
181  if (m_matrix(0, 0) != 1.0)
182  return false;
183  if (m_matrix(0, 1) != 0.0)
184  return false;
185  if (m_matrix(0, 2) != 0.0)
186  return false;
187  if (m_matrix(1, 0) != 0.0)
188  return false;
189  if (m_matrix(2, 0) != 0.0)
190  return false;
191  return true;
192 }

References m_matrix.

Referenced by getRotationType().

◆ isYRotation()

bool Transform3D::isYRotation ( ) const

Definition at line 194 of file Transform3D.cpp.

195 {
196  if (m_matrix(1, 1) != 1.0)
197  return false;
198  if (m_matrix(0, 1) != 0.0)
199  return false;
200  if (m_matrix(1, 0) != 0.0)
201  return false;
202  if (m_matrix(1, 2) != 0.0)
203  return false;
204  if (m_matrix(2, 1) != 0.0)
205  return false;
206  return true;
207 }

References m_matrix.

Referenced by getRotationType().

◆ isZRotation()

bool Transform3D::isZRotation ( ) const

Definition at line 209 of file Transform3D.cpp.

210 {
211  if (m_matrix(2, 2) != 1.0)
212  return false;
213  if (m_matrix(0, 2) != 0.0)
214  return false;
215  if (m_matrix(1, 2) != 0.0)
216  return false;
217  if (m_matrix(2, 0) != 0.0)
218  return false;
219  if (m_matrix(2, 1) != 0.0)
220  return false;
221  return true;
222 }

References m_matrix.

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

Friends And Related Function Documentation

◆ operator<<

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

Definition at line 97 of file Transform3D.h.

98  {
99  m.print(ostr);
100  return ostr;
101  }
void print(std::ostream &ostr) const

Member Data Documentation

◆ m_matrix

◆ m_inverse_matrix

Eigen::Matrix3d Transform3D::m_inverse_matrix
private

Definition at line 112 of file Transform3D.h.

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


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