Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JDirection3D.hh
Go to the documentation of this file.
1#ifndef __JDIRECTION3D__
2#define __JDIRECTION3D__
3
4#include <istream>
5#include <ostream>
6
8#include "JLang/JManip.hh"
15
16
17/**
18 * \author mdejong
19 */
20
21namespace JGEOMETRY3D {}
22namespace JPP { using namespace JGEOMETRY3D; }
23
24namespace JGEOMETRY3D {
25
26 using JIO::JReader;
27 using JIO::JWriter;
28
29
30 /**
31 * Data structure for direction in three dimensions.
32 */
34 public JVersor3D
35 {
36 public:
37
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 */
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 {
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 {
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 {
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 {
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 {
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
I/O manipulators.
JFormat_t & getFormat()
Get format for given type.
Definition JManip.hh:682
void rotate(double &__x, double &__y) const
Rotate.
void rotate_back(double &__x, double &__y) const
Rotate back.
Data structure for angles in three dimensions.
Definition JAngle3D.hh:35
double getDY() const
Get y direction.
Definition JAngle3D.hh:119
double getDZ() const
Get z direction.
Definition JAngle3D.hh:130
double getDX() const
Get x direction.
Definition JAngle3D.hh:108
Data structure for direction in three dimensions.
void setDirection(const JDirection3D &dir)
Set direction.
JDirection3D & rotate(const JRotation3D &R)
Rotate.
JDirection3D & rotate(const JRotation3Y &R)
Rotate around Y-axis.
JDirection3D & rotate_back(const JRotation3Y &R)
Rotate back around Y-axis.
double getDot(const JVector3D &pos) const
Get dot product.
JDirection3D & rotate_back(const JRotation3Z &R)
Rotate back around Z-axis.
friend std::ostream & operator<<(std::ostream &out, const JDirection3D &direction)
Write direction to output.
JDirection3D & transform(const JMatrix3D &T)
Transform.
JDirection3D(const JAngle3D &angle)
Constructor.
JDirection3D(const double dx, const double dy, const double dz)
Constructor.
friend JReader & operator>>(JReader &in, JDirection3D &direction)
Read direction from input.
JDirection3D(const JVector3D &pos)
Constructor.
JDirection3D(const JVersor3Z &dir)
Constructor.
JDirection3D & rotate_back(const JRotation3X &R)
Rotate back around X-axis.
JDirection3D & rotate(const JRotation3X &R)
Rotate around X-axis.
JDirection3D()
Default constructor.
JDirection3D(const JVersor3D &dir)
Constructor.
JDirection3D & rotate_back(const JRotation3D &R)
Rotate back.
JDirection3D & rotate(const JQuaternion3D &Q)
Rotate.
JDirection3D & rotate_back(const JQuaternion3D &Q)
Rotate back.
const JDirection3D & getDirection() const
Get direction.
double getDot(const JAngle3D &angle) const
Get dot product.
double getDot(const JVersor3Z &dir) const
Get dot product.
friend JWriter & operator<<(JWriter &out, const JDirection3D &direction)
Write direction to output.
JDirection3D & getDirection()
Get direction.
JDirection3D & rotate(const JRotation3Z &R)
Rotate around Z-axis.
friend std::istream & operator>>(std::istream &in, JDirection3D &direction)
Read direction from input.
Data structure for unit quaternion in three dimensions.
void rotate(double &__x, double &__y, double &__z) const
Rotate.
void rotate_back(double &__x, double &__y, double &__z) const
Rotate back.
void rotate_back(double &__x, double &__y, double &__z) const
Rotate back.
void rotate(double &__x, double &__y, double &__z) const
Rotate.
Rotation around X-axis.
Rotation around Y-axis.
Rotation around Z-axis.
Data structure for vector in three dimensions.
Definition JVector3D.hh:36
double getY() const
Get y position.
Definition JVector3D.hh:104
double getZ() const
Get z position.
Definition JVector3D.hh:115
double getX() const
Get x position.
Definition JVector3D.hh:94
Data structure for normalised vector in three dimensions.
Definition JVersor3D.hh:28
double getDY() const
Get y direction.
Definition JVersor3D.hh:106
double getDX() const
Get x direction.
Definition JVersor3D.hh:95
double getDot(const JVersor3D &versor) const
Get dot product.
Definition JVersor3D.hh:156
double getDZ() const
Get z direction.
Definition JVersor3D.hh:117
JVersor3D & normalise()
Normalise versor.
Definition JVersor3D.hh:192
Data structure for normalised vector in positive z-direction.
Definition JVersor3Z.hh:41
double getDZ() const
Get z direction.
Definition JVersor3Z.hh:169
double getDY() const
Get y direction.
Definition JVersor3Z.hh:158
double getDX() const
Get x direction.
Definition JVersor3Z.hh:147
Interface for binary input.
Interface for binary output.
Auxiliary classes and methods for 3D geometrical objects and operations.
Definition JAngle3D.hh:19
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Data structure for format specifications.
Definition JManip.hh:524
Auxiliary class to temporarily define format specifications.
Definition JManip.hh:636