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