Jpp
JVersor3Z.hh
Go to the documentation of this file.
1 #ifndef __JVERSOR3Z__
2 #define __JVERSOR3Z__
3 
4 #include <istream>
5 #include <ostream>
6 #include <limits>
7 #include <cmath>
8 
9 #include "JIO/JSerialisable.hh"
10 #include "JMath/JMath.hh"
11 #include "JGeometry2D/JVersor2D.hh"
12 #include "JGeometry3D/JAngle3D.hh"
13 #include "JGeometry3D/JVector3D.hh"
14 #include "JGeometry3D/JVersor3D.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;
29 
30 
31  /**
32  * Data structure for normalised vector in positive z-direction.
33  * The member methods getDX() and getDY() refer to the corresponding direction cosines.
34  * Note that the direction cosines may have any value.
35  * The method getDZ() will simply return 0 if the sum of the squares of the direction cosines is larger than 1.
36  */
37  class JVersor3Z :
38  public JMATH::JMath<JVersor3Z>
39  {
40  public:
41  /**
42  * Default constructor.
43  */
45  __dx(0.0),
46  __dy(0.0)
47  {}
48 
49 
50  /**
51  * Constructor.
52  *
53  * \param dir direction cosines
54  */
55  JVersor3Z(const JVersor2D& dir) :
56  __dx(dir.getDX()),
57  __dy(dir.getDY())
58  {}
59 
60 
61  /**
62  * Constructor.
63  *
64  * \param dx direction cosine dx/dz
65  * \param dy direction cosine dy/dz
66  */
67  JVersor3Z(const double dx,
68  const double dy) :
69  __dx(dx),
70  __dy(dy)
71  {}
72 
73 
74  /**
75  * Get direction.
76  *
77  * \return direction
78  */
79  const JVersor3Z& getDirection() const
80  {
81  return static_cast<const JVersor3Z&>(*this);
82  }
83 
84 
85  /**
86  * Get direction.
87  *
88  * \return direction
89  */
91  {
92  return static_cast<JVersor3Z&>(*this);
93  }
94 
95 
96  /**
97  * Set direction.
98  *
99  * \param direction direction
100  */
101  void setDirection(const JVersor3Z& direction)
102  {
103  static_cast<JVersor3Z&>(*this) = direction;
104  }
105 
106 
107  /**
108  * Get angle.
109  *
110  * \return angle
111  */
112  operator JAngle3D() const
113  {
114  return JAngle3D(getDX(), getDY(), getDZ());
115  }
116 
117 
118  /**
119  * Type conversion operator.
120  *
121  * \return position
122  */
123  operator JVector3D() const
124  {
125  return JVector3D(getDX(), getDY(), getDZ());
126  }
127 
128 
129  /**
130  * Type conversion operator.
131  *
132  * \return direction
133  */
134  operator JVersor3D() const
135  {
136  return JVersor3D(getDX(), getDY(), getDZ());
137  }
138 
139 
140  /**
141  * Get x direction.
142  *
143  * \return x direction
144  */
145  double getDX() const
146  {
147  return __dx;
148  }
149 
150 
151  /**
152  * Get y direction.
153  *
154  * \return y direction
155  */
156  double getDY() const
157  {
158  return __dy;
159  }
160 
161 
162  /**
163  * Get z direction.
164  *
165  * \return z direction
166  */
167  double getDZ() const
168  {
169  const double v = getDX()*getDX() + getDY()*getDY();
170 
171  if (v <= 1.0)
172  return sqrt(1.0 - v);
173  else
174  return 0.0;
175  }
176 
177 
178  /**
179  * Prefix unary minus.
180  *
181  * \return this versor
182  */
184  {
185  __dx = -__dx;
186  __dy = -__dy;
187 
188  return *this;
189  }
190 
191 
192  /**
193  * Addition operator.
194  *
195  * \param value versor
196  * \return this versor
197  */
198  JVersor3Z& add(const JVersor3Z& value)
199  {
200  __dx += value.getDX();
201  __dy += value.getDY();
202 
203  return *this;
204  }
205 
206 
207  /**
208  * Subtraction operator.
209  *
210  * \param value versor
211  * \return this versor
212  */
213  JVersor3Z& sub(const JVersor3Z& value)
214  {
215  __dx -= value.getDX();
216  __dy -= value.getDY();
217 
218  return *this;
219  }
220 
221 
222  /**
223  * Multiplication operator.
224  *
225  * \param value multiplication factor
226  * \return this versor
227  */
228  JVersor3Z& mul(const double value)
229  {
230  __dx *= value;
231  __dy *= value;
232 
233  return *this;
234  }
235 
236 
237  /**
238  * Division operator.
239  *
240  * \param value multiplication factor
241  * \return this versor
242  */
243  JVersor3Z& div(const double value)
244  {
245  __dx /= value;
246  __dy /= value;
247 
248  return *this;
249  }
250 
251 
252  /**
253  * Check equality.
254  *
255  * \param versor versor
256  * \return true if versors are equal; else false
257  */
258  bool equals(const JVersor3D& versor,
259  const double precision = std::numeric_limits<double>::min()) const
260  {
261  return (fabs(getDX() - versor.getDX()) <= precision &&
262  fabs(getDY() - versor.getDY()) <= precision);
263  }
264 
265 
266  /**
267  * Get dot product.
268  *
269  * \param dir direction
270  * \return dot product
271  */
272  double getDot(const JVersor3Z& dir) const
273  {
274  return
275  getDX() * dir.getDX() +
276  getDY() * dir.getDY() +
277  getDZ() * dir.getDZ();
278  }
279 
280 
281  /**
282  * Get dot product.
283  *
284  * \param angle angle
285  * \return dot product
286  */
287  double getDot(const JAngle3D& angle) const
288  {
289  return
290  getDX() * angle.getDX() +
291  getDY() * angle.getDY() +
292  getDZ() * angle.getDZ();
293  }
294 
295 
296  /**
297  * Get dot product.
298  *
299  * \param pos position
300  * \return dot product
301  */
302  double getDot(const JVector3D& pos) const
303  {
304  return
305  getDX() * pos.getX() +
306  getDY() * pos.getY() +
307  getDZ() * pos.getZ();
308  }
309 
310 
311  /**
312  * Get dot product.
313  *
314  * \param dir direction
315  * \return dot product
316  */
317  double getDot(const JVersor3D& dir) const
318  {
319  return
320  getDX() * dir.getDX() +
321  getDY() * dir.getDY() +
322  getDZ() * dir.getDZ();
323  }
324 
325 
326  /**
327  * Read versor from input.
328  *
329  * \param in input stream
330  * \param versor versor
331  * \return input stream
332  */
333  friend inline std::istream& operator>>(std::istream& in, JVersor3Z& versor)
334  {
335  return in >> versor.__dx >> versor.__dy;
336  }
337 
338 
339  /**
340  * Write versor to output.
341  *
342  * \param out output stream
343  * \param versor versor
344  * \return output stream
345  */
346  friend inline std::ostream& operator<<(std::ostream& out, const JVersor3Z& versor)
347  {
348  return out << versor.getDX() << ' ' << versor.getDY();
349  }
350 
351 
352  /**
353  * Read versor from input.
354  *
355  * \param in reader
356  * \param versor versor
357  * \return reader
358  */
359  friend inline JReader& operator>>(JReader& in, JVersor3Z& versor)
360  {
361  return in >> versor.__dx >> versor.__dy;
362  }
363 
364 
365  /**
366  * Write versor to output.
367  *
368  * \param out writer
369  * \param versor versor
370  * \return writer
371  */
372  friend inline JWriter& operator<<(JWriter& out, const JVersor3Z& versor)
373  {
374  return out << versor.__dx << versor.__dy;
375  }
376 
377  protected:
378  double __dx;
379  double __dy;
380  };
381 }
382 
383 #endif
JGEOMETRY3D::JVersor3D::getDZ
double getDZ() const
Get z direction.
Definition: JVersor3D.hh:113
JGEOMETRY3D::JVersor3Z::negate
JVersor3Z & negate()
Prefix unary minus.
Definition: JVersor3Z.hh:183
JIO::JReader
Interface for binary input.
Definition: JSerialisable.hh:62
JVector3D.hh
JGEOMETRY3D::JVersor3Z::div
JVersor3Z & div(const double value)
Division operator.
Definition: JVersor3Z.hh:243
JGEOMETRY3D::JVersor3Z::equals
bool equals(const JVersor3D &versor, const double precision=std::numeric_limits< double >::min()) const
Check equality.
Definition: JVersor3Z.hh:258
JGEOMETRY3D::JVersor3Z::operator>>
friend std::istream & operator>>(std::istream &in, JVersor3Z &versor)
Read versor from input.
Definition: JVersor3Z.hh:333
JGEOMETRY3D::JVersor3Z
Data structure for normalised vector in positive z-direction.
Definition: JVersor3Z.hh:37
JGEOMETRY3D::JVersor3Z::setDirection
void setDirection(const JVersor3Z &direction)
Set direction.
Definition: JVersor3Z.hh:101
JGEOMETRY3D::JVector3D::getZ
double getZ() const
Get z position.
Definition: JVector3D.hh:114
JGEOMETRY3D::JVersor3Z::add
JVersor3Z & add(const JVersor3Z &value)
Addition operator.
Definition: JVersor3Z.hh:198
JGEOMETRY3D::JVersor3Z::getDot
double getDot(const JVersor3Z &dir) const
Get dot product.
Definition: JVersor3Z.hh:272
JGEOMETRY3D::JVersor3Z::mul
JVersor3Z & mul(const double value)
Multiplication operator.
Definition: JVersor3Z.hh:228
JGEOMETRY3D::JVersor3Z::JVersor3Z
JVersor3Z()
Default constructor.
Definition: JVersor3Z.hh:44
JGEOMETRY3D::JVersor3D
Data structure for normalised vector in three dimensions.
Definition: JVersor3D.hh:23
JGEOMETRY3D::JVersor3Z::operator>>
friend JReader & operator>>(JReader &in, JVersor3Z &versor)
Read versor from input.
Definition: JVersor3Z.hh:359
JMATH::JMath
Auxiliary base class for aritmetic operations of derived class types.
Definition: JMath.hh:26
JGEOMETRY3D::JVersor3Z::JVersor3Z
JVersor3Z(const double dx, const double dy)
Constructor.
Definition: JVersor3Z.hh:67
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JGEOMETRY3D::JVersor3Z::__dx
double __dx
Definition: JVersor3Z.hh:378
JVersor2D.hh
JGEOMETRY3D::JVector3D
Data structure for vector in three dimensions.
Definition: JVector3D.hh:33
JSerialisable.hh
JGEOMETRY3D::JVersor3Z::getDot
double getDot(const JVector3D &pos) const
Get dot product.
Definition: JVersor3Z.hh:302
JIO::JWriter
Interface for binary output.
Definition: JSerialisable.hh:130
JAngle3D.hh
JGEOMETRY3D::JVersor3Z::getDot
double getDot(const JVersor3D &dir) const
Get dot product.
Definition: JVersor3Z.hh:317
JGEOMETRY3D::JAngle3D::getDX
double getDX() const
Get x direction.
Definition: JAngle3D.hh:106
JGEOMETRY3D::JVersor3D::getDX
double getDX() const
Get x direction.
Definition: JVersor3D.hh:91
JGEOMETRY3D::JVersor3Z::sub
JVersor3Z & sub(const JVersor3Z &value)
Subtraction operator.
Definition: JVersor3Z.hh:213
JGEOMETRY3D::JVersor3D::getDY
double getDY() const
Get y direction.
Definition: JVersor3D.hh:102
JTOOLS::v
data_type v[N+1][M+1]
Definition: JPolint.hh:707
JMath.hh
JGEOMETRY3D::JVersor3Z::operator<<
friend JWriter & operator<<(JWriter &out, const JVersor3Z &versor)
Write versor to output.
Definition: JVersor3Z.hh:372
JGEOMETRY3D::JAngle3D
Data structure for angles in three dimensions.
Definition: JAngle3D.hh:31
JGEOMETRY3D::JAngle3D::getDZ
double getDZ() const
Get z direction.
Definition: JAngle3D.hh:128
JGEOMETRY3D::JVersor3Z::getDirection
const JVersor3Z & getDirection() const
Get direction.
Definition: JVersor3Z.hh:79
JGEOMETRY3D::JVector3D::getY
double getY() const
Get y position.
Definition: JVector3D.hh:103
JGEOMETRY3D::JAngle3D::getDY
double getDY() const
Get y direction.
Definition: JAngle3D.hh:117
JGEOMETRY3D::JVersor3Z::getDY
double getDY() const
Get y direction.
Definition: JVersor3Z.hh:156
JGEOMETRY3D
Auxiliary classes and methods for 3D geometrical objects and operations.
Definition: JAngle3D.hh:18
JGEOMETRY3D::JVersor3Z::getDot
double getDot(const JAngle3D &angle) const
Get dot product.
Definition: JVersor3Z.hh:287
JGEOMETRY3D::JVersor3Z::JVersor3Z
JVersor3Z(const JVersor2D &dir)
Constructor.
Definition: JVersor3Z.hh:55
JGEOMETRY2D::JVersor2D
Data structure for normalised vector in two dimensions.
Definition: JVersor2D.hh:20
JGEOMETRY3D::JVector3D::getX
double getX() const
Get x position.
Definition: JVector3D.hh:93
JVersor3D.hh
JGEOMETRY3D::JVersor3Z::getDirection
JVersor3Z & getDirection()
Get direction.
Definition: JVersor3Z.hh:90
JGEOMETRY3D::JVersor3Z::operator<<
friend std::ostream & operator<<(std::ostream &out, const JVersor3Z &versor)
Write versor to output.
Definition: JVersor3Z.hh:346
JGEOMETRY3D::JVersor3Z::getDZ
double getDZ() const
Get z direction.
Definition: JVersor3Z.hh:167
JGEOMETRY3D::JVersor3Z::__dy
double __dy
Definition: JVersor3Z.hh:379
JGEOMETRY3D::JVersor3Z::getDX
double getDX() const
Get x direction.
Definition: JVersor3Z.hh:145