File: Rotations.h

package info (click to toggle)
bornagain 23.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,936 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 318; ruby: 173; xml: 130; makefile: 51; ansic: 24
file content (173 lines) | stat: -rw-r--r-- 4,964 bytes parent folder | download | duplicates (2)
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
172
173
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Sample/Scattering/Rotations.h
//! @brief     Defines 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)
//
//  ************************************************************************************************

#ifndef BORNAGAIN_SAMPLE_SCATTERING_ROTATIONS_H
#define BORNAGAIN_SAMPLE_SCATTERING_ROTATIONS_H

#include "Base/Type/ICloneable.h"
#include "Base/Vector/RotMatrix.h"
#include "Param/Node/INode.h"
#include <heinz/Vectors3D.h>

//! Abstract base class for rotations.

class IRotation : public ICloneable, public INode {
public:
    static IRotation* createRotation(const RotMatrix& matrix);

    IRotation(const std::vector<double>& PValues);

#ifndef SWIG
    IRotation* clone() const override = 0;

    //! Returns a new IRotation object that is the current object's inverse
    virtual IRotation* createInverse() const = 0;
#endif // SWIG

    //! Returns transformation.
    virtual RotMatrix rotMatrix() const = 0;

    R3 transformed(const R3& v) const;

    //! Returns true if rotation matrix is identity matrix (no rotations)
    virtual bool isIdentity() const;

    bool zInvariant() const;
};

IRotation* createProduct(const IRotation& left, const IRotation& right);


//! The identity rotation, which leaves everything in place.

class IdentityRotation : public IRotation // TODO RECONSIDER: merge with class IRotation
{
public:
    IdentityRotation();

#ifndef SWIG
    IdentityRotation* clone() const override { return new IdentityRotation(); }

    IdentityRotation* createInverse() const override { return new IdentityRotation(); }
#endif // SWIG

    std::string className() const final { return "IdentityRotation"; }

    RotMatrix rotMatrix() const override;

    bool isIdentity() const override { return true; }
};

//! A rotation about the x axis.

class RotationX : public IRotation {
public:
    RotationX(std::vector<double> P);
    RotationX(double angle);

#ifndef SWIG
    RotationX* clone() const override { return new RotationX(m_angle); }

    RotationX* createInverse() const override { return new RotationX(-m_angle); }
#endif // SWIG

    std::string className() const final { return "RotationX"; }
    std::vector<ParaMeta> parDefs() const final { return {{"Angle", "rad"}}; }

    double angle() const { return m_angle; }

    RotMatrix rotMatrix() const override;

protected:
    const double& m_angle;
};

//! A rotation about the y axis.

class RotationY : public IRotation {
public:
    RotationY(std::vector<double> P);
    RotationY(double angle);

#ifndef SWIG
    RotationY* clone() const override { return new RotationY(m_angle); }

    RotationY* createInverse() const override { return new RotationY(-m_angle); }
#endif // SWIG

    std::string className() const final { return "RotationY"; }
    std::vector<ParaMeta> parDefs() const final { return {{"Angle", "rad"}}; }

    double angle() const { return m_angle; }

    RotMatrix rotMatrix() const override;

protected:
    const double& m_angle;
};

//! A rotation about the z axis.

class RotationZ : public IRotation {
public:
    RotationZ(std::vector<double> P);
    RotationZ(double angle);

#ifndef SWIG
    RotationZ* clone() const override { return new RotationZ(m_angle); }

    RotationZ* createInverse() const override { return new RotationZ(-m_angle); }
#endif // SWIG

    std::string className() const final { return "RotationZ"; }
    std::vector<ParaMeta> parDefs() const final { return {{"Angle", "rad"}}; }

    double angle() const { return m_angle; }

    RotMatrix rotMatrix() const override;

protected:
    const double& m_angle;
};

//! A sequence of rotations about the z-x'-z'' axes.

class RotationEuler : public IRotation {
public:
    RotationEuler(std::vector<double> P);
    RotationEuler(double alpha, double beta, double gamma);

#ifndef SWIG
    RotationEuler* clone() const override { return new RotationEuler(m_alpha, m_beta, m_gamma); }

    IRotation* createInverse() const override;
#endif // SWIG

    std::string className() const final { return "RotationEuler"; }
    std::vector<ParaMeta> parDefs() const final
    {
        return {{"Alpha", "rad"}, {"Beta", "rad"}, {"Gamma", "rad"}};
    }

    double alpha() const { return m_alpha; } //!< First Euler angle, rotation around z axis
    double beta() const { return m_beta; }   //!< Second Euler angle, rotation around x' axis
    double gamma() const { return m_gamma; } //!< Third Euler angle, rotation around z'' axis

    RotMatrix rotMatrix() const override;

protected:
    double m_alpha, m_beta, m_gamma;
};

#endif // BORNAGAIN_SAMPLE_SCATTERING_ROTATIONS_H