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