OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
Euclid3D.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: Euclid3D.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: Euclid3D
10 // Euclid3D represents an arbitrary 3-dimension translation and
11 // rotation.
12 //
13 // ------------------------------------------------------------------------
14 // Class category: BeamlineGeometry
15 // ------------------------------------------------------------------------
16 //
17 // $Date: 2000/03/27 09:32:34 $
18 // $Author: fci $
19 //
20 // ------------------------------------------------------------------------
21 
23 #include <cmath>
24 
25 
26 // Class Euclid3D
27 // ------------------------------------------------------------------------
28 // The present implementation contains a Vector3D representing the
29 // displacement, and a Matrix3D representing the rotation.
30 
32 (double x, double y, double z, double vx, double vy, double vz):
33  V(x, y, z), R(vx, vy, vz), is_identity(false)
34 {}
35 
36 
38  V(vec), R(rot), is_identity(false)
39 {}
40 
41 
42 bool Euclid3D::operator==(const Euclid3D &rhs) const {
43  return (V == rhs.V) && (R == rhs.R);
44 }
45 
46 
47 bool Euclid3D::operator!=(const Euclid3D &rhs) const {
48  return (V != rhs.V) || (R != rhs.R);
49 }
50 
51 
52 void Euclid3D::getAll(double &x, double &y, double &z,
53  double &vx, double &vy, double &vz) const {
54  V.getComponents(x, y, z);
55  R.getAxis(vx, vy, vz);
56 }
57 
58 
59 const Vector3D &Euclid3D::getVector() const {
60  return V;
61 }
62 
63 
65  return R;
66 }
67 
68 
69 void Euclid3D::setX(double x) {
70  V.setX(x);
71 }
72 
73 
74 void Euclid3D::setY(double y) {
75  V.setY(y);
76 }
77 
78 
79 void Euclid3D::setZ(double z) {
80  V.setZ(z);
81 }
82 
83 
85  if(! v.isZero()) is_identity = false;
86  V = v;
87 }
88 
89 
91  if(! rot.isIdentity()) is_identity = false;
92  R = rot;
93 }
94 
95 
96 Euclid3D Euclid3D::dot(const Euclid3D &rhs) const {
97  Euclid3D result(*this);
98  return result.dotBy(rhs);
99 }
100 
101 
102 const Euclid3D &Euclid3D::dotBy(const Euclid3D &rhs) {
103  V += R * rhs.V;
104  R *= rhs.R;
105  if(! rhs.is_identity) is_identity = false;
106  return *this;
107 }
108 
109 
111  Euclid3D result(*this);
112  return result.dotBy(rhs);
113 }
114 
115 
117  return dotBy(rhs);
118 }
119 
120 
122  Rotation3D rot = R.inverse();
123  return Euclid3D(rot * (- V), rot);
124 }
125 
126 
128  return R.isIdentity();
129 }
130 
131 
133  return V.isZero() && R.isPureXRotation();
134 }
135 
136 
138  return V.isZero() && R.isPureYRotation();
139 }
140 
141 
143  return V.isZero() && R.isPureZRotation();
144 }
145 
146 
148  return Euclid3D();
149 }
150 
151 
152 Euclid3D Euclid3D::translation(double x, double y, double z) {
153  return Euclid3D(Vector3D(x, y, z), Rotation3D::Identity());
154 }
155 
156 
158  Euclid3D result = Euclid3D(Vector3D(), Rotation3D::XRotation(angle));
159  result.is_identity = angle == 0.0;
160  return result;
161 }
162 
163 
165  Euclid3D result = Euclid3D(Vector3D(), Rotation3D::YRotation(angle));
166  result.is_identity = angle == 0.0;
167  return result;
168 }
169 
170 
172  Euclid3D result = Euclid3D(Vector3D(), Rotation3D::ZRotation(angle));
173  result.is_identity = angle == 0.0;
174  return result;
175 }
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
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
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
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
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
static Rotation3D Identity()
Make identity.
Definition: Rotation3D.cpp:126
bool isIdentity() const
Test for identity.
Definition: Rotation3D.h:160
static Rotation3D ZRotation(double angle)
Make rotation.
Definition: Rotation3D.cpp:147
static Rotation3D YRotation(double angle)
Make rotation.
Definition: Rotation3D.cpp:139
Rotation3D inverse() const
Inversion.
Definition: Rotation3D.cpp:98
bool isPureXRotation() const
Test for rotation.
Definition: Rotation3D.cpp:111
Vector3D getAxis() const
Get axis vector.
Definition: Rotation3D.cpp:91
bool isPureZRotation() const
Test for rotation.
Definition: Rotation3D.cpp:121
static Rotation3D XRotation(double angle)
Make rotation.
Definition: Rotation3D.cpp:131
bool isPureYRotation() const
Test for rotation.
Definition: Rotation3D.cpp:116
A 3-dimension vector.
Definition: Vector3D.h:31
void setY(double)
Set component.
Definition: Vector3D.h:160
void setX(double)
Set component.
Definition: Vector3D.h:156
void setZ(double)
Set component.
Definition: Vector3D.h:164
void getComponents(double &x, double &y, double &z) const
Get components.
Definition: Vector3D.cpp:98
bool isZero() const
Test for zero.
Definition: Vector3D.cpp:106
Definition: Vec.h:22