Jpp
 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"
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  JQuaternion3D b(Q);
308  JQuaternion3D a;
309 
310  a.mul(*this, b.conjugate());
311 
312  static_cast<JVersor3D&>(*this) = b.mul(Q,a);
313 
314  return *this;
315  }
316 
317 
318  /**
319  * Get dot product.
320  *
321  * \param angle angle
322  * \return dot product
323  */
324  double getDot(const JAngle3D& angle) const
325  {
326  return
327  getDX() * angle.getDX() +
328  getDY() * angle.getDY() +
329  getDZ() * angle.getDZ();
330  }
331 
332 
333  /**
334  * Get dot product.
335  *
336  * \param pos position
337  * \return dot product
338  */
339  double getDot(const JVector3D& pos) const
340  {
341  return
342  getDX() * pos.getX() +
343  getDY() * pos.getY() +
344  getDZ() * pos.getZ();
345  }
346 
347 
348  /**
349  * Get dot product.
350  *
351  * \param dir direction
352  * \return dot product
353  */
354  double getDot(const JVersor3Z& dir) const
355  {
356  return
357  getDX() * dir.getDX() +
358  getDY() * dir.getDY() +
359  getDZ() * dir.getDZ();
360  }
361 
362 
363  /**
364  * Read direction from input.
365  *
366  * \param in input stream
367  * \param direction direction
368  * \return input stream
369  */
370  friend inline std::istream& operator>>(std::istream& in, JDirection3D& direction)
371  {
372  in >> direction.__dx >> direction.__dy >> direction.__dz;
373 
374  return in;
375  }
376 
377 
378  /**
379  * Write direction to output.
380  *
381  * \param out output stream
382  * \param direction direction
383  * \return output stream
384  */
385  friend inline std::ostream& operator<<(std::ostream& out, const JDirection3D& direction)
386  {
387  out << direction.getDX() << ' ' << direction.getDY() << ' ' << direction.getDZ();
388 
389  return out;
390  }
391 
392 
393  /**
394  * Read direction from input.
395  *
396  * \param in reader
397  * \param direction direction
398  * \return reader
399  */
400  friend inline JReader& operator>>(JReader& in, JDirection3D& direction)
401  {
402  return in >> direction.__dx >> direction.__dy >> direction.__dz;
403  }
404 
405 
406  /**
407  * Write direction to output.
408  *
409  * \param out writer
410  * \param direction direction
411  * \return writer
412  */
413  friend inline JWriter& operator<<(JWriter& out, const JDirection3D& direction)
414  {
415  return out << direction.getDX() << direction.getDY() << direction.getDZ();
416  }
417  };
418 }
419 
420 #endif
Data structure for angles in three dimensions.
Definition: JAngle3D.hh:30
Interface for binary output.
JDirection3D()
Default constructor.
Definition: JDirection3D.hh:42
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:32
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:277
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:296
Rotation matrix.
Definition: JRotation3D.hh:108
JDirection3D(const JVector3D &pos)
Constructor.
Definition: JDirection3D.hh:72
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:166
JQuaternion3D & mul(const double factor)
Scale quaternion.
double getDY() const
Get y direction.
Definition: JVersor3Z.hh:155
Rotation around Z-axis.
Definition: JRotation3D.hh:82
double getDot(const JVersor3Z &dir) const
Get dot product.
JDirection3D(const JVersor3Z &dir)
Constructor.
Definition: JDirection3D.hh:82
Data structure for vector in three dimensions.
Definition: JVector3D.hh:32
JDirection3D & rotate(const JRotation3D &R)
Rotate.
JDirection3D & rotate(const JRotation3Y &R)
Rotate around Y-axis.
double getDY() const
Get y direction.
Definition: JVersor3D.hh:101
double getDX() const
Get x direction.
Definition: JVersor3D.hh:90
double getY() const
Get y position.
Definition: JVector3D.hh:102
Rotation around Y-axis.
Definition: JRotation3D.hh:54
JDirection3D(const JAngle3D &angle)
Constructor.
Definition: JDirection3D.hh:62
Interface for binary input.
Data structure for quaternion in three dimensions.
friend std::istream & operator>>(std::istream &in, JDirection3D &direction)
Read direction from input.
void setDirection(const JDirection3D &dir)
Set direction.
friend std::ostream & operator<<(std::ostream &out, const JDirection3D &direction)
Write direction to output.
double getDX() const
Get x direction.
Definition: JVersor3Z.hh:144
JDirection3D(const JVersor3D &dir)
Constructor.
Definition: JDirection3D.hh:52
double getX() const
Get x position.
Definition: JVector3D.hh:92
Rotation around X-axis.
Definition: JRotation3D.hh:28
friend JWriter & operator<<(JWriter &out, const JDirection3D &direction)
Write direction to output.
double getDot(const JVersor3D &versor) const
Get dot product.
Definition: JVersor3D.hh:151
double getDZ() const
Get z direction.
Definition: JVersor3Z.hh:166
Data structure for normalised vector in three dimensions.
Definition: JVersor3D.hh:23
Data structure for normalised vector in positive z-direction.
Definition: JVersor3Z.hh:36
JDirection3D & getDirection()
Get direction.
void transform(double &__x, double &__y, double &__z) const
Transform.
double getZ() const
Get z position.
Definition: JVector3D.hh:113
double getDZ() const
Get z direction.
Definition: JVersor3D.hh:112
double getDX() const
Get x direction.
Definition: JAngle3D.hh:105
JDirection3D(const double dx, const double dy, const double dz)
Constructor.
Definition: JDirection3D.hh:94
double getDZ() const
Get z direction.
Definition: JAngle3D.hh:127
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:116
JQuaternion3D & conjugate()
Conjugate quaternion.