Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
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
9#include "JLang/JManip.hh"
17
18
19/**
20 * \author mdejong
21 */
22
23namespace JGEOMETRY3D {}
24namespace JPP { using namespace JGEOMETRY3D; }
25
26namespace JGEOMETRY3D {
27
28 using JIO::JReader;
29 using JIO::JWriter;
31
32
33 /**
34 * Data structure for position in three dimensions.
35 */
37 public JVector3D
38 {
39 public:
40
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 */
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 */
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
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 vector in two dimensions.
Definition JVector2D.hh:34
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 position in three dimensions.
JPosition3D(const JVector2D &pos, const double z)
Constructor.
JPosition3D & rotate_back(const JRotation3X &R)
Rotate back around X-axis.
JPosition3D & rotate_back(const JRotation3Y &R)
Rotate back around Y-axis.
void setPosition(const JVector3D &pos)
Set position.
void transform_back(const JRotation3D &R, const JVector3D &pos)
Transform back position.
JPosition3D(const JVersor3D &dir)
Constructor.
JPosition3D & rotate_back(const JQuaternion3D &Q)
Rotate back.
double getDot(const JVersor3Z &dir) const
Get dot product.
void transform(const JRotation3D &R, const JVector3D &pos)
Transform position.
JPosition3D & rotate(const JRotation3D &R)
Rotate.
JPosition3D(const JVersor3Z &dir)
Constructor.
JPosition3D(const JVector3D &pos)
Constructor.
JPosition3D(const JAngle3D &angle)
Constructor.
JPosition3D(const double x, const double y, const double z)
Constructor.
friend JWriter & operator<<(JWriter &out, const JPosition3D &position)
Write position to output.
JPosition3D & rotate_back(const JRotation3Z &R)
Rotate back around Z-axis.
double getDot(const JAngle3D &angle) const
Get dot product.
JPosition3D & rotate(const JRotation3Z &R)
Rotate around Z-axis.
JPosition3D & rotate(const JQuaternion3D &Q)
Rotate.
JPosition3D & rotate(const JRotation3Y &R)
Rotate around Y-axis.
JPosition3D()
Default constructor.
double getDot(const JVersor3D &dir) const
Get dot product.
JPosition3D & getPosition()
Get position.
friend JReader & operator>>(JReader &in, JPosition3D &position)
Read position from input.
const JPosition3D & getPosition() const
Get position.
JPosition3D & rotate_back(const JRotation3D &R)
Rotate back.
friend std::istream & operator>>(std::istream &in, JPosition3D &position)
Read position from input.
friend std::ostream & operator<<(std::ostream &out, const JPosition3D &position)
Write position to output.
JPosition3D & rotate(const JRotation3X &R)
Rotate around X-axis.
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
JVector3D & add(const JVector3D &vector)
Add vector.
Definition JVector3D.hh:142
double getZ() const
Get z position.
Definition JVector3D.hh:115
JVector3D & transform(const JMatrix3D &T)
Transform.
Definition JVector3D.hh:206
double getDot(const JVector3D &vector) const
Get dot product.
Definition JVector3D.hh:282
JVector3D & sub(const JVector3D &vector)
Subtract vector.
Definition JVector3D.hh:158
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 getDZ() const
Get z direction.
Definition JVersor3D.hh:117
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