Jpp
JDirection3D.hh
Go to the documentation of this file.
1 #ifndef __JDIRECTION3D__
2 #define __JDIRECTION3D__
3 
4 #include <istream>
5 #include <ostream>
6 
7 #include "JIO/JSerialisable.hh"
10 #include "JGeometry3D/JVector3D.hh"
11 #include "JGeometry3D/JVersor3Z.hh"
14 
15 
16 /**
17  * \author mdejong
18  */
19 
20 namespace JGEOMETRY3D {}
21 namespace JPP { using namespace JGEOMETRY3D; }
22 
23 namespace JGEOMETRY3D {
24 
25  using JIO::JReader;
26  using JIO::JWriter;
27 
28 
29  /**
30  * Data structure for direction in three dimensions.
31  */
32  class JDirection3D :
33  public JVersor3D
34  {
35  public:
36 
37  using JVersor3D::getDot;
38 
39  /**
40  * Default constructor.
41  */
43  JVersor3D()
44  {}
45 
46 
47  /**
48  * Constructor.
49  *
50  * \param dir direction
51  */
52  JDirection3D(const JVersor3D& dir) :
53  JVersor3D(dir)
54  {}
55 
56 
57  /**
58  * Constructor.
59  *
60  * \param angle angle
61  */
62  JDirection3D(const JAngle3D& angle) :
63  JVersor3D(angle.getDX(), angle.getDY(), angle.getDZ())
64  {}
65 
66 
67  /**
68  * Constructor.
69  *
70  * \param pos position
71  */
72  JDirection3D(const JVector3D& pos) :
73  JVersor3D(pos.getX(), pos.getY(), pos.getZ())
74  {}
75 
76 
77  /**
78  * Constructor.
79  *
80  * \param dir direction
81  */
82  JDirection3D(const JVersor3Z& dir) :
83  JVersor3D(dir.getDX(), dir.getDY(), dir.getDZ())
84  {}
85 
86 
87  /**
88  * Constructor.
89  *
90  * \param dx dx value
91  * \param dy dy value
92  * \param dz dz value
93  */
94  JDirection3D(const double dx,
95  const double dy,
96  const double dz) :
97  JVersor3D(dx, dy, dz)
98  {}
99 
100 
101  /**
102  * Get direction.
103  *
104  * \return direction
105  */
106  const JDirection3D& getDirection() const
107  {
108  return static_cast<const JDirection3D&>(*this);
109  }
110 
111 
112  /**
113  * Get direction.
114  *
115  * \return direction
116  */
118  {
119  return static_cast<JDirection3D&>(*this);
120  }
121 
122 
123  /**
124  * Set direction.
125  *
126  * \param dir direction
127  */
128  void setDirection(const JDirection3D& dir)
129  {
130  static_cast<JDirection3D&>(*this) = dir;
131  }
132 
133  /**
134  * Type conversion operator.
135  *
136  * \return angle
137  */
138  operator JAngle3D() const
139  {
140  return JAngle3D(getDX(), getDY(), getDZ());
141  }
142 
143 
144  /**
145  * Type conversion operator.
146  *
147  * \return position
148  */
149  operator JVector3D() const
150  {
151  return JVector3D(getDX(), getDY(), getDZ());
152  }
153 
154 
155  /**
156  * Transform.
157  *
158  * \param T matrix
159  * \return this direction
160  */
162  {
163  T.transform(__dx, __dy, __dz);
164 
165  normalise();
166 
167  return *this;
168  }
169 
170 
171  /**
172  * Rotate.
173  *
174  * \param R rotation matrix
175  * \return this direction
176  */
178  {
179  R.rotate(__dx, __dy, __dz);
180 
181  normalise();
182 
183  return *this;
184  }
185 
186 
187  /**
188  * Rotate back.
189  *
190  * \param R rotation matrix
191  * \return this direction
192  */
194  {
195  R.rotate_back(__dx, __dy, __dz);
196 
197  normalise();
198 
199  return *this;
200  }
201 
202 
203  /**
204  * Rotate around X-axis.
205  *
206  * \param R rotation matrix
207  * \return this direction
208  */
210  {
211  R.rotate(__dy, __dz);
212 
213  normalise();
214 
215  return *this;
216  }
217 
218 
219  /**
220  * Rotate back around X-axis.
221  *
222  * \param R rotation matrix
223  * \return this direction
224  */
226  {
227  R.rotate_back(__dy, __dz);
228 
229  normalise();
230 
231  return *this;
232  }
233 
234 
235  /**
236  * Rotate around Y-axis.
237  *
238  * \param R rotation matrix
239  * \return this direction
240  */
242  {
243  R.rotate(__dx, __dz);
244 
245  normalise();
246 
247  return *this;
248  }
249 
250 
251  /**
252  * Rotate back around Y-axis.
253  *
254  * \param R rotation matrix
255  * \return this direction
256  */
258  {
259  R.rotate_back(__dx, __dz);
260 
261  normalise();
262 
263  return *this;
264  }
265 
266 
267  /**
268  * Rotate around Z-axis.
269  *
270  * \param R rotation matrix
271  * \return this direction
272  */
274  {
275  R.rotate(__dx, __dy);
276 
277  normalise();
278 
279  return *this;
280  }
281 
282 
283  /**
284  * Rotate back around Z-axis.
285  *
286  * \param R rotation matrix
287  * \return this direction
288  */
290  {
291  R.rotate_back(__dx, __dy);
292 
293  normalise();
294 
295  return *this;
296  }
297 
298 
299  /**
300  * Rotate.
301  *
302  * \param Q quaternion
303  * \return this position
304  */
306  {
307  Q.rotate(__dx, __dy, __dz);
308 
309  return *this;
310  }
311 
312 
313  /**
314  * Rotate back.
315  *
316  * \param Q quaternion
317  * \return this position
318  */
320  {
321  Q.rotate_back(__dx, __dy, __dz);
322 
323  return *this;
324  }
325 
326 
327  /**
328  * Get dot product.
329  *
330  * \param angle angle
331  * \return dot product
332  */
333  double getDot(const JAngle3D& angle) const
334  {
335  return
336  getDX() * angle.getDX() +
337  getDY() * angle.getDY() +
338  getDZ() * angle.getDZ();
339  }
340 
341 
342  /**
343  * Get dot product.
344  *
345  * \param pos position
346  * \return dot product
347  */
348  double getDot(const JVector3D& pos) const
349  {
350  return
351  getDX() * pos.getX() +
352  getDY() * pos.getY() +
353  getDZ() * pos.getZ();
354  }
355 
356 
357  /**
358  * Get dot product.
359  *
360  * \param dir direction
361  * \return dot product
362  */
363  double getDot(const JVersor3Z& dir) const
364  {
365  return
366  getDX() * dir.getDX() +
367  getDY() * dir.getDY() +
368  getDZ() * dir.getDZ();
369  }
370 
371 
372  /**
373  * Read direction from input.
374  *
375  * \param in input stream
376  * \param direction direction
377  * \return input stream
378  */
379  friend inline std::istream& operator>>(std::istream& in, JDirection3D& direction)
380  {
381  in >> direction.__dx >> direction.__dy >> direction.__dz;
382 
383  return in;
384  }
385 
386 
387  /**
388  * Write direction to output.
389  *
390  * \param out output stream
391  * \param direction direction
392  * \return output stream
393  */
394  friend inline std::ostream& operator<<(std::ostream& out, const JDirection3D& direction)
395  {
396  out << direction.getDX() << ' ' << direction.getDY() << ' ' << direction.getDZ();
397 
398  return out;
399  }
400 
401 
402  /**
403  * Read direction from input.
404  *
405  * \param in reader
406  * \param direction direction
407  * \return reader
408  */
409  friend inline JReader& operator>>(JReader& in, JDirection3D& direction)
410  {
411  return in >> direction.__dx >> direction.__dy >> direction.__dz;
412  }
413 
414 
415  /**
416  * Write direction to output.
417  *
418  * \param out writer
419  * \param direction direction
420  * \return writer
421  */
422  friend inline JWriter& operator<<(JWriter& out, const JDirection3D& direction)
423  {
424  return out << direction.getDX() << direction.getDY() << direction.getDZ();
425  }
426  };
427 }
428 
429 #endif
JGEOMETRY3D::JVersor3D::getDZ
double getDZ() const
Get z direction.
Definition: JVersor3D.hh:114
JGEOMETRY3D::JDirection3D::rotate_back
JDirection3D & rotate_back(const JRotation3D &R)
Rotate back.
Definition: JDirection3D.hh:193
JGEOMETRY3D::JDirection3D::getDot
double getDot(const JVersor3Z &dir) const
Get dot product.
Definition: JDirection3D.hh:363
JGEOMETRY3D::JVersor3D::__dz
double __dz
Definition: JVersor3D.hh:184
JGEOMETRY2D::JRotation2D::rotate_back
void rotate_back(double &__x, double &__y) const
Rotate back.
Definition: JRotation2D.hh:112
JIO::JReader
Interface for binary input.
Definition: JSerialisable.hh:62
JVector3D.hh
JGEOMETRY3D::JRotation3X
Rotation around X-axis.
Definition: JRotation3D.hh:31
JGEOMETRY3D::JDirection3D::getDot
double getDot(const JVector3D &pos) const
Get dot product.
Definition: JDirection3D.hh:348
JGEOMETRY3D::JRotation3D::rotate
void rotate(double &__x, double &__y, double &__z) const
Rotate.
Definition: JRotation3D.hh:336
JGEOMETRY3D::JVersor3D::__dx
double __dx
Definition: JVersor3D.hh:182
JGEOMETRY3D::JDirection3D::rotate
JDirection3D & rotate(const JRotation3D &R)
Rotate.
Definition: JDirection3D.hh:177
JGEOMETRY3D::JRotation3D::rotate_back
void rotate_back(double &__x, double &__y, double &__z) const
Rotate back.
Definition: JRotation3D.hh:355
JGEOMETRY3D::JVersor3Z
Data structure for normalised vector in positive z-direction.
Definition: JVersor3Z.hh:37
JGEOMETRY3D::JQuaternion3D::rotate_back
void rotate_back(double &__x, double &__y, double &__z) const
Rotate back.
Definition: JQuaternion3D.hh:668
JGEOMETRY3D::JDirection3D::getDirection
const JDirection3D & getDirection() const
Get direction.
Definition: JDirection3D.hh:106
JGEOMETRY3D::JDirection3D::rotate
JDirection3D & rotate(const JRotation3X &R)
Rotate around X-axis.
Definition: JDirection3D.hh:209
JGEOMETRY3D::JVector3D::getZ
double getZ() const
Get z position.
Definition: JVector3D.hh:114
JMATH::JMatrix3D
3 x 3 matrix
Definition: JMath/JMatrix3D.hh:32
JGEOMETRY3D::JDirection3D::getDot
double getDot(const JAngle3D &angle) const
Get dot product.
Definition: JDirection3D.hh:333
JGEOMETRY3D::JDirection3D
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:32
JQuaternion3D.hh
JGEOMETRY3D::JVersor3D
Data structure for normalised vector in three dimensions.
Definition: JVersor3D.hh:23
JGEOMETRY3D::JDirection3D::operator<<
friend std::ostream & operator<<(std::ostream &out, const JDirection3D &direction)
Write direction to output.
Definition: JDirection3D.hh:394
JGEOMETRY3D::JDirection3D::rotate_back
JDirection3D & rotate_back(const JRotation3X &R)
Rotate back around X-axis.
Definition: JDirection3D.hh:225
JGEOMETRY3D::JDirection3D::setDirection
void setDirection(const JDirection3D &dir)
Set direction.
Definition: JDirection3D.hh:128
JGEOMETRY3D::JDirection3D::JDirection3D
JDirection3D(const JAngle3D &angle)
Constructor.
Definition: JDirection3D.hh:62
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JGEOMETRY3D::JDirection3D::operator<<
friend JWriter & operator<<(JWriter &out, const JDirection3D &direction)
Write direction to output.
Definition: JDirection3D.hh:422
JGEOMETRY3D::JVector3D
Data structure for vector in three dimensions.
Definition: JVector3D.hh:33
JGEOMETRY2D::JRotation2D::rotate
void rotate(double &__x, double &__y) const
Rotate.
Definition: JRotation2D.hh:96
JSerialisable.hh
JGEOMETRY3D::JDirection3D::rotate_back
JDirection3D & rotate_back(const JQuaternion3D &Q)
Rotate back.
Definition: JDirection3D.hh:319
JGEOMETRY3D::JDirection3D::rotate_back
JDirection3D & rotate_back(const JRotation3Z &R)
Rotate back around Z-axis.
Definition: JDirection3D.hh:289
JIO::JWriter
Interface for binary output.
Definition: JSerialisable.hh:131
JGEOMETRY3D::JDirection3D::JDirection3D
JDirection3D(const JVersor3Z &dir)
Constructor.
Definition: JDirection3D.hh:82
JAngle3D.hh
JGEOMETRY3D::JVersor3D::getDot
double getDot(const JVersor3D &versor) const
Get dot product.
Definition: JVersor3D.hh:153
JGEOMETRY3D::JAngle3D::getDX
double getDX() const
Get x direction.
Definition: JAngle3D.hh:106
JGEOMETRY3D::JVersor3D::getDX
double getDX() const
Get x direction.
Definition: JVersor3D.hh:92
JVersor3Z.hh
JGEOMETRY3D::JQuaternion3D
Data structure for quaternion in three dimensions.
Definition: JQuaternion3D.hh:240
JGEOMETRY3D::JDirection3D::rotate
JDirection3D & rotate(const JRotation3Y &R)
Rotate around Y-axis.
Definition: JDirection3D.hh:241
JGEOMETRY3D::JVersor3D::getDY
double getDY() const
Get y direction.
Definition: JVersor3D.hh:103
JGEOMETRY3D::JVersor3D::__dy
double __dy
Definition: JVersor3D.hh:183
JGEOMETRY3D::JDirection3D::JDirection3D
JDirection3D(const JVersor3D &dir)
Constructor.
Definition: JDirection3D.hh:52
JGEOMETRY3D::JRotation3Z
Rotation around Z-axis.
Definition: JRotation3D.hh:85
JGEOMETRY3D::JAngle3D
Data structure for angles in three dimensions.
Definition: JAngle3D.hh:31
JGEOMETRY3D::JAngle3D::getDZ
double getDZ() const
Get z direction.
Definition: JAngle3D.hh:128
JMATH::JMatrix3D::transform
void transform(double &__x, double &__y, double &__z) const
Transform.
Definition: JMath/JMatrix3D.hh:318
JGEOMETRY3D::JVersor3D::normalise
JVersor3D & normalise()
Normalise versor.
Definition: JVersor3D.hh:168
JGEOMETRY3D::JDirection3D::getDirection
JDirection3D & getDirection()
Get direction.
Definition: JDirection3D.hh:117
JGEOMETRY3D::JDirection3D::JDirection3D
JDirection3D()
Default constructor.
Definition: JDirection3D.hh:42
JGEOMETRY3D::JDirection3D::operator>>
friend JReader & operator>>(JReader &in, JDirection3D &direction)
Read direction from input.
Definition: JDirection3D.hh:409
JGEOMETRY3D::JDirection3D::rotate
JDirection3D & rotate(const JQuaternion3D &Q)
Rotate.
Definition: JDirection3D.hh:305
JGEOMETRY3D::JDirection3D::transform
JDirection3D & transform(const JMatrix3D &T)
Transform.
Definition: JDirection3D.hh:161
JRotation3D.hh
JGEOMETRY3D::JVector3D::getY
double getY() const
Get y position.
Definition: JVector3D.hh:103
JGEOMETRY3D::JAngle3D::getDY
double getDY() const
Get y direction.
Definition: JAngle3D.hh:117
JGEOMETRY3D::JVersor3Z::getDY
double getDY() const
Get y direction.
Definition: JVersor3Z.hh:156
JGEOMETRY3D
Auxiliary classes and methods for 3D geometrical objects and operations.
Definition: JAngle3D.hh:18
JGEOMETRY3D::JDirection3D::operator>>
friend std::istream & operator>>(std::istream &in, JDirection3D &direction)
Read direction from input.
Definition: JDirection3D.hh:379
JGEOMETRY3D::JVector3D::getX
double getX() const
Get x position.
Definition: JVector3D.hh:93
JGEOMETRY3D::JRotation3Y
Rotation around Y-axis.
Definition: JRotation3D.hh:57
JVersor3D.hh
JGEOMETRY3D::JDirection3D::rotate
JDirection3D & rotate(const JRotation3Z &R)
Rotate around Z-axis.
Definition: JDirection3D.hh:273
JGEOMETRY3D::JVersor3Z::getDZ
double getDZ() const
Get z direction.
Definition: JVersor3Z.hh:167
JGEOMETRY3D::JDirection3D::JDirection3D
JDirection3D(const double dx, const double dy, const double dz)
Constructor.
Definition: JDirection3D.hh:94
JGEOMETRY3D::JDirection3D::JDirection3D
JDirection3D(const JVector3D &pos)
Constructor.
Definition: JDirection3D.hh:72
JGEOMETRY3D::JRotation3D
Rotation matrix.
Definition: JRotation3D.hh:111
JGEOMETRY3D::JDirection3D::rotate_back
JDirection3D & rotate_back(const JRotation3Y &R)
Rotate back around Y-axis.
Definition: JDirection3D.hh:257
JGEOMETRY3D::JQuaternion3D::rotate
void rotate(double &__x, double &__y, double &__z) const
Rotate.
Definition: JQuaternion3D.hh:645
JGEOMETRY3D::JVersor3Z::getDX
double getDX() const
Get x direction.
Definition: JVersor3Z.hh:145