Jpp
JDirection2D.hh
Go to the documentation of this file.
1 #ifndef __JDIRECTION2D__
2 #define __JDIRECTION2D__
3 
4 #include <istream>
5 #include <ostream>
6 
7 #include "JIO/JSerialisable.hh"
10 #include "JGeometry2D/JVector2D.hh"
12 
13 
14 /**
15  * \author mdejong
16  */
17 
18 namespace JGEOMETRY2D {}
19 namespace JPP { using namespace JGEOMETRY2D; }
20 
21 namespace JGEOMETRY2D {
22 
23  using JIO::JReader;
24  using JIO::JWriter;
25 
26 
27  /**
28  * Data structure for direction in two dimensions.
29  */
30  class JDirection2D :
31  public JVersor2D
32  {
33  public:
34 
35  using JVersor2D::getDot;
37 
38 
39  /**
40  * Default constructor.
41  */
43  JVersor2D()
44  {}
45 
46 
47  /**
48  * Constructor.
49  *
50  * \param dir direction
51  */
52  JDirection2D(const JVersor2D& dir) :
53  JVersor2D(dir.getDY(), dir.getDX())
54  {}
55 
56 
57  /**
58  * Constructor.
59  *
60  * \param angle angle
61  */
62  JDirection2D(const JAngle2D& angle) :
63  JVersor2D(angle.getDX(), angle.getDY())
64  {}
65 
66 
67  /**
68  * Constructor.
69  *
70  * \param pos position
71  */
72  JDirection2D(const JVector2D& pos) :
73  JVersor2D(pos.getY(),pos.getX())
74  {}
75 
76 
77  /**
78  * Constructor.
79  *
80  * \param dx dx value
81  * \param dy dy value
82  */
83  JDirection2D(const double dx,
84  const double dy) :
85  JVersor2D(dx, dy)
86  {}
87 
88 
89  /**
90  * Get direction.
91  *
92  * \return direction
93  */
94  const JDirection2D& getDirection() const
95  {
96  return static_cast<const JDirection2D&>(*this);
97  }
98 
99 
100  /**
101  * Get direction.
102  *
103  * \return direction
104  */
106  {
107  return static_cast<JDirection2D&>(*this);
108  }
109 
110 
111  /**
112  * Set direction.
113  *
114  * \param dir direction
115  */
116  void setDirection(const JDirection2D& dir)
117  {
118  static_cast<JDirection2D&>(*this) = dir;
119  }
120 
121 
122  /**
123  * Type conversion operator.
124  *
125  * \return angle
126  */
127  operator JAngle2D() const
128  {
129  return JAngle2D(getDX(), getDY());
130  }
131 
132 
133  /**
134  * Type conversion operator.
135  *
136  * \return position
137  */
138  operator JVector2D() const
139  {
140  return JVector2D(getDX(), getDY());
141  }
142 
143 
144  /**
145  * Transform.
146  *
147  * \param T matrix
148  * \return this direction
149  */
151  {
152  T.transform(__dx, __dy);
153 
154  normalise();
155 
156  return *this;
157  }
158 
159 
160  /**
161  * Rotate.
162  *
163  * \param R rotation matrix
164  * \return this direction
165  */
167  {
168  R.rotate(__dx, __dy);
169 
170  normalise();
171 
172  return *this;
173  }
174 
175 
176  /**
177  * Rotate back.
178  *
179  * \param R rotation matrix
180  * \return this direction
181  */
183  {
184  R.rotate_back(__dx, __dy);
185 
186  normalise();
187 
188  return *this;
189  }
190 
191 
192  /**
193  * Get dot product.
194  *
195  * \param angle angle
196  * \return dot product
197  */
198  double getDot(const JAngle2D& angle) const
199  {
200  return
201  getDX() * angle.getDX() +
202  getDY() * angle.getDY();
203  }
204 
205 
206  /**
207  * Get dot product.
208  *
209  * \param pos position
210  * \return dot product
211  */
212  double getDot(const JVector2D& pos) const
213  {
214  return
215  getDX() * pos.getX() +
216  getDY() * pos.getY();
217  }
218 
219 
220  /**
221  * Get perpendicular dot product.
222  *
223  * \param angle angle
224  * \return perpendicular dot product
225  */
226  double getPerpDot(const JAngle2D& angle) const
227  {
228  return
229  getDX() * angle.getDY() -
230  getDY() * angle.getDX();
231  }
232 
233 
234  /**
235  * Get perpendicular dot product.
236  *
237  * \param pos position
238  * \return perpendicular dot product
239  */
240  double getPerpDot(const JVector2D& pos) const
241  {
242  return
243  getDX() * pos.getY() -
244  getDY() * pos.getX();
245  }
246 
247 
248  /**
249  * Read direction from input.
250  *
251  * \param in input stream
252  * \param direction direction
253  * \return input stream
254  */
255  friend inline std::istream& operator>>(std::istream& in, JDirection2D& direction)
256  {
257  in >> direction.__dx >> direction.__dy;
258 
259  return in;
260  }
261 
262 
263  /**
264  * Write direction to output.
265  *
266  * \param out output stream
267  * \param direction direction
268  * \return output stream
269  */
270  friend inline std::ostream& operator<<(std::ostream& out, const JDirection2D& direction)
271  {
272  out << direction.getDX() << ' ' << direction.getDY();
273 
274  return out;
275  }
276 
277 
278  /**
279  * Read direction from input.
280  *
281  * \param in reader
282  * \param direction direction
283  * \return reader
284  */
285  friend inline JReader& operator>>(JReader& in, JDirection2D& direction)
286  {
287  in >> direction.__dx;
288  in >> direction.__dy;
289 
290  return in;
291  }
292 
293 
294  /**
295  * Write direction to output.
296  *
297  * \param out writer
298  * \param direction direction
299  * \return writer
300  */
301  friend inline JWriter& operator<<(JWriter& out, const JDirection2D& direction)
302  {
303  out << direction.getDX();
304  out << direction.getDY();
305 
306  return out;
307  }
308  };
309 }
310 
311 #endif
JGEOMETRY2D::JDirection2D::transform
JDirection2D & transform(const JMatrix2D &T)
Transform.
Definition: JDirection2D.hh:150
JGEOMETRY2D::JRotation2D::rotate_back
void rotate_back(double &__x, double &__y) const
Rotate back.
Definition: JRotation2D.hh:112
JIO::JReader
Interface for binary input.
Definition: JSerialisable.hh:62
JGEOMETRY2D::JAngle2D::getDX
double getDX() const
Get x direction.
Definition: JAngle2D.hh:81
JAngle2D.hh
JGEOMETRY2D::JDirection2D::operator>>
friend std::istream & operator>>(std::istream &in, JDirection2D &direction)
Read direction from input.
Definition: JDirection2D.hh:255
JGEOMETRY2D::JDirection2D::getPerpDot
double getPerpDot(const JAngle2D &angle) const
Get perpendicular dot product.
Definition: JDirection2D.hh:226
JGEOMETRY2D::JDirection2D::operator<<
friend JWriter & operator<<(JWriter &out, const JDirection2D &direction)
Write direction to output.
Definition: JDirection2D.hh:301
JGEOMETRY2D::JVersor2D::__dy
double __dy
Definition: JVersor2D.hh:161
JGEOMETRY2D::JDirection2D::getDirection
const JDirection2D & getDirection() const
Get direction.
Definition: JDirection2D.hh:94
JGEOMETRY2D::JDirection2D::getDot
double getDot(const JAngle2D &angle) const
Get dot product.
Definition: JDirection2D.hh:198
JGEOMETRY2D::JDirection2D::setDirection
void setDirection(const JDirection2D &dir)
Set direction.
Definition: JDirection2D.hh:116
JGEOMETRY2D::JVersor2D::__dx
double __dx
Definition: JVersor2D.hh:160
JRotation2D.hh
JGEOMETRY2D::JVersor2D::getDot
double getDot(const JVersor2D &versor) const
Get dot product.
Definition: JVersor2D.hh:116
JGEOMETRY2D::JDirection2D::rotate
JDirection2D & rotate(const JRotation2D &R)
Rotate.
Definition: JDirection2D.hh:166
JGEOMETRY2D::JDirection2D::rotate_back
JDirection2D & rotate_back(const JRotation2D &R)
Rotate back.
Definition: JDirection2D.hh:182
JGEOMETRY2D
Auxiliary classes and methods for 2D geometrical objects and operations.
Definition: JAngle2D.hh:18
JGEOMETRY2D::JDirection2D
Data structure for direction in two dimensions.
Definition: JDirection2D.hh:30
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JVersor2D.hh
JGEOMETRY2D::JVersor2D::normalise
JVersor2D & normalise()
Normalise versor.
Definition: JVersor2D.hh:144
JGEOMETRY2D::JRotation2D::rotate
void rotate(double &__x, double &__y) const
Rotate.
Definition: JRotation2D.hh:96
JSerialisable.hh
JGEOMETRY2D::JDirection2D::getDirection
JDirection2D & getDirection()
Get direction.
Definition: JDirection2D.hh:105
JMATH::JMatrix2D::transform
void transform(double &__x, double &__y) const
Transform.
Definition: JMath/JMatrix2D.hh:284
JGEOMETRY2D::JDirection2D::JDirection2D
JDirection2D(const JVector2D &pos)
Constructor.
Definition: JDirection2D.hh:72
JIO::JWriter
Interface for binary output.
Definition: JSerialisable.hh:131
JGEOMETRY2D::JVersor2D::getPerpDot
double getPerpDot(const JVersor2D &versor) const
Get perpendicular dot product.
Definition: JVersor2D.hh:130
JGEOMETRY2D::JAngle2D::getDY
double getDY() const
Get y direction.
Definition: JAngle2D.hh:92
JGEOMETRY2D::JDirection2D::JDirection2D
JDirection2D(const double dx, const double dy)
Constructor.
Definition: JDirection2D.hh:83
JGEOMETRY2D::JDirection2D::operator>>
friend JReader & operator>>(JReader &in, JDirection2D &direction)
Read direction from input.
Definition: JDirection2D.hh:285
JVector2D.hh
JGEOMETRY2D::JDirection2D::getDot
double getDot(const JVector2D &pos) const
Get dot product.
Definition: JDirection2D.hh:212
JGEOMETRY2D::JDirection2D::JDirection2D
JDirection2D(const JVersor2D &dir)
Constructor.
Definition: JDirection2D.hh:52
JGEOMETRY2D::JDirection2D::JDirection2D
JDirection2D(const JAngle2D &angle)
Constructor.
Definition: JDirection2D.hh:62
JGEOMETRY2D::JAngle2D
Data structure for angle in two dimensions.
Definition: JAngle2D.hh:31
JGEOMETRY2D::JDirection2D::operator<<
friend std::ostream & operator<<(std::ostream &out, const JDirection2D &direction)
Write direction to output.
Definition: JDirection2D.hh:270
JMATH::JMatrix2D
2 x 2 matrix
Definition: JMath/JMatrix2D.hh:32
JGEOMETRY2D::JVector2D::getX
double getX() const
Get x position.
Definition: JVector2D.hh:62
JGEOMETRY2D::JDirection2D::getPerpDot
double getPerpDot(const JVector2D &pos) const
Get perpendicular dot product.
Definition: JDirection2D.hh:240
JGEOMETRY2D::JVersor2D::getDX
double getDX() const
Get x direction.
Definition: JVersor2D.hh:53
JGEOMETRY2D::JDirection2D::JDirection2D
JDirection2D()
Default constructor.
Definition: JDirection2D.hh:42
JGEOMETRY2D::JVersor2D
Data structure for normalised vector in two dimensions.
Definition: JVersor2D.hh:20
JGEOMETRY2D::JVector2D::getY
double getY() const
Get y position.
Definition: JVector2D.hh:73
JGEOMETRY2D::JRotation2D
Rotation matrix.
Definition: JRotation2D.hh:23
JGEOMETRY2D::JVersor2D::getDY
double getDY() const
Get y direction.
Definition: JVersor2D.hh:64
JGEOMETRY2D::JVector2D
Data structure for vector in two dimensions.
Definition: JVector2D.hh:31