Jpp  18.2.1-ARCA-DF-PATCH
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JVersor3D.hh
Go to the documentation of this file.
1 #ifndef __JVERSOR3D__
2 #define __JVERSOR3D__
3 
4 #include <limits>
5 #include <cmath>
6 
7 #include "JMath/JMath.hh"
8 #include "JMath/JConstants.hh"
9 
10 
11 /**
12  * \author mdejong
13  */
14 
15 namespace JGEOMETRY3D {}
16 namespace JPP { using namespace JGEOMETRY3D; }
17 
18 namespace JGEOMETRY3D {
19 
20  using JMATH::JMath;
21 
22 
23  /**
24  * Data structure for normalised vector in three dimensions.
25  */
26  class JVersor3D :
27  public JMath<JVersor3D>
28  {
29  public:
30  /**
31  * Default constructor.
32  * This constructor yields a unit z-vector.
33  */
35  __dx(0.0),
36  __dy(0.0),
37  __dz(1.0)
38  {}
39 
40 
41  /**
42  * Constructor.
43  *
44  * \param dx dx value
45  * \param dy dy value
46  * \param dz dz value
47  */
48  JVersor3D(const double dx,
49  const double dy,
50  const double dz) :
51  __dx(dx),
52  __dy(dy),
53  __dz(dz)
54  {
55  normalise();
56  }
57 
58 
59  /**
60  * Negate versor.
61  *
62  * \return this versor
63  */
65  {
66  __dx = -__dx;
67  __dy = -__dy;
68  __dz = -__dz;
69 
70  return *this;
71  }
72 
73 
74  /**
75  * Check equality.
76  *
77  * \param versor versor
78  * \param precision precision
79  * \return true if versors are equal; else false
80  */
81  bool equals(const JVersor3D& versor,
82  const double precision = std::numeric_limits<double>::min()) const
83  {
84  return (fabs(getDX() - versor.getDX()) <= precision &&
85  fabs(getDY() - versor.getDY()) <= precision &&
86  fabs(getDZ() - versor.getDZ()) <= precision);
87  }
88 
89 
90  /**
91  * Get x direction.
92  *
93  * \return x direction
94  */
95  double getDX() const
96  {
97  return __dx;
98  }
99 
100 
101  /**
102  * Get y direction.
103  *
104  * \return y direction
105  */
106  double getDY() const
107  {
108  return __dy;
109  }
110 
111 
112  /**
113  * Get z direction.
114  *
115  * \return z direction
116  */
117  double getDZ() const
118  {
119  return __dz;
120  }
121 
122 
123  /**
124  * Get theta angle.
125  *
126  * \return theta angle [rad]
127  */
128  double getTheta() const
129  {
130  if (__dz > +1.0)
131  return 0.0;
132  else if (__dz < -1.0)
133  return JMATH::PI;
134  else
135  return acos(__dz);
136  }
137 
138 
139  /**
140  * Get phi angle.
141  *
142  * \return phi angle [rad]
143  */
144  double getPhi() const
145  {
146  return atan2(__dy, __dx);
147  }
148 
149 
150  /**
151  * Get dot product.
152  *
153  * \param versor versor
154  * \return dot product
155  */
156  double getDot(const JVersor3D& versor) const
157  {
158  return
159  getDX() * versor.getDX() +
160  getDY() * versor.getDY() +
161  getDZ() * versor.getDZ();
162  }
163 
164 
165  /**
166  * Get cross product.
167  * Note that this versor should not overlap with the first or second versor,
168  *
169  * \param first first versor
170  * \param second second versor
171  * \return this versor
172  */
174  const JVersor3D& second)
175  {
176  __dx = first .getDY() * second.getDZ() - second.getDY() * first .getDZ();
177  __dy = second.getDX() * first .getDZ() - first .getDX() * second.getDZ();
178  __dz = first .getDX() * second.getDY() - second.getDX() * first .getDY();
179 
180  normalise();
181 
182  return *this;
183  }
184 
185 
186  /**
187  * Normalise versor.
188  * This operation may set the result to the unit z-vector.
189  *
190  * \return this versor
191  */
193  {
194  const double v = sqrt(getDX()*getDX() + getDY()*getDY() + getDZ()*getDZ());
195 
196  if (v != 0.0) {
197  __dx /= v;
198  __dy /= v;
199  __dz /= v;
200  }
201 
202  return *this;
203  }
204 
205  protected:
206  double __dx;
207  double __dy;
208  double __dz;
209  };
210 
211 
212  static const JVersor3D JVersor3X_t(1,0,0); //!< unit x-vector
213  static const JVersor3D JVersor3Y_t(0,1,0); //!< unit y-vector
214  static const JVersor3D JVersor3Z_t(0,0,1); //!< unit z-vector
215 }
216 
217 #endif
Auxiliary base class for aritmetic operations of derived class types.
Definition: JMath.hh:109
JVersor3D & getCross(const JVersor3D &first, const JVersor3D &second)
Get cross product.
Definition: JVersor3D.hh:173
double getPhi() const
Get phi angle.
Definition: JVersor3D.hh:144
JVersor3D & normalise()
Normalise versor.
Definition: JVersor3D.hh:192
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
bool equals(const JVersor3D &versor, const double precision=std::numeric_limits< double >::min()) const
Check equality.
Definition: JVersor3D.hh:81
JVersor3D & negate()
Negate versor.
Definition: JVersor3D.hh:64
Mathematical constants.
double getDY() const
Get y direction.
Definition: JVersor3D.hh:106
double getDX() const
Get x direction.
Definition: JVersor3D.hh:95
double getTheta() const
Get theta angle.
Definition: JVersor3D.hh:128
static const double PI
Mathematical constants.
static const JVersor3D JVersor3X_t(1, 0, 0)
unit x-vector
JVersor3D()
Default constructor.
Definition: JVersor3D.hh:34
static const JVersor3D JVersor3Y_t(0, 1, 0)
unit y-vector
Base class for data structures with artithmetic capabilities.
static const JVersor3D JVersor3Z_t(0, 0, 1)
unit z-vector
double getDot(const JVersor3D &versor) const
Get dot product.
Definition: JVersor3D.hh:156
JVersor3D(const double dx, const double dy, const double dz)
Constructor.
Definition: JVersor3D.hh:48
data_type v[N+1][M+1]
Definition: JPolint.hh:866
Data structure for normalised vector in three dimensions.
Definition: JVersor3D.hh:26
double getDZ() const
Get z direction.
Definition: JVersor3D.hh:117