Jpp  17.3.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JAxis3D.hh
Go to the documentation of this file.
1 #ifndef __JAXIS3D__
2 #define __JAXIS3D__
3 
4 #include <istream>
5 #include <ostream>
6 #include <cmath>
7 
8 #include "JIO/JSerialisable.hh"
10 #include "JGeometry3D/JVersor3D.hh"
11 #include "JGeometry3D/JVersor3Z.hh"
18 
19 
20 /**
21  * \author mdejong
22  */
23 
24 namespace JGEOMETRY3D {}
25 namespace JPP { using namespace JGEOMETRY3D; }
26 
27 namespace JGEOMETRY3D {
28 
29  using JIO::JReader;
30  using JIO::JWriter;
31 
32 
33  /**
34  * Axis object.
35  *
36  * An axis object consists of a position and a direction.
37  */
38  class JAxis3D :
39  public JPosition3D,
40  public JDirection3D
41  {
42  public:
43 
45 
46 
47  /**
48  * Default constructor.
49  */
50  JAxis3D() :
51  JPosition3D (),
52  JDirection3D()
53  {}
54 
55 
56  /**
57  * Constructor.
58  *
59  * \param pos position
60  * \param dir direction
61  */
62  JAxis3D(const JVector3D& pos,
63  const JVersor3D& dir) :
64  JPosition3D (pos),
65  JDirection3D(dir)
66  {}
67 
68 
69  /**
70  * Constructor.
71  *
72  * \param pos position
73  * \param dir direction
74  */
75  JAxis3D(const JVector3D& pos,
76  const JVersor3Z& dir) :
77  JPosition3D (pos),
78  JDirection3D(dir)
79  {}
80 
81 
82  /**
83  * Constructor.
84  *
85  * \param segment line segment
86  */
87  JAxis3D(const JSegment3D& segment) :
88  JPosition3D (segment.first),
89  JDirection3D(segment.second - segment.first)
90  {}
91 
92 
93  /**
94  * Get axis.
95  *
96  * \return axis
97  */
98  const JAxis3D& getAxis() const
99  {
100  return *this;
101  }
102 
103 
104  /**
105  * Set axis.
106  *
107  * \param axis axis
108  */
109  void setAxis(const JAxis3D& axis)
110  {
111  *this = axis;
112  }
113 
114 
115  /**
116  * Negate axis.
117  *
118  * \return this axis
119  */
121  {
122  static_cast<JPosition3D&> (*this).negate();
123  static_cast<JDirection3D&>(*this).negate();
124 
125  return *this;
126  }
127 
128 
129  /**
130  * Move vertex along this axis.
131  *
132  * \param step step
133  */
134  void move(const double step)
135  {
136  getPosition() += step * JPosition3D(getDirection());
137  }
138 
139 
140  /**
141  * Get longitudinal position along axis of position of closest approach with given position.
142  *
143  * \param pos position
144  * \return longitudinal position
145  */
146  inline double getIntersection(const JVector3D& pos) const
147  {
148  JPosition3D D(pos);
149 
150  D.sub(this->getPosition());
151 
152  return D.getDot(this->getDirection());
153  }
154 
155 
156  /**
157  * Get longitudinal position along axis of position of closest approach with given axis.\n
158  * If the axes are paralel, this position corresponds to the vertex of the given axis.
159  *
160  * \param axis axis
161  * \param precision precision
162  * \return longitudinal position
163  */
164  double getIntersection(const JAxis3D& axis, const double precision = 1.0e-8) const
165  {
166  JPosition3D pos(getPosition ());
167  JDirection3D dir(getDirection());
168 
169  const JRotation3D R(axis.getDirection());
170 
171  // offset this position with position of given axis
172 
173  pos.sub(axis.getPosition());
174 
175  // rotate along given axis
176 
177  pos.rotate(R);
178  dir.rotate(R);
179 
180  // longitudinal position at minimal distance of approach
181 
182  const double alpha = pos.getX() * dir.getDX() + pos.getY() * dir.getDY();
183  const double beta = dir.getDX() * dir.getDX() + dir.getDY() * dir.getDY();
184 
185  return (fabs(beta) > precision ? -alpha/beta : -pos.getZ());
186  }
187 
188 
189  /**
190  * Get distance squared.
191  *
192  * \param pos position
193  * \return square of distance
194  */
195  inline double getDistanceSquared(const JVector3D& pos) const
196  {
197  JPosition3D D(pos);
198 
199  D.sub(this->getPosition());
200 
201  const double dz = D.getDot(this->getDirection());
202 
203  return D.getLengthSquared() - dz*dz;
204  }
205 
206 
207  /**
208  * Get distance.
209  *
210  * \param pos osition
211  * \return distance
212  */
213  inline double getDistance(const JVector3D& pos) const
214  {
215  return sqrt(this->getDistanceSquared(pos));
216  }
217 
218 
219  /**
220  * Rotate axis.
221  *
222  * \param R rotation matrix
223  * \return this axis
224  */
226  {
227  static_cast<JPosition3D&> (*this).rotate(R);
228  static_cast<JDirection3D&>(*this).rotate(R);
229 
230  return *this;
231  }
232 
233 
234  /**
235  * Rotate back axis.
236  *
237  * \param R rotation matrix
238  * \return this axis
239  */
241  {
242  static_cast<JPosition3D&> (*this).rotate_back(R);
243  static_cast<JDirection3D&>(*this).rotate_back(R);
244 
245  return *this;
246  }
247 
248 
249  /**
250  * Rotate around X-axis.
251  *
252  * \param R rotation matrix
253  * \return this axis
254  */
256  {
257  static_cast<JPosition3D&> (*this).rotate(R);
258  static_cast<JDirection3D&>(*this).rotate(R);
259 
260  return *this;
261  }
262 
263 
264  /**
265  * Rotate back around X-axis.
266  *
267  * \param R rotation matrix
268  * \return this axis
269  */
271  {
272  static_cast<JPosition3D&> (*this).rotate_back(R);
273  static_cast<JDirection3D&>(*this).rotate_back(R);
274 
275  return *this;
276  }
277 
278 
279  /**
280  * Rotate around Y-axis.
281  *
282  * \param R rotation matrix
283  * \return this axis
284  */
286  {
287  static_cast<JPosition3D&> (*this).rotate(R);
288  static_cast<JDirection3D&>(*this).rotate(R);
289 
290  return *this;
291  }
292 
293 
294  /**
295  * Rotate back around Y-axis.
296  *
297  * \param R rotation matrix
298  * \return this axis
299  */
301  {
302  static_cast<JPosition3D&> (*this).rotate_back(R);
303  static_cast<JDirection3D&>(*this).rotate_back(R);
304 
305  return *this;
306  }
307 
308 
309  /**
310  * Rotate around Z-axis.
311  *
312  * \param R rotation matrix
313  * \return this axis
314  */
316  {
317  static_cast<JPosition3D&> (*this).rotate(R);
318  static_cast<JDirection3D&>(*this).rotate(R);
319 
320  return *this;
321  }
322 
323 
324  /**
325  * Rotate back around Z-axis.
326  *
327  * \param R rotation matrix
328  * \return his axis
329  */
331  {
332  static_cast<JPosition3D&> (*this).rotate_back(R);
333  static_cast<JDirection3D&>(*this).rotate_back(R);
334 
335  return *this;
336  }
337 
338 
339  /**
340  * Rotate axis.
341  *
342  * \param Q quaternion
343  * \return this axis
344  */
346  {
347  static_cast<JPosition3D&> (*this).rotate(Q);
348  static_cast<JDirection3D&>(*this).rotate(Q);
349 
350  return *this;
351  }
352 
353 
354  /**
355  * Transform axis to reference frame of given axis.
356  *
357  * \param axis axis
358  */
359  void transform(const JAxis3D& axis)
360  {
361  JRotation3D R (axis.getDirection());
362  JPosition3D pos(axis.getPosition ());
363 
364  transform(R, pos.rotate(R));
365  }
366 
367 
368  /**
369  * Transform axis.
370  *
371  * The final position and direction are obtained as follows:
372  * -# rotation of the position and the direction according rotation matrix (\c R);
373  * -# offset position with position of origin in rotated system (\c pos);
374  * -# rotation of position and direction around z-axis, such that final position is in x-z plane;
375  *
376  * \param R rotation matrix
377  * \param pos position of origin
378  */
379  void transform(const JRotation3D& R,
380  const JVector3D& pos)
381  {
382  JPosition3D& u = getPosition ();
384 
385  // rotate axis to system such that direction is along z-axis
386 
387  u.rotate(R);
388  v.rotate(R);
389 
390  // offset with respect to origin
391 
392  u.sub(pos);
393 
394  // rotate axis to x-z plane such that position is in x-z plane
395 
396  const double phi = atan2(u.getY(), u.getX());
397 
398  const JRotation3Z r(-phi);
399 
400  u.rotate(r);
401  v.rotate(r);
402  }
403 
404 
405  /**
406  * Transform back axis.
407  *
408  * The final position and direction are obtained as follows:
409  * -# offset position with position pos;
410  * -# rotation of position and direction according matrix R;
411  *
412  * \param R rotation matrix
413  * \param pos position of origin (before rotation)
414  */
416  const JVector3D& pos)
417  {
418  JPosition3D& u = getPosition ();
420 
421  // offset with respect to origin
422 
423  u.add(pos);
424 
425  // rotate back axis to system with original particle direction
426 
427  u.rotate_back(R);
428  v.rotate_back(R);
429  }
430 
431 
432  /**
433  * Transform axis.
434  *
435  * \param T transformation
436  */
438  {
440  }
441 
442 
443  /**
444  * Transform back axis.
445  *
446  * \param T transformation
447  */
449  {
451  }
452 
453 
454  /**
455  * Read axis from input.
456  *
457  * \param in input stream
458  * \param axis axis
459  * \return input stream
460  */
461  friend inline std::istream& operator>>(std::istream& in, JAxis3D& axis)
462  {
463  in >> static_cast<JPosition3D&> (axis);
464  in >> static_cast<JDirection3D&>(axis);
465 
466  return in;
467  }
468 
469 
470  /**
471  * Write axis to output.
472  *
473  * \param out output stream
474  * \param axis axis
475  * \return output stream
476  */
477  friend inline std::ostream& operator<<(std::ostream& out, const JAxis3D& axis)
478  {
479  out << static_cast<const JPosition3D&> (axis);
480  out << ' ';
481  out << static_cast<const JDirection3D&>(axis);
482 
483  return out;
484  }
485 
486 
487  /**
488  * Read axis from input.
489  *
490  * \param in reader
491  * \param axis axis
492  * \return reader
493  */
494  friend inline JReader& operator>>(JReader& in, JAxis3D& axis)
495  {
496  in >> static_cast<JPosition3D&> (axis);
497  in >> static_cast<JDirection3D&>(axis);
498 
499  return in;
500  }
501 
502 
503  /**
504  * Write axis to output.
505  *
506  * \param out writer
507  * \param axis axis
508  * \return writer
509  */
510  friend inline JWriter& operator<<(JWriter& out, const JAxis3D& axis)
511  {
512  out << static_cast<const JPosition3D&> (axis);
513  out << static_cast<const JDirection3D&>(axis);
514 
515  return out;
516  }
517  };
518 }
519 
520 #endif
Interface for binary output.
Q(UTCMax_s-UTCMin_s)-livetime_s
double getDot(const JAngle3D &angle) const
Get dot product.
Definition: JPosition3D.hh:378
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:33
JDirection3D & rotate_back(const JRotation3D &R)
Rotate back.
double getDistanceSquared(const JVector3D &pos) const
Get distance squared.
Definition: JAxis3D.hh:195
JPosition3D & rotate_back(const JRotation3D &R)
Rotate back.
Definition: JPosition3D.hh:200
JAxis3D & rotate(const JRotation3Y &R)
Rotate around Y-axis.
Definition: JAxis3D.hh:285
void transform(const JRotation3D &R, const JVector3D &pos)
Transform axis.
Definition: JAxis3D.hh:379
void transform_back(const JTransformation3D &T)
Transform back axis.
Definition: JAxis3D.hh:448
const JDirection3D & getDirection() const
Get direction.
double getIntersection(const JVector3D &pos) const
Get longitudinal position along axis of position of closest approach with given position.
Definition: JAxis3D.hh:146
JAxis3D()
Default constructor.
Definition: JAxis3D.hh:50
friend JReader & operator>>(JReader &in, JAxis3D &axis)
Read axis from input.
Definition: JAxis3D.hh:494
Rotation matrix.
Definition: JRotation3D.hh:111
double getIntersection(const JAxis3D &axis, const double precision=1.0e-8) const
Get longitudinal position along axis of position of closest approach with given axis.
Definition: JAxis3D.hh:164
void setAxis(const JAxis3D &axis)
Set axis.
Definition: JAxis3D.hh:109
JAxis3D & rotate_back(const JRotation3X &R)
Rotate back around X-axis.
Definition: JAxis3D.hh:270
void move(const double step)
Move vertex along this axis.
Definition: JAxis3D.hh:134
data_type r[M+1]
Definition: JPolint.hh:779
double getDot(const JAngle3D &angle) const
Get dot product.
JAxis3D & rotate_back(const JRotation3Y &R)
Rotate back around Y-axis.
Definition: JAxis3D.hh:300
void transform(const JAxis3D &axis)
Transform axis to reference frame of given axis.
Definition: JAxis3D.hh:359
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
JAxis3D(const JVector3D &pos, const JVersor3Z &dir)
Constructor.
Definition: JAxis3D.hh:75
Axis object.
Definition: JAxis3D.hh:38
Rotation around Z-axis.
Definition: JRotation3D.hh:85
void transform_back(const JRotation3D &R, const JVector3D &pos)
Transform back axis.
Definition: JAxis3D.hh:415
JAxis3D & rotate(const JRotation3Z &R)
Rotate around Z-axis.
Definition: JAxis3D.hh:315
JAxis3D & rotate(const JRotation3X &R)
Rotate around X-axis.
Definition: JAxis3D.hh:255
JVector3D & sub(const JVector3D &vector)
Subtract vector.
Definition: JVector3D.hh:158
JAxis3D & rotate(const JRotation3D &R)
Rotate axis.
Definition: JAxis3D.hh:225
JVersor3D & negate()
Negate versor.
Definition: JVersor3D.hh:64
Data structure for vector in three dimensions.
Definition: JVector3D.hh:34
JDirection3D & rotate(const JRotation3D &R)
Rotate.
friend JWriter & operator<<(JWriter &out, const JAxis3D &axis)
Write axis to output.
Definition: JAxis3D.hh:510
friend std::istream & operator>>(std::istream &in, JAxis3D &axis)
Read axis from input.
Definition: JAxis3D.hh:461
double getDY() const
Get y direction.
Definition: JVersor3D.hh:106
double getDX() const
Get x direction.
Definition: JVersor3D.hh:95
do set_variable OUTPUT_DIRECTORY $WORKDIR T
JAxis3D & rotate_back(const JRotation3D &R)
Rotate back axis.
Definition: JAxis3D.hh:240
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
Line segment in two dimensions.
Definition: JSegment3D.hh:33
double getLengthSquared() const
Get length squared.
Definition: JVector3D.hh:235
void transform(const JTransformation3D &T)
Transform axis.
Definition: JAxis3D.hh:437
const JRotation3D & getRotation() const
Get rotation.
Definition: JRotation3D.hh:272
Data structure for unit quaternion in three dimensions.
JAxis3D & rotate(const JQuaternion3D &Q)
Rotate axis.
Definition: JAxis3D.hh:345
then JCookie sh JDataQuality D $DETECTOR_ID R
Definition: JDataQuality.sh:41
double getDistance(const JVector3D &pos) const
Get distance.
Definition: JAxis3D.hh:213
JPosition3D()
Default constructor.
Definition: JPosition3D.hh:48
JAxis3D(const JVector3D &pos, const JVersor3D &dir)
Constructor.
Definition: JAxis3D.hh:62
JAxis3D(const JSegment3D &segment)
Constructor.
Definition: JAxis3D.hh:87
const JAxis3D & getAxis() const
Get axis.
Definition: JAxis3D.hh:98
double getX() const
Get x position.
Definition: JVector3D.hh:94
Rotation around X-axis.
Definition: JRotation3D.hh:31
JAxis3D & negate()
Negate axis.
Definition: JAxis3D.hh:120
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
JVector3D & negate()
Negate vector.
Definition: JVector3D.hh:126
data_type v[N+1][M+1]
Definition: JPolint.hh:777
Data structure for normalised vector in three dimensions.
Definition: JVersor3D.hh:26
double u[N+1]
Definition: JPolint.hh:776
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 JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
JPosition3D & rotate(const JRotation3D &R)
Rotate.
Definition: JPosition3D.hh:186
JAxis3D & rotate_back(const JRotation3Z &R)
Rotate back around Z-axis.
Definition: JAxis3D.hh:330
do echo Generating $dir eval D
Definition: JDrawLED.sh:53
double getZ() const
Get z position.
Definition: JVector3D.hh:115
JVector3D & add(const JVector3D &vector)
Add vector.
Definition: JVector3D.hh:142
friend std::ostream & operator<<(std::ostream &out, const JAxis3D &axis)
Write axis to output.
Definition: JAxis3D.hh:477