1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file Sample/Scattering/Rotations.cpp
//! @brief Implements class IRotationes.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#include "Sample/Scattering/Rotations.h"
#include "Base/Util/Assert.h"
// ************************************************************************************************
// interface IRotation
// ************************************************************************************************
IRotation::IRotation(const std::vector<double>& PValues)
: INode(PValues)
{
}
IRotation* IRotation::createRotation(const RotMatrix& matrix)
{
if (matrix.isIdentity())
return new IdentityRotation;
if (std::optional<double> angle = matrix.angleAroundCoordAxis(0))
return new RotationX(angle.value());
if (std::optional<double> angle = matrix.angleAroundCoordAxis(1))
return new RotationY(angle.value());
if (std::optional<double> angle = matrix.angleAroundCoordAxis(2))
return new RotationZ(angle.value());
auto angles = matrix.zxzEulerAngles();
return new RotationEuler(angles[0], angles[1], angles[2]);
}
R3 IRotation::transformed(const R3& v) const
{
return rotMatrix().transformed(v);
}
bool IRotation::isIdentity() const
{
return rotMatrix().isIdentity();
}
bool IRotation::zInvariant() const
{
return rotMatrix().isZRotation();
}
//! Returns concatenated rotation (first right, then left).
IRotation* createProduct(const IRotation& left, const IRotation& right)
{
RotMatrix tr_left = left.rotMatrix();
RotMatrix tr_right = right.rotMatrix();
IRotation* result = IRotation::createRotation(tr_left * tr_right);
return result;
}
// ************************************************************************************************
// class IdentityRotation
// ************************************************************************************************
IdentityRotation::IdentityRotation()
: IRotation({})
{
}
RotMatrix IdentityRotation::rotMatrix() const
{
return {};
}
// ************************************************************************************************
// class RotationX
// ************************************************************************************************
//! Constructor of rotation around x-axis
RotationX::RotationX(const std::vector<double> P)
: IRotation(P)
, m_angle(m_P[0])
{
}
RotationX::RotationX(double angle)
: RotationX(std::vector<double>{angle})
{
}
RotMatrix RotationX::rotMatrix() const
{
return RotMatrix::AroundX(m_angle);
}
// ************************************************************************************************
// class RotationY
// ************************************************************************************************
//! Constructor of rotation around y-axis
RotationY::RotationY(const std::vector<double> P)
: IRotation(P)
, m_angle(m_P[0])
{
}
RotationY::RotationY(double angle)
: RotationY(std::vector<double>{angle})
{
}
RotMatrix RotationY::rotMatrix() const
{
return RotMatrix::AroundY(m_angle);
}
// ************************************************************************************************
// class RotationZ
// ************************************************************************************************
// --- RotationZ --------------------------------------------------------------
//! Constructor of rotation around z-axis
RotationZ::RotationZ(const std::vector<double> P)
: IRotation(P)
, m_angle(m_P[0])
{
}
RotationZ::RotationZ(double angle)
: RotationZ(std::vector<double>{angle})
{
}
RotMatrix RotationZ::rotMatrix() const
{
return RotMatrix::AroundZ(m_angle);
}
// ************************************************************************************************
// class RotationEuler
// ************************************************************************************************
RotationEuler::RotationEuler(const std::vector<double> P)
: IRotation(P)
, m_alpha(m_P[0])
, m_beta(m_P[1])
, m_gamma(m_P[2])
{
}
RotationEuler::RotationEuler(double alpha, double beta, double gamma)
: RotationEuler(std::vector<double>{alpha, beta, gamma})
{
}
IRotation* RotationEuler::createInverse() const
{
RotMatrix inverse_transform(rotMatrix().Inverse());
return createRotation(inverse_transform);
}
RotMatrix RotationEuler::rotMatrix() const
{
return RotMatrix::EulerZXZ(m_alpha, m_beta, m_gamma);
}
|