OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
Euclid3D.h
Go to the documentation of this file.
1#ifndef CLASSIC_Euclid3D_HH
2#define CLASSIC_Euclid3D_HH
3
4// ------------------------------------------------------------------------
5// $RCSfile: Euclid3D.h,v $
6// ------------------------------------------------------------------------
7// $Revision: 1.1.1.1 $
8// ------------------------------------------------------------------------
9// Copyright: see Copyright.readme
10// ------------------------------------------------------------------------
11//
12// Class: Euclid3D
13//
14// ------------------------------------------------------------------------
15// Class category: BeamlineGeometry
16// ------------------------------------------------------------------------
17//
18// $Date: 2000/03/27 09:32:34 $
19// $Author: fci $
20//
21// ------------------------------------------------------------------------
22
25
26
27// Class Euclid3D
28// ------------------------------------------------------------------------
30// An arbitrary 3-dimension translation and rotation.
31// The translation is a 3-dimensional vector, the rotation is represented
32// as a 3-dimensional orthonormal matrix.
33// {P}
34// If we think of an Euler3D object as an operator E which transforms a
35// point in the super-frame X to the local frame X':
36// {P}
37// X' = E(X),
38// {P}
39// then we can define a dot product of two successive operations in the
40// following way: Given two Euclid3D objects (operators) E1 and E2,
41// we can define
42// {P}
43// E3 = E2 . E1
44// {P}
45// using
46// {P}
47// X''= E3(X) = E2(E1(X)).
48// {P}
49// The definition of a multiplicative inverse naturally follows as
50// {P}
51// E . inv(E) = I.
52// {P}
53// If R represents the 3-d rotation and X the vector specified by
54// (x,y,z), then a transformation of a point P in the super-frame by
55// the Euclid3D is given by
56// {P}
57// P -> R . P + X.
58// {P}
59// For the representation of rotations, see Rotation3D.
60// The copy constructor, destructor, and assignment operator generated
61// by the compiler perform the correct operation. For speed reasons they
62// are not implemented.
63// An alternate representation for the rotation is given by a vector
64// pointing in the direction of the axis of rotation, whose sense is
65// given by the right-hand rule, and whose length is equal to the angle
66// of rotation.
67
68class Euclid3D {
69public:
70
72 // Construct identity.
73 Euclid3D();
74
76 // Use displacement [b]V[/b] and rotation [b]R[/b].
77 Euclid3D(const Vector3D &V, const Rotation3D &R);
78
80 // Use displacement (x,y,z) and rotation (vx,vy,vz).
81 Euclid3D(double x, double y, double z, double vx, double vy, double vz);
82
83 bool operator==(const Euclid3D &) const;
84 bool operator!=(const Euclid3D &) const;
85
87 // Return the displacement in (x,y,z) and the rotation axis in (vx,vy,vz).
88 void getAll(double &x, double &y, double &z,
89 double &vx, double &vy, double &vz) const;
90
92 // Return x-component of displacement.
93 double getX() const;
94
96 // Return x-component of displacement.
97 double getY() const;
98
100 // Return x-component of displacement.
101 double getZ() const;
102
104 // Return displacement as a vector.
105 const Vector3D &getVector() const;
106
108 // Return rotation as an orthogonal matrix.
109 const Rotation3D &getRotation() const;
110
112 // Return the component (row,col) of the rotation matrix.
113 double M(int row, int col) const;
114
116 // Assign x-component of displacement.
117 void setX(double x);
118
120 // Assign y-component of displacement.
121 void setY(double y);
122
124 // Assign z-component of displacement.
125 void setZ(double z);
126
128 // Assign displacement as a vector.
129 void setDisplacement(const Vector3D &V);
130
132 // Assign rotation as an orthogonal matrix.
133 void setRotation(const Rotation3D &R);
134
136 // Return composition of [b]this[/b] with [b]rhs[/b].
137 Euclid3D dot(const Euclid3D &rhs) const;
138
140 // Return composition of [b]this[/b] with [b]rhs[/b].
141 const Euclid3D &dotBy(const Euclid3D &rhs);
142
144 // Return composition of [b]this[/b] with [b]rhs[/b].
145 Euclid3D operator*(const Euclid3D &rhs) const;
146
148 const Euclid3D &operator*=(const Euclid3D &rhs);
149
151 Euclid3D inverse() const;
152
154 bool isIdentity() const;
155
157 // Return true, if [b]this[/b] is a pure translation.
158 bool isPureTranslation() const;
159
161 // Return true, if [b]this[/b] is a pure x-rotation.
162 bool isPureXRotation() const;
163
165 // Return true, if [b]this[/b] is a pure y-rotation.
166 bool isPureYRotation() const;
167
169 // Return true, if [b]this[/b] is a pure z-rotation.
170 bool isPureZRotation() const;
171
173 static Euclid3D identity();
174
176 // Use displacement (x,y,z).
177 static Euclid3D translation(double x, double y, double z);
178
180 // Construct pure rotation by [b]angle[/b] around the x-axis;
181 static Euclid3D XRotation(double angle);
182
184 // Construct pure rotation by [b]angle[/b] around the y-axis;
185 static Euclid3D YRotation(double angle);
186
188 // Construct pure rotation by [b]angle[/b] around the z-axis;
189 static Euclid3D ZRotation(double angle);
190
191private:
192
193 // Implementation.
194 Vector3D V; // The displacement.
195 Rotation3D R; // The rotation.
196 mutable bool is_identity; // True, when [b]this[/b] is identity.
197};
198
199
200// Global Function.
201// ------------------------------------------------------------------------
202
204inline Euclid3D Inverse(const Euclid3D &t) {
205 return t.inverse();
206}
207
208
209// Trivial functions are inlined.
210// ------------------------------------------------------------------------
211
213 V(), R(), is_identity(true)
214{}
215
216inline double Euclid3D::getX() const {
217 return V.getX();
218}
219
220inline double Euclid3D::getY() const {
221 return V.getY();
222}
223
224inline double Euclid3D::getZ() const {
225 return V.getZ();
226}
227
228inline double Euclid3D::M(int row, int col) const {
229 return R(row, col);
230}
231
232
233inline bool Euclid3D::isIdentity() const {
234 return is_identity;
235}
236
237#endif // CLASSIC_Euclid3D_HH
Euclid3D Inverse(const Euclid3D &t)
Euclidean inverse.
Definition: Euclid3D.h:204
Displacement and rotation in space.
Definition: Euclid3D.h:68
bool is_identity
Definition: Euclid3D.h:196
static Euclid3D ZRotation(double angle)
Make rotation.
Definition: Euclid3D.cpp:171
void setZ(double z)
Set displacement.
Definition: Euclid3D.cpp:79
void setX(double x)
Set displacement.
Definition: Euclid3D.cpp:69
double getX() const
Get displacement.
Definition: Euclid3D.h:216
double getY() const
Get displacement.
Definition: Euclid3D.h:220
Vector3D V
Definition: Euclid3D.h:194
bool isPureXRotation() const
Test for rotation.
Definition: Euclid3D.cpp:132
void setY(double y)
Set displacement.
Definition: Euclid3D.cpp:74
void getAll(double &x, double &y, double &z, double &vx, double &vy, double &vz) const
Unpack.
Definition: Euclid3D.cpp:52
double M(int row, int col) const
Get component.
Definition: Euclid3D.h:228
static Euclid3D YRotation(double angle)
Make rotation.
Definition: Euclid3D.cpp:164
bool operator==(const Euclid3D &) const
Definition: Euclid3D.cpp:42
Euclid3D()
Default constructor.
Definition: Euclid3D.h:212
void setDisplacement(const Vector3D &V)
Set displacement.
Definition: Euclid3D.cpp:84
bool operator!=(const Euclid3D &) const
Definition: Euclid3D.cpp:47
const Euclid3D & operator*=(const Euclid3D &rhs)
Dot product with assign.
Definition: Euclid3D.cpp:116
static Euclid3D XRotation(double angle)
Make rotation.
Definition: Euclid3D.cpp:157
const Euclid3D & dotBy(const Euclid3D &rhs)
Dot product with assign.
Definition: Euclid3D.cpp:102
const Vector3D & getVector() const
Get displacement.
Definition: Euclid3D.cpp:59
bool isPureYRotation() const
Test for rotation.
Definition: Euclid3D.cpp:137
Euclid3D inverse() const
Inverse.
Definition: Euclid3D.cpp:121
bool isIdentity() const
Test for identity.
Definition: Euclid3D.h:233
void setRotation(const Rotation3D &R)
Set rotation.
Definition: Euclid3D.cpp:90
static Euclid3D identity()
Make identity.
Definition: Euclid3D.cpp:147
Euclid3D operator*(const Euclid3D &rhs) const
Dot product.
Definition: Euclid3D.cpp:110
static Euclid3D translation(double x, double y, double z)
Make translation.
Definition: Euclid3D.cpp:152
Rotation3D R
Definition: Euclid3D.h:195
bool isPureZRotation() const
Test for rotation.
Definition: Euclid3D.cpp:142
Euclid3D dot(const Euclid3D &rhs) const
Dot product.
Definition: Euclid3D.cpp:96
double getZ() const
Get displacement.
Definition: Euclid3D.h:224
bool isPureTranslation() const
Test for translation.
Definition: Euclid3D.cpp:127
const Rotation3D & getRotation() const
Get rotation.
Definition: Euclid3D.cpp:64
Rotation in 3-dimensional space.
Definition: Rotation3D.h:46
A 3-dimension vector.
Definition: Vector3D.h:31
double getY() const
Get component.
Definition: Vector3D.h:148
double getX() const
Get component.
Definition: Vector3D.h:144
double getZ() const
Get component.
Definition: Vector3D.h:152