Jpp
 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 "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  * \param precision precision
76  * \return true if versors are equal; else false
77  */
78  bool equals(const JVersor3D& versor,
79  const double precision = std::numeric_limits<double>::min()) const
80  {
81  return (fabs(getDX() - versor.getDX()) <= precision &&
82  fabs(getDY() - versor.getDY()) <= precision &&
83  fabs(getDZ() - versor.getDZ()) <= precision);
84  }
85 
86 
87  /**
88  * Get x direction.
89  *
90  * \return x direction
91  */
92  double getDX() const
93  {
94  return __dx;
95  }
96 
97 
98  /**
99  * Get y direction.
100  *
101  * \return y direction
102  */
103  double getDY() const
104  {
105  return __dy;
106  }
107 
108 
109  /**
110  * Get z direction.
111  *
112  * \return z direction
113  */
114  double getDZ() const
115  {
116  return __dz;
117  }
118 
119 
120  /**
121  * Get theta angle.
122  *
123  * \return theta angle [rad]
124  */
125  double getTheta() const
126  {
127  if (__dz > +1.0)
128  return 0.0;
129  else if (__dz < -1.0)
130  return JTOOLS::PI;
131  else
132  return acos(__dz);
133  }
134 
135 
136  /**
137  * Get phi angle.
138  *
139  * \return phi angle [rad]
140  */
141  double getPhi() const
142  {
143  return atan2(__dy, __dx);
144  }
145 
146 
147  /**
148  * Get dot product.
149  *
150  * \param versor versor
151  * \return dot product
152  */
153  double getDot(const JVersor3D& versor) const
154  {
155  return
156  getDX() * versor.getDX() +
157  getDY() * versor.getDY() +
158  getDZ() * versor.getDZ();
159  }
160 
161 
162  /**
163  * Normalise versor.
164  * This operation may set the result to the unit z-vector.
165  *
166  * \return this versor
167  */
169  {
170  const double v = sqrt(getDX()*getDX() + getDY()*getDY() + getDZ()*getDZ());
171 
172  if (v != 0.0) {
173  __dx /= v;
174  __dy /= v;
175  __dz /= v;
176  }
177 
178  return *this;
179  }
180 
181  protected:
182  double __dx;
183  double __dy;
184  double __dz;
185  };
186 
187 
188  static const JVersor3D JVersor3X_t(1,0,0); //!< unit x-vector
189  static const JVersor3D JVersor3Y_t(0,1,0); //!< unit y-vector
190  static const JVersor3D JVersor3Z_t(0,0,1); //!< unit z-vector
191 }
192 
193 #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:141
JVersor3D & normalise()
Normalise versor.
Definition: JVersor3D.hh:168
Constants.
bool equals(const JVersor3D &versor, const double precision=std::numeric_limits< double >::min()) const
Check equality.
Definition: JVersor3D.hh:78
JVersor3D & negate()
Negate versor.
Definition: JVersor3D.hh:61
double getDY() const
Get y direction.
Definition: JVersor3D.hh:103
double getDX() const
Get x direction.
Definition: JVersor3D.hh:92
double getTheta() const
Get theta angle.
Definition: JVersor3D.hh:125
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:153
JVersor3D(const double dx, const double dy, const double dz)
Constructor.
Definition: JVersor3D.hh:45
data_type v[N+1][M+1]
Definition: JPolint.hh:707
Data structure for normalised vector in three dimensions.
Definition: JVersor3D.hh:23
double getDZ() const
Get z direction.
Definition: JVersor3D.hh:114