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