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  * \param precision precision
257  * \return true if versors are equal; else false
258  */
259  bool equals(const JVersor3D& versor,
260  const double precision = std::numeric_limits<double>::min()) const
261  {
262  return (fabs(getDX() - versor.getDX()) <= precision &&
263  fabs(getDY() - versor.getDY()) <= precision);
264  }
265 
266 
267  /**
268  * Get dot product.
269  *
270  * \param dir direction
271  * \return dot product
272  */
273  double getDot(const JVersor3Z& dir) const
274  {
275  return
276  getDX() * dir.getDX() +
277  getDY() * dir.getDY() +
278  getDZ() * dir.getDZ();
279  }
280 
281 
282  /**
283  * Get dot product.
284  *
285  * \param angle angle
286  * \return dot product
287  */
288  double getDot(const JAngle3D& angle) const
289  {
290  return
291  getDX() * angle.getDX() +
292  getDY() * angle.getDY() +
293  getDZ() * angle.getDZ();
294  }
295 
296 
297  /**
298  * Get dot product.
299  *
300  * \param pos position
301  * \return dot product
302  */
303  double getDot(const JVector3D& pos) const
304  {
305  return
306  getDX() * pos.getX() +
307  getDY() * pos.getY() +
308  getDZ() * pos.getZ();
309  }
310 
311 
312  /**
313  * Get dot product.
314  *
315  * \param dir direction
316  * \return dot product
317  */
318  double getDot(const JVersor3D& dir) const
319  {
320  return
321  getDX() * dir.getDX() +
322  getDY() * dir.getDY() +
323  getDZ() * dir.getDZ();
324  }
325 
326 
327  /**
328  * Read versor from input.
329  *
330  * \param in input stream
331  * \param versor versor
332  * \return input stream
333  */
334  friend inline std::istream& operator>>(std::istream& in, JVersor3Z& versor)
335  {
336  return in >> versor.__dx >> versor.__dy;
337  }
338 
339 
340  /**
341  * Write versor to output.
342  *
343  * \param out output stream
344  * \param versor versor
345  * \return output stream
346  */
347  friend inline std::ostream& operator<<(std::ostream& out, const JVersor3Z& versor)
348  {
349  return out << versor.getDX() << ' ' << versor.getDY();
350  }
351 
352 
353  /**
354  * Read versor from input.
355  *
356  * \param in reader
357  * \param versor versor
358  * \return reader
359  */
360  friend inline JReader& operator>>(JReader& in, JVersor3Z& versor)
361  {
362  return in >> versor.__dx >> versor.__dy;
363  }
364 
365 
366  /**
367  * Write versor to output.
368  *
369  * \param out writer
370  * \param versor versor
371  * \return writer
372  */
373  friend inline JWriter& operator<<(JWriter& out, const JVersor3Z& versor)
374  {
375  return out << versor.__dx << versor.__dy;
376  }
377 
378  protected:
379  double __dx;
380  double __dy;
381  };
382 }
383 
384 #endif
JGEOMETRY3D::JVersor3D::getDZ
double getDZ() const
Get z direction.
Definition: JVersor3D.hh:114
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:259
JGEOMETRY3D::JVersor3Z::operator>>
friend std::istream & operator>>(std::istream &in, JVersor3Z &versor)
Read versor from input.
Definition: JVersor3Z.hh:334
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:273
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:360
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:379
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:303
JIO::JWriter
Interface for binary output.
Definition: JSerialisable.hh:131
JAngle3D.hh
JGEOMETRY3D::JVersor3Z::getDot
double getDot(const JVersor3D &dir) const
Get dot product.
Definition: JVersor3Z.hh:318
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:92
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:103
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:373
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:288
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:347
JGEOMETRY3D::JVersor3Z::getDZ
double getDZ() const
Get z direction.
Definition: JVersor3Z.hh:167
JGEOMETRY3D::JVersor3Z::__dy
double __dy
Definition: JVersor3Z.hh:380
JGEOMETRY3D::JVersor3Z::getDX
double getDX() const
Get x direction.
Definition: JVersor3Z.hh:145