Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
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
12namespace JGEOMETRY2D {}
13namespace JPP { using namespace JGEOMETRY2D; }
14
15namespace JGEOMETRY2D {
16
17 /**
18 * Data structure for normalised vector in two dimensions.
19 */
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 * \param precision precision
100 * \return true if versors are equal; else false
101 */
102 bool equals(const JVersor2D& versor,
103 const double precision = std::numeric_limits<double>::min()) const
104 {
105 return (fabs(getDX() - versor.getDX()) <= precision &&
106 fabs(getDY() - versor.getDY()) <= precision);
107 }
108
109
110 /**
111 * Get dot product.
112 *
113 * \param versor versor
114 * \return dot product
115 */
116 double getDot(const JVersor2D& versor) const
117 {
118 return
119 getDX() * versor.getDX() +
120 getDY() * versor.getDY();
121 }
122
123
124 /**
125 * Get perpendicular dot product.
126 *
127 * \param versor versor
128 * \return perpendicular dot product
129 */
130 double getPerpDot(const JVersor2D& versor) const
131 {
132 return
133 getDX() * versor.getDY() -
134 getDY() * versor.getDX();
135 }
136
137
138 /**
139 * Normalise versor.
140 * This operation may set the result to the unit y-vector.
141 *
142 * \return this versor
143 */
145 {
146 const double v = sqrt(getDX()*getDX() + getDY()*getDY());
147
148 if (v != 0.0) {
149 __dx /= v;
150 __dy /= v;
151 } else {
152 __dx = 0.0;
153 __dy = 1.0;
154 }
155
156 return *this;
157 }
158
159 protected:
160 double __dx;
161 double __dy;
162 };
163
164
165 static const JVersor2D JVersor2X_t(1,0); //!< unit x-vector
166 static const JVersor2D JVersor2Y_t(0,1); //!< unit y-vector
167}
168
169#endif
Data structure for normalised vector in two dimensions.
Definition JVersor2D.hh:21
double getDX() const
Get x direction.
Definition JVersor2D.hh:53
JVersor2D & normalise()
Normalise versor.
Definition JVersor2D.hh:144
bool equals(const JVersor2D &versor, const double precision=std::numeric_limits< double >::min()) const
Check equality.
Definition JVersor2D.hh:102
JVersor2D()
Default constructor.
Definition JVersor2D.hh:27
double getPerpDot(const JVersor2D &versor) const
Get perpendicular dot product.
Definition JVersor2D.hh:130
JVersor2D(const double dx, const double dy)
Constructor.
Definition JVersor2D.hh:39
double getDY() const
Get y direction.
Definition JVersor2D.hh:64
double getPhi() const
Get phi angle.
Definition JVersor2D.hh:75
JVersor2D & negate()
Negate versor.
Definition JVersor2D.hh:86
double getDot(const JVersor2D &versor) const
Get dot product.
Definition JVersor2D.hh:116
Auxiliary classes and methods for 2D geometrical objects and operations.
Definition JAngle2D.hh:19
static const JVersor2D JVersor2X_t(1, 0)
unit x-vector
static const JVersor2D JVersor2Y_t(0, 1)
unit y-vector
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).