Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JPosition2D.hh
Go to the documentation of this file.
1#ifndef __JPOSITION2D__
2#define __JPOSITION2D__
3
4#include <istream>
5#include <ostream>
6
8#include "JLang/JManip.hh"
13
14
15/**
16 * \author mdejong
17 */
18
19namespace JGEOMETRY2D {}
20namespace JPP { using namespace JGEOMETRY2D; }
21
22namespace JGEOMETRY2D {
23
24 using JIO::JReader;
25 using JIO::JWriter;
26
27
28 /**
29 * Data structure for position in two dimensions.
30 */
32 public JVector2D
33 {
34 public:
35
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
I/O manipulators.
JFormat_t & getFormat()
Get format for given type.
Definition JManip.hh:682
Data structure for angle in two dimensions.
Definition JAngle2D.hh:35
double getDY() const
Get y direction.
Definition JAngle2D.hh:94
double getDX() const
Get x direction.
Definition JAngle2D.hh:83
Data structure for position in two dimensions.
double getDot(const JAngle2D &angle) const
Get dot product.
JPosition2D(const double x, const double y)
Constructor.
JPosition2D & getPosition()
Get position.
double getPerpDot(const JVersor2D &dir) const
Get perpendicular dot product.
const JPosition2D & getPosition() const
Get position.
friend std::istream & operator>>(std::istream &in, JPosition2D &position)
Read position from input.
JPosition2D(const JAngle2D &angle)
Constructor.
JPosition2D & rotate_back(const JRotation2D &R)
Rotate back.
JPosition2D & rotate(const JRotation2D &R)
Rotate.
JPosition2D()
Default constructor.
void setPosition(const JVector2D &pos)
Set position.
JPosition2D(const JVector2D &pos)
Constructor.
friend std::ostream & operator<<(std::ostream &out, const JPosition2D &position)
Write position to output.
double getPerpDot(const JAngle2D &angle) const
Get perpendicular dot product.
friend JReader & operator>>(JReader &in, JPosition2D &position)
Read position from input.
double getDot(const JVersor2D &versor) const
Get dot product.
friend JWriter & operator<<(JWriter &out, const JPosition2D &position)
Write position to output.
JPosition2D(const JVersor2D &dir)
Constructor.
void rotate(double &__x, double &__y) const
Rotate.
void rotate_back(double &__x, double &__y) const
Rotate back.
Data structure for vector in two dimensions.
Definition JVector2D.hh:34
JVector2D & transform(const JMatrix2D &T)
Transform.
Definition JVector2D.hh:160
double getY() const
Get y position.
Definition JVector2D.hh:74
double getX() const
Get x position.
Definition JVector2D.hh:63
double getPerpDot(const JVector2D &point) const
Get perpendicular dot product.
Definition JVector2D.hh:249
double getDot(const JVector2D &point) const
Get dot product.
Definition JVector2D.hh:235
Data structure for normalised vector in two dimensions.
Definition JVersor2D.hh:21
double getDX() const
Get x direction.
Definition JVersor2D.hh:53
double getDY() const
Get y direction.
Definition JVersor2D.hh:64
Interface for binary input.
Interface for binary output.
Auxiliary classes and methods for 2D geometrical objects and operations.
Definition JAngle2D.hh:19
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Data structure for format specifications.
Definition JManip.hh:524
Auxiliary class to temporarily define format specifications.
Definition JManip.hh:636