OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
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 
68 class Euclid3D {
69 public:
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 
191 private:
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 
204 inline 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 
216 inline double Euclid3D::getX() const {
217  return V.getX();
218 }
219 
220 inline double Euclid3D::getY() const {
221  return V.getY();
222 }
223 
224 inline double Euclid3D::getZ() const {
225  return V.getZ();
226 }
227 
228 inline double Euclid3D::M(int row, int col) const {
229  return R(row, col);
230 }
231 
232 
233 inline bool Euclid3D::isIdentity() const {
234  return is_identity;
235 }
236 
237 #endif // CLASSIC_Euclid3D_HH
Euclid3D dot(const Euclid3D &rhs) const
Dot product.
Definition: Euclid3D.cpp:96
static Euclid3D XRotation(double angle)
Make rotation.
Definition: Euclid3D.cpp:157
void setDisplacement(const Vector3D &V)
Set displacement.
Definition: Euclid3D.cpp:84
const Euclid3D & operator*=(const Euclid3D &rhs)
Dot product with assign.
Definition: Euclid3D.cpp:116
static Euclid3D translation(double x, double y, double z)
Make translation.
Definition: Euclid3D.cpp:152
double getX() const
Get displacement.
Definition: Euclid3D.h:216
void setY(double y)
Set displacement.
Definition: Euclid3D.cpp:74
bool isPureYRotation() const
Test for rotation.
Definition: Euclid3D.cpp:137
Euclid3D()
Default constructor.
Definition: Euclid3D.h:212
Euclid3D inverse() const
Inverse.
Definition: Euclid3D.cpp:121
bool operator!=(const Euclid3D &) const
Definition: Euclid3D.cpp:47
double getZ() const
Get displacement.
Definition: Euclid3D.h:224
void setRotation(const Rotation3D &R)
Set rotation.
Definition: Euclid3D.cpp:90
double getZ() const
Get component.
Definition: Vector3D.h:152
double getY() const
Get component.
Definition: Vector3D.h:148
Vector3D V
Definition: Euclid3D.h:194
double M(int row, int col) const
Get component.
Definition: Euclid3D.h:228
static Euclid3D YRotation(double angle)
Make rotation.
Definition: Euclid3D.cpp:164
static Euclid3D identity()
Make identity.
Definition: Euclid3D.cpp:147
Euclid3D Inverse(const Euclid3D &t)
Euclidean inverse.
Definition: Euclid3D.h:204
bool operator==(const Euclid3D &) const
Definition: Euclid3D.cpp:42
double getX() const
Get component.
Definition: Vector3D.h:144
bool isPureZRotation() const
Test for rotation.
Definition: Euclid3D.cpp:142
void getAll(double &x, double &y, double &z, double &vx, double &vy, double &vz) const
Unpack.
Definition: Euclid3D.cpp:52
const Euclid3D & dotBy(const Euclid3D &rhs)
Dot product with assign.
Definition: Euclid3D.cpp:102
Displacement and rotation in space.
Definition: Euclid3D.h:68
bool isIdentity() const
Test for identity.
Definition: Euclid3D.h:233
void setZ(double z)
Set displacement.
Definition: Euclid3D.cpp:79
const Rotation3D & getRotation() const
Get rotation.
Definition: Euclid3D.cpp:64
void setX(double x)
Set displacement.
Definition: Euclid3D.cpp:69
A 3-dimension vector.
Definition: Vector3D.h:31
Euclid3D operator*(const Euclid3D &rhs) const
Dot product.
Definition: Euclid3D.cpp:110
bool isPureXRotation() const
Test for rotation.
Definition: Euclid3D.cpp:132
bool isPureTranslation() const
Test for translation.
Definition: Euclid3D.cpp:127
bool is_identity
Definition: Euclid3D.h:196
Rotation in 3-dimensional space.
Definition: Rotation3D.h:46
double getY() const
Get displacement.
Definition: Euclid3D.h:220
static Euclid3D ZRotation(double angle)
Make rotation.
Definition: Euclid3D.cpp:171
Rotation3D R
Definition: Euclid3D.h:195
const Vector3D & getVector() const
Get displacement.
Definition: Euclid3D.cpp:59