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