Jpp
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 "JTools/JConstants.hh"
8 #include "JMath/JMath.hh"
9 
10 
11 /**
12  * \author mdejong
13  */
14 
15 namespace JGEOMETRY3D {}
16 namespace JPP { using namespace JGEOMETRY3D; }
17 
18 namespace JGEOMETRY3D {
19 
20  /**
21  * Data structure for normalised vector in three dimensions.
22  */
23  class JVersor3D :
24  public JMATH::JMath<JVersor3D>
25  {
26  public:
27  /**
28  * Default constructor.
29  * This constructor yields a unit z-vector.
30  */
32  __dx(0.0),
33  __dy(0.0),
34  __dz(1.0)
35  {}
36 
37 
38  /**
39  * Constructor.
40  *
41  * \param dx dx value
42  * \param dy dy value
43  * \param dz dz value
44  */
45  JVersor3D(const double dx,
46  const double dy,
47  const double dz) :
48  __dx(dx),
49  __dy(dy),
50  __dz(dz)
51  {
52  normalise();
53  }
54 
55 
56  /**
57  * Negate versor.
58  *
59  * \return this versor
60  */
62  {
63  __dx = -__dx;
64  __dy = -__dy;
65  __dz = -__dz;
66 
67  return *this;
68  }
69 
70 
71  /**
72  * Check equality.
73  *
74  * \param versor versor
75  * \return true if versors are equal; else false
76  */
77  bool equals(const JVersor3D& versor,
78  const double precision = std::numeric_limits<double>::min()) const
79  {
80  return (fabs(getDX() - versor.getDX()) <= precision &&
81  fabs(getDY() - versor.getDY()) <= precision &&
82  fabs(getDZ() - versor.getDZ()) <= precision);
83  }
84 
85 
86  /**
87  * Get x direction.
88  *
89  * \return x direction
90  */
91  double getDX() const
92  {
93  return __dx;
94  }
95 
96 
97  /**
98  * Get y direction.
99  *
100  * \return y direction
101  */
102  double getDY() const
103  {
104  return __dy;
105  }
106 
107 
108  /**
109  * Get z direction.
110  *
111  * \return z direction
112  */
113  double getDZ() const
114  {
115  return __dz;
116  }
117 
118 
119  /**
120  * Get theta angle.
121  *
122  * \return theta angle [rad]
123  */
124  double getTheta() const
125  {
126  if (__dz > +1.0)
127  return 0.0;
128  else if (__dz < -1.0)
129  return JTOOLS::PI;
130  else
131  return acos(__dz);
132  }
133 
134 
135  /**
136  * Get phi angle.
137  *
138  * \return phi angle [rad]
139  */
140  double getPhi() const
141  {
142  return atan2(__dy, __dx);
143  }
144 
145 
146  /**
147  * Get dot product.
148  *
149  * \param versor versor
150  * \return dot product
151  */
152  double getDot(const JVersor3D& versor) const
153  {
154  return
155  getDX() * versor.getDX() +
156  getDY() * versor.getDY() +
157  getDZ() * versor.getDZ();
158  }
159 
160 
161  /**
162  * Normalise versor.
163  * This operation may set the result to the unit z-vector.
164  *
165  * \return this versor
166  */
168  {
169  const double v = sqrt(getDX()*getDX() + getDY()*getDY() + getDZ()*getDZ());
170 
171  if (v != 0.0) {
172  __dx /= v;
173  __dy /= v;
174  __dz /= v;
175  }
176 
177  return *this;
178  }
179 
180  protected:
181  double __dx;
182  double __dy;
183  double __dz;
184  };
185 
186 
187  static const JVersor3D JVersor3X_t(1,0,0); //!< unit x-vector
188  static const JVersor3D JVersor3Y_t(0,1,0); //!< unit y-vector
189  static const JVersor3D JVersor3Z_t(0,0,1); //!< unit z-vector
190 }
191 
192 #endif
JGEOMETRY3D::JVersor3D::getDZ
double getDZ() const
Get z direction.
Definition: JVersor3D.hh:113
JGEOMETRY3D::JVersor3D::__dz
double __dz
Definition: JVersor3D.hh:183
JGEOMETRY3D::JVersor3D::__dx
double __dx
Definition: JVersor3D.hh:181
JGEOMETRY3D::JVersor3D::equals
bool equals(const JVersor3D &versor, const double precision=std::numeric_limits< double >::min()) const
Check equality.
Definition: JVersor3D.hh:77
JGEOMETRY3D::JVersor3X_t
static const JVersor3D JVersor3X_t(1, 0, 0)
unit x-vector
JGEOMETRY3D::JVersor3D
Data structure for normalised vector in three dimensions.
Definition: JVersor3D.hh:23
JGEOMETRY3D::JVersor3Y_t
static const JVersor3D JVersor3Y_t(0, 1, 0)
unit y-vector
JMATH::JMath
Auxiliary base class for aritmetic operations of derived class types.
Definition: JMath.hh:26
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JGEOMETRY3D::JVersor3D::JVersor3D
JVersor3D(const double dx, const double dy, const double dz)
Constructor.
Definition: JVersor3D.hh:45
JGEOMETRY3D::JVersor3D::getTheta
double getTheta() const
Get theta angle.
Definition: JVersor3D.hh:124
JConstants.hh
JGEOMETRY3D::JVersor3D::JVersor3D
JVersor3D()
Default constructor.
Definition: JVersor3D.hh:31
JGEOMETRY3D::JVersor3D::getDot
double getDot(const JVersor3D &versor) const
Get dot product.
Definition: JVersor3D.hh:152
JGEOMETRY3D::JVersor3D::getDX
double getDX() const
Get x direction.
Definition: JVersor3D.hh:91
JGEOMETRY3D::JVersor3Z_t
static const JVersor3D JVersor3Z_t(0, 0, 1)
unit z-vector
JGEOMETRY3D::JVersor3D::getDY
double getDY() const
Get y direction.
Definition: JVersor3D.hh:102
JGEOMETRY3D::JVersor3D::__dy
double __dy
Definition: JVersor3D.hh:182
JTOOLS::v
data_type v[N+1][M+1]
Definition: JPolint.hh:707
JMath.hh
JGEOMETRY3D::JVersor3D::normalise
JVersor3D & normalise()
Normalise versor.
Definition: JVersor3D.hh:167
JTOOLS::PI
static const double PI
Constants.
Definition: JConstants.hh:20
JGEOMETRY3D
Auxiliary classes and methods for 3D geometrical objects and operations.
Definition: JAngle3D.hh:18
JGEOMETRY3D::JVersor3D::negate
JVersor3D & negate()
Negate versor.
Definition: JVersor3D.hh:61
JGEOMETRY3D::JVersor3D::getPhi
double getPhi() const
Get phi angle.
Definition: JVersor3D.hh:140