Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JVersor3D.hh
Go to the documentation of this file.
1 
2 #ifndef __JVERSOR3D__
3 #define __JVERSOR3D__
4 
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) const
78  {
79  return (getDX() == versor.getDX() &&
80  getDY() == versor.getDY() &&
81  getDZ() == versor.getDZ());
82  }
83 
84 
85  /**
86  * Get x direction.
87  *
88  * \return x direction
89  */
90  double getDX() const
91  {
92  return __dx;
93  }
94 
95 
96  /**
97  * Get y direction.
98  *
99  * \return y direction
100  */
101  double getDY() const
102  {
103  return __dy;
104  }
105 
106 
107  /**
108  * Get z direction.
109  *
110  * \return z direction
111  */
112  double getDZ() const
113  {
114  return __dz;
115  }
116 
117 
118  /**
119  * Get theta angle.
120  *
121  * \return theta angle [rad]
122  */
123  double getTheta() const
124  {
125  if (__dz > +1.0)
126  return 0.0;
127  else if (__dz < -1.0)
128  return JTOOLS::PI;
129  else
130  return acos(__dz);
131  }
132 
133 
134  /**
135  * Get phi angle.
136  *
137  * \return phi angle [rad]
138  */
139  double getPhi() const
140  {
141  return atan2(__dy, __dx);
142  }
143 
144 
145  /**
146  * Get dot product.
147  *
148  * \param versor versor
149  * \return dot product
150  */
151  double getDot(const JVersor3D& versor) const
152  {
153  return
154  getDX() * versor.getDX() +
155  getDY() * versor.getDY() +
156  getDZ() * versor.getDZ();
157  }
158 
159 
160  /**
161  * Normalise versor.
162  * This operation may set the result to the unit z-vector.
163  *
164  * \return this versor
165  */
167  {
168  const double v = sqrt(getDX()*getDX() + getDY()*getDY() + getDZ()*getDZ());
169 
170  if (v != 0.0) {
171  __dx /= v;
172  __dy /= v;
173  __dz /= v;
174  }
175 
176  return *this;
177  }
178 
179  protected:
180  double __dx;
181  double __dy;
182  double __dz;
183  };
184 
185 
186  static const JVersor3D JVersor3X_t(1,0,0); //!< unit x-vector
187  static const JVersor3D JVersor3Y_t(0,1,0); //!< unit y-vector
188  static const JVersor3D JVersor3Z_t(0,0,1); //!< unit z-vector
189 }
190 
191 #endif
Auxiliary base class for aritmetic operations of derived class types.
Definition: JMath.hh:26
static const double PI
Constants.
Definition: JConstants.hh:20
double getPhi() const
Get phi angle.
Definition: JVersor3D.hh:139
JVersor3D & normalise()
Normalise versor.
Definition: JVersor3D.hh:166
Constants.
JVersor3D & negate()
Negate versor.
Definition: JVersor3D.hh:61
double getDY() const
Get y direction.
Definition: JVersor3D.hh:101
double getDX() const
Get x direction.
Definition: JVersor3D.hh:90
double getTheta() const
Get theta angle.
Definition: JVersor3D.hh:123
static const JVersor3D JVersor3X_t(1, 0, 0)
unit x-vector
JVersor3D()
Default constructor.
Definition: JVersor3D.hh:31
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:151
JVersor3D(const double dx, const double dy, const double dz)
Constructor.
Definition: JVersor3D.hh:45
Data structure for normalised vector in three dimensions.
Definition: JVersor3D.hh:23
double getDZ() const
Get z direction.
Definition: JVersor3D.hh:112
bool equals(const JVersor3D &versor) const
Check equality.
Definition: JVersor3D.hh:77