Jpp - 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"
10 #include "JGeometry2D/JVersor2D.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 position in two dimensions.
29  */
30  class JPosition2D :
31  public JVector2D
32  {
33  public:
34 
35  using JVector2D::getDot;
38 
39 
40  /**
41  * Default constructor.
42  */
44  JVector2D()
45  {}
46 
47 
48  /**
49  * Constructor.
50  *
51  * \param pos position
52  */
53  JPosition2D(const JVector2D& pos) :
54  JVector2D(pos)
55  {}
56 
57 
58  /**
59  * Constructor.
60  *
61  * \param angle angle
62  */
63  JPosition2D(const JAngle2D& angle) :
64  JVector2D(angle.getDX(),
65  angle.getDY())
66  {}
67 
68 
69  /**
70  * Constructor.
71  *
72  * \param dir direction
73  */
74  JPosition2D(const JVersor2D& dir) :
75  JVector2D(dir.getDX(),
76  dir.getDY())
77  {}
78 
79 
80  /**
81  * Constructor.
82  *
83  * \param x x value
84  * \param y y value
85  */
86  JPosition2D(const double x,
87  const double y) :
88  JVector2D(x,y)
89  {}
90 
91 
92  /**
93  * Get position.
94  *
95  * \return position
96  */
97  const JPosition2D& getPosition() const
98  {
99  return static_cast<const JPosition2D&>(*this);
100  }
101 
102 
103  /**
104  * Get position.
105  *
106  * \return position
107  */
109  {
110  return static_cast<JPosition2D&>(*this);
111  }
112 
113 
114  /**
115  * Set position.
116  *
117  * \param pos position
118  */
119  void setPosition(const JVector2D& pos)
120  {
121  static_cast<JVector2D&>(*this) = pos;
122  }
123 
124 
125  /**
126  * Type conversion operator.
127  *
128  * \return angle
129  */
130  operator JAngle2D() const
131  {
132  return JAngle2D(getX(), getY());
133  }
134 
135 
136  /**
137  * Type conversion operator.
138  *
139  * \return direction
140  */
141  operator JVersor2D() const
142  {
143  return JVersor2D(getX(), getY());
144  }
145 
146 
147  /**
148  * Rotate.
149  *
150  * \param R rotation matrix
151  * \return this position
152  */
154  {
155  R.rotate(__x, __y);
156 
157  return *this;
158  }
159 
160 
161  /**
162  * Rotate back.
163  *
164  * \param R rotation matrix
165  * \return this position
166  */
168  {
169  R.rotate_back(__x, __y);
170 
171  return *this;
172  }
173 
174 
175  /**
176  * Get dot product.
177  *
178  * \param angle angle
179  * \return dot product
180  */
181  double getDot(const JAngle2D& angle) const
182  {
183  return
184  getX() * angle.getDX() +
185  getY() * angle.getDY();
186  }
187 
188 
189  /**
190  * Get dot product.
191  *
192  * \param versor versor
193  * \return dot product
194  */
195  double getDot(const JVersor2D& versor) const
196  {
197  return
198  getX() * versor.getDX() +
199  getY() * versor.getDY();
200  }
201 
202 
203  /**
204  * Get perpendicular dot product.
205  *
206  * \param angle angle
207  * \return perpendicular dot product
208  */
209  double getPerpDot(const JAngle2D& angle) const
210  {
211  return
212  getX() * angle.getDY() -
213  getY() * angle.getDX();
214  }
215 
216 
217  /**
218  * Get perpendicular dot product.
219  *
220  * \param dir direction
221  * \return perpendicular dot product
222  */
223  double getPerpDot(const JVersor2D& dir) const
224  {
225  return
226  getX() * dir.getDY() -
227  getY() * dir.getDX();
228  }
229 
230 
231  /**
232  * Read position from input.
233  *
234  * \param in input stream
235  * \param position position
236  * \return input stream
237  */
238  friend inline std::istream& operator>>(std::istream& in, JPosition2D& position)
239  {
240  in >> position.__x >> position.__y;
241 
242  return in;
243  }
244 
245 
246  /**
247  * Write position to output.
248  *
249  * \param out output stream
250  * \param position position
251  * \return output stream
252  */
253  friend inline std::ostream& operator<<(std::ostream& out, const JPosition2D& position)
254  {
255  out << position.getX() << ' ' << position.getY();
256 
257  return out;
258  }
259 
260 
261  /**
262  * Read position from input.
263  *
264  * \param in reader
265  * \param position position
266  * \return reader
267  */
268  friend inline JReader& operator>>(JReader& in, JPosition2D& position)
269  {
270  in >> position.__x;
271  in >> position.__y;
272 
273  return in;
274  }
275 
276 
277  /**
278  * Write position to output.
279  *
280  * \param out writer
281  * \param position position
282  * \return writer
283  */
284  friend inline JWriter& operator<<(JWriter& out, const JPosition2D& position)
285  {
286  out << position.getX();
287  out << position.getY();
288 
289  return out;
290  }
291  };
292 }
293 
294 #endif
const JPosition2D & getPosition() const
Get position.
Definition: JPosition2D.hh:97
Data structure for vector in two dimensions.
Definition: JVector2D.hh:32
double getDX() const
Get x direction.
Definition: JAngle2D.hh:82
Data structure for angle in two dimensions.
Definition: JAngle2D.hh:32
Interface for binary output.
Rotation matrix.
Definition: JRotation2D.hh:23
friend JReader & operator>>(JReader &in, JPosition2D &position)
Read position from input.
Definition: JPosition2D.hh:268
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:284
JPosition2D()
Default constructor.
Definition: JPosition2D.hh:43
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:223
double getY() const
Get y position.
Definition: JVector2D.hh:74
JPosition2D(const JVector2D &pos)
Constructor.
Definition: JPosition2D.hh:53
double getDX() const
Get x direction.
Definition: JVersor2D.hh:53
Data structure for normalised vector in two dimensions.
Definition: JVersor2D.hh:20
JPosition2D(const JVersor2D &dir)
Constructor.
Definition: JPosition2D.hh:74
friend std::ostream & operator<<(std::ostream &out, const JPosition2D &position)
Write position to output.
Definition: JPosition2D.hh:253
JPosition2D & getPosition()
Get position.
Definition: JPosition2D.hh:108
double getX() const
Get x position.
Definition: JVector2D.hh:63
JPosition2D & rotate(const JRotation2D &R)
Rotate.
Definition: JPosition2D.hh:153
double getDot(const JVersor2D &versor) const
Get dot product.
Definition: JPosition2D.hh:195
friend std::istream & operator>>(std::istream &in, JPosition2D &position)
Read position from input.
Definition: JPosition2D.hh:238
Interface for binary input.
JPosition2D(const JAngle2D &angle)
Constructor.
Definition: JPosition2D.hh:63
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:40
double getDot(const JAngle2D &angle) const
Get dot product.
Definition: JPosition2D.hh:181
Data structure for position in two dimensions.
Definition: JPosition2D.hh:30
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:209
double getDY() const
Get y direction.
Definition: JVersor2D.hh:64
double getDY() const
Get y direction.
Definition: JAngle2D.hh:93
JPosition2D & rotate_back(const JRotation2D &R)
Rotate back.
Definition: JPosition2D.hh:167
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:38
void setPosition(const JVector2D &pos)
Set position.
Definition: JPosition2D.hh:119
JPosition2D(const double x, const double y)
Constructor.
Definition: JPosition2D.hh:86