Jpp  15.0.4
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPosition2D.hh
Go to the documentation of this file.
1 #ifndef __JPOSITION2D__
2 #define __JPOSITION2D__
3 
4 #include <istream>
5 #include <ostream>
6 
7 #include "JIO/JSerialisable.hh"
8 #include "JLang/JManip.hh"
10 #include "JGeometry2D/JAngle2D.hh"
11 #include "JGeometry2D/JVersor2D.hh"
13 
14 
15 /**
16  * \author mdejong
17  */
18 
19 namespace JGEOMETRY2D {}
20 namespace JPP { using namespace JGEOMETRY2D; }
21 
22 namespace JGEOMETRY2D {
23 
24  using JIO::JReader;
25  using JIO::JWriter;
26 
27 
28  /**
29  * Data structure for position in two dimensions.
30  */
31  class JPosition2D :
32  public JVector2D
33  {
34  public:
35 
36  using JVector2D::getDot;
39 
40 
41  /**
42  * Default constructor.
43  */
45  JVector2D()
46  {}
47 
48 
49  /**
50  * Constructor.
51  *
52  * \param pos position
53  */
54  JPosition2D(const JVector2D& pos) :
55  JVector2D(pos)
56  {}
57 
58 
59  /**
60  * Constructor.
61  *
62  * \param angle angle
63  */
64  JPosition2D(const JAngle2D& angle) :
65  JVector2D(angle.getDX(),
66  angle.getDY())
67  {}
68 
69 
70  /**
71  * Constructor.
72  *
73  * \param dir direction
74  */
75  JPosition2D(const JVersor2D& dir) :
76  JVector2D(dir.getDX(),
77  dir.getDY())
78  {}
79 
80 
81  /**
82  * Constructor.
83  *
84  * \param x x value
85  * \param y y value
86  */
87  JPosition2D(const double x,
88  const double y) :
89  JVector2D(x,y)
90  {}
91 
92 
93  /**
94  * Get position.
95  *
96  * \return position
97  */
98  const JPosition2D& getPosition() const
99  {
100  return static_cast<const JPosition2D&>(*this);
101  }
102 
103 
104  /**
105  * Get position.
106  *
107  * \return position
108  */
110  {
111  return static_cast<JPosition2D&>(*this);
112  }
113 
114 
115  /**
116  * Set position.
117  *
118  * \param pos position
119  */
120  void setPosition(const JVector2D& pos)
121  {
122  static_cast<JVector2D&>(*this) = pos;
123  }
124 
125 
126  /**
127  * Type conversion operator.
128  *
129  * \return angle
130  */
131  operator JAngle2D() const
132  {
133  return JAngle2D(getX(), getY());
134  }
135 
136 
137  /**
138  * Type conversion operator.
139  *
140  * \return direction
141  */
142  operator JVersor2D() const
143  {
144  return JVersor2D(getX(), getY());
145  }
146 
147 
148  /**
149  * Rotate.
150  *
151  * \param R rotation matrix
152  * \return this position
153  */
155  {
156  R.rotate(__x, __y);
157 
158  return *this;
159  }
160 
161 
162  /**
163  * Rotate back.
164  *
165  * \param R rotation matrix
166  * \return this position
167  */
169  {
170  R.rotate_back(__x, __y);
171 
172  return *this;
173  }
174 
175 
176  /**
177  * Get dot product.
178  *
179  * \param angle angle
180  * \return dot product
181  */
182  double getDot(const JAngle2D& angle) const
183  {
184  return
185  getX() * angle.getDX() +
186  getY() * angle.getDY();
187  }
188 
189 
190  /**
191  * Get dot product.
192  *
193  * \param versor versor
194  * \return dot product
195  */
196  double getDot(const JVersor2D& versor) const
197  {
198  return
199  getX() * versor.getDX() +
200  getY() * versor.getDY();
201  }
202 
203 
204  /**
205  * Get perpendicular dot product.
206  *
207  * \param angle angle
208  * \return perpendicular dot product
209  */
210  double getPerpDot(const JAngle2D& angle) const
211  {
212  return
213  getX() * angle.getDY() -
214  getY() * angle.getDX();
215  }
216 
217 
218  /**
219  * Get perpendicular dot product.
220  *
221  * \param dir direction
222  * \return perpendicular dot product
223  */
224  double getPerpDot(const JVersor2D& dir) const
225  {
226  return
227  getX() * dir.getDY() -
228  getY() * dir.getDX();
229  }
230 
231 
232  /**
233  * Read position from input.
234  *
235  * \param in input stream
236  * \param position position
237  * \return input stream
238  */
239  friend inline std::istream& operator>>(std::istream& in, JPosition2D& position)
240  {
241  in >> position.__x >> position.__y;
242 
243  return in;
244  }
245 
246 
247  /**
248  * Write position to output.
249  *
250  * \param out output stream
251  * \param position position
252  * \return output stream
253  */
254  friend inline std::ostream& operator<<(std::ostream& out, const JPosition2D& position)
255  {
256  const JFormat format(out, getFormat<JPosition2D>(JFormat_t(9, 3, std::ios::fixed | std::ios::showpos)));
257 
258  out << format << position.getX() << ' '
259  << format << position.getY();
260 
261  return out;
262  }
263 
264 
265  /**
266  * Read position from input.
267  *
268  * \param in reader
269  * \param position position
270  * \return reader
271  */
272  friend inline JReader& operator>>(JReader& in, JPosition2D& position)
273  {
274  in >> position.__x;
275  in >> position.__y;
276 
277  return in;
278  }
279 
280 
281  /**
282  * Write position to output.
283  *
284  * \param out writer
285  * \param position position
286  * \return writer
287  */
288  friend inline JWriter& operator<<(JWriter& out, const JPosition2D& position)
289  {
290  out << position.__x;
291  out << position.__y;
292 
293  return out;
294  }
295  };
296 }
297 
298 #endif
const JPosition2D & getPosition() const
Get position.
Definition: JPosition2D.hh:98
Data structure for vector in two dimensions.
Definition: JVector2D.hh:32
double getDX() const
Get x direction.
Definition: JAngle2D.hh:83
Data structure for angle in two dimensions.
Definition: JAngle2D.hh:33
Interface for binary output.
Rotation matrix.
Definition: JRotation2D.hh:23
friend JReader & operator>>(JReader &in, JPosition2D &position)
Read position from input.
Definition: JPosition2D.hh:272
double getDot(const JVector2D &point) const
Get dot product.
Definition: JVector2D.hh:235
friend JWriter & operator<<(JWriter &out, const JPosition2D &position)
Write position to output.
Definition: JPosition2D.hh:288
JPosition2D()
Default constructor.
Definition: JPosition2D.hh:44
void rotate(double &__x, double &__y) const
Rotate.
Definition: JRotation2D.hh:96
JVector2D & transform(const JMatrix2D &T)
Transform.
Definition: JVector2D.hh:160
void rotate_back(double &__x, double &__y) const
Rotate back.
Definition: JRotation2D.hh:112
double getPerpDot(const JVersor2D &dir) const
Get perpendicular dot product.
Definition: JPosition2D.hh:224
double getY() const
Get y position.
Definition: JVector2D.hh:74
JPosition2D(const JVector2D &pos)
Constructor.
Definition: JPosition2D.hh:54
double getDX() const
Get x direction.
Definition: JVersor2D.hh:53
Auxiliary class to temporarily define format specifications.
Definition: JManip.hh:632
Data structure for normalised vector in two dimensions.
Definition: JVersor2D.hh:20
JPosition2D(const JVersor2D &dir)
Constructor.
Definition: JPosition2D.hh:75
friend std::ostream & operator<<(std::ostream &out, const JPosition2D &position)
Write position to output.
Definition: JPosition2D.hh:254
JPosition2D & getPosition()
Get position.
Definition: JPosition2D.hh:109
double getX() const
Get x position.
Definition: JVector2D.hh:63
JPosition2D & rotate(const JRotation2D &R)
Rotate.
Definition: JPosition2D.hh:154
double getDot(const JVersor2D &versor) const
Get dot product.
Definition: JPosition2D.hh:196
friend std::istream & operator>>(std::istream &in, JPosition2D &position)
Read position from input.
Definition: JPosition2D.hh:239
Interface for binary input.
JPosition2D(const JAngle2D &angle)
Constructor.
Definition: JPosition2D.hh:64
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:43
I/O manipulators.
double getDot(const JAngle2D &angle) const
Get dot product.
Definition: JPosition2D.hh:182
Data structure for position in two dimensions.
Definition: JPosition2D.hh:31
double getPerpDot(const JVector2D &point) const
Get perpendicular dot product.
Definition: JVector2D.hh:249
double getPerpDot(const JAngle2D &angle) const
Get perpendicular dot product.
Definition: JPosition2D.hh:210
double getDY() const
Get y direction.
Definition: JVersor2D.hh:64
double getDY() const
Get y direction.
Definition: JAngle2D.hh:94
JPosition2D & rotate_back(const JRotation2D &R)
Rotate back.
Definition: JPosition2D.hh:168
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41
Data structure for format specifications.
Definition: JManip.hh:522
void setPosition(const JVector2D &pos)
Set position.
Definition: JPosition2D.hh:120
JPosition2D(const double x, const double y)
Constructor.
Definition: JPosition2D.hh:87