Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JUTMPosition.hh
Go to the documentation of this file.
1#ifndef __JUTM__JUTMPOSITION__
2#define __JUTM__JUTMPOSITION__
3
4#include <istream>
5#include <ostream>
6
8#include "JMath/JMath.hh"
9#include "JLang/JManip.hh"
10#include "JIO/JSerialisable.hh"
11
12
13/**
14 * \author mdejong
15 */
16
17namespace JUTM {}
18namespace JPP { using namespace JUTM; }
19
20/**
21 * Auxiliaries for handling universal transverse mercator coordinate system (UTM).
22 */
23namespace JUTM {
24
25 using JMATH::JMath;
28 using JIO::JReader;
29 using JIO::JWriter;
30
31
32 /**
33 * Data structure for UTM position.
34 * The z-coordinate corresponds to the depth where <tt>z = 0</tt> is at sea level.
35 */
37 public JMath<JUTMPosition>
38 {
39 public:
40 /**
41 * Default constructor.
42 */
44 east (0.0),
45 north(0.0),
46 z (0.0)
47 {}
48
49
50 /**
51 * Constructor.
52 *
53 * \param pos UTM position
54 */
55 JUTMPosition(const JVector3D& pos) :
56 east (pos.getX()),
57 north(pos.getY()),
58 z (pos.getZ())
59 {}
60
61
62 /**
63 * Constructor.
64 *
65 * \param east UTM East
66 * \param north UTM North
67 * \param z UTM Z
68 */
69 JUTMPosition(const double east,
70 const double north,
71 const double z)
72 {
73 this->east = east;
74 this->north = north;
75 this->z = z;
76 }
77
78
79 /**
80 * Get UTM position.
81 *
82 * \return position
83 */
85 {
86 return static_cast<const JUTMPosition&>(*this);
87 }
88
89
90 /**
91 * Set UTM position.
92 *
93 * \param position position
94 */
95 void setUTMPosition(const JUTMPosition& position)
96 {
97 static_cast<JUTMPosition&>(*this) = position;
98 }
99
100
101 /**
102 * Get position.
103 *
104 * \return position
105 */
107 {
108 return JPosition3D(this->getX(), this->getY(), this->getZ());
109 }
110
111
112 /**
113 * Type conversion operator.
114 *
115 * \return position
116 */
117 operator JPosition3D() const
118 {
119 return getPosition();
120 }
121
122
123 /**
124 * Get UTM east.
125 *
126 * \return UTM East
127 */
128 double getUTMEast() const
129 {
130 return this->east;
131 }
132
133
134 /**
135 * Get UTM north.
136 *
137 * \return UTM North
138 */
139 double getUTMNorth() const
140 {
141 return this->north;
142 }
143
144
145 /**
146 * Get UTM Z.
147 *
148 * \return UTM Z
149 */
150 double getUTMZ() const
151 {
152 return this->z;
153 }
154
155
156 /**
157 * Get x.
158 *
159 * \return UTM East
160 */
161 double getX() const
162 {
163 return this->east;
164 }
165
166
167 /**
168 * Get y.
169 *
170 * \return UTM North
171 */
172 double getY() const
173 {
174 return this->north;
175 }
176
177
178 /**
179 * Get z.
180 *
181 * \return UTM Z
182 */
183 double getZ() const
184 {
185 return this->z;
186 }
187
188
189 /**
190 * Negate UTM position.
191 *
192 * \return this UTM position
193 */
195 {
196 east = -east;
197 north = -north;
198 z = -z;
199
200 return *this;
201 }
202
203
204 /**
205 * Add UTM position.
206 *
207 * \param pos UTM position
208 * \return this UTM position
209 */
211 {
212 east += pos.getUTMEast();
213 north += pos.getUTMNorth();
214 z += pos.getUTMZ();
215
216 return *this;
217 }
218
219
220 /**
221 * Subtract UTM position.
222 *
223 * \param pos UTM position
224 * \return this UTM position
225 */
227 {
228 east -= pos.getUTMEast();
229 north -= pos.getUTMNorth();
230 z -= pos.getUTMZ();
231
232 return *this;
233 }
234
235
236 /**
237 * Scale UTM position.
238 *
239 * \param factor multiplication factor
240 * \return this UTM position
241 */
242 JUTMPosition& mul(const double factor)
243 {
244 east *= factor;
245 north *= factor;
246 z *= factor;
247
248 return *this;
249 }
250
251
252 /**
253 * Scale UTM position.
254 *
255 * \param factor division factor
256 * \return this UTM position
257 */
258 JUTMPosition& div(const double factor)
259 {
260 east /= factor;
261 north /= factor;
262 z /= factor;
263
264 return *this;
265 }
266
267
268 /**
269 * Get displacement to position.
270 *
271 * The displacement corresponds to the 2D distance in the (East,North) plane.
272 *
273 * \param position position
274 * \return displacement
275 */
276 double getDisplacement(const JUTMPosition& position) const
277 {
278 const double x = this->getUTMEast() - position.getUTMEast();
279 const double y = this->getUTMNorth() - position.getUTMNorth();
280
281 return sqrt(x*x + y*y);
282 }
283
284
285 /**
286 * Read UTM position from input.
287 *
288 * \param in input stream
289 * \param pos UTM position
290 * \return input stream
291 */
292 friend inline std::istream& operator>>(std::istream& in, JUTMPosition& pos)
293 {
294 return in >> pos.east >> pos.north >> pos.z;
295 }
296
297
298 /**
299 * Write UTM position to output.
300 *
301 * \param out output stream
302 * \param pos UTM position
303 * \return output stream
304 */
305 friend inline std::ostream& operator<<(std::ostream& out, const JUTMPosition& pos)
306 {
307 const JFormat format[] = { JFormat(out, getFormat<JUTMPosition>(JFormat_t(12, 3, std::ios::fixed | std::ios::showpos))),
308 JFormat(out, getFormat<JPosition3D> (JFormat_t( 9, 3, std::ios::fixed | std::ios::showpos))) };
309
310 return out << format[0] << pos.east << ' '
311 << format[0] << pos.north << ' '
312 << format[1] << pos.z;
313 }
314
315
316
317 /**
318 * Read UTM position from input.
319 *
320 * \param in input stream
321 * \param pos UTM position
322 * \return input stream
323 */
324 friend inline JReader& operator>>(JReader& in, JUTMPosition& pos)
325 {
326 return in >> pos.east >> pos.north >> pos.z;
327 }
328
329
330 /**
331 * Write UTM position to output.
332 *
333 * \param out output stream
334 * \param pos UTM position
335 * \return output stream
336 */
337 friend inline JWriter& operator<<(JWriter& out, const JUTMPosition& pos)
338 {
339 return out << pos.east << pos.north << pos.z;
340 }
341
342
343 protected:
344 double east;
345 double north;
346 double z;
347 };
348
349
350 static const JUTMPosition JNorth_t(0,+1,0); //!< North
351 static const JUTMPosition JEast_t (+1,0,0); //!< East
352 static const JUTMPosition JSouth_t(0,-1,0); //!< South
353 static const JUTMPosition JWest_t (-1,0,0); //!< West
354}
355
356#endif
I/O manipulators.
JFormat_t & getFormat()
Get format for given type.
Definition JManip.hh:682
Base class for data structures with artithmetic capabilities.
Data structure for position in three dimensions.
Data structure for vector in three dimensions.
Definition JVector3D.hh:36
Interface for binary input.
Interface for binary output.
Data structure for UTM position.
double getZ() const
Get z.
double getUTMNorth() const
Get UTM north.
double getUTMEast() const
Get UTM east.
JUTMPosition(const JVector3D &pos)
Constructor.
double getY() const
Get y.
double getUTMZ() const
Get UTM Z.
double getDisplacement(const JUTMPosition &position) const
Get displacement to position.
JPosition3D getPosition() const
Get position.
JUTMPosition & mul(const double factor)
Scale UTM position.
JUTMPosition(const double east, const double north, const double z)
Constructor.
friend std::istream & operator>>(std::istream &in, JUTMPosition &pos)
Read UTM position from input.
JUTMPosition & div(const double factor)
Scale UTM position.
double getX() const
Get x.
JUTMPosition & add(const JUTMPosition &pos)
Add UTM position.
JUTMPosition & negate()
Negate UTM position.
friend JWriter & operator<<(JWriter &out, const JUTMPosition &pos)
Write UTM position to output.
friend JReader & operator>>(JReader &in, JUTMPosition &pos)
Read UTM position from input.
JUTMPosition & sub(const JUTMPosition &pos)
Subtract UTM position.
void setUTMPosition(const JUTMPosition &position)
Set UTM position.
const JUTMPosition & getUTMPosition() const
Get UTM position.
friend std::ostream & operator<<(std::ostream &out, const JUTMPosition &pos)
Write UTM position to output.
JUTMPosition()
Default constructor.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliaries for handling universal transverse mercator coordinate system (UTM).
Definition JUTMGrid.hh:20
static const JUTMPosition JWest_t(-1, 0, 0)
West.
static const JUTMPosition JSouth_t(0,-1, 0)
South.
static const JUTMPosition JEast_t(+1, 0, 0)
East.
static const JUTMPosition JNorth_t(0,+1, 0)
North.
Data structure for format specifications.
Definition JManip.hh:524
Auxiliary class to temporarily define format specifications.
Definition JManip.hh:636
Auxiliary base class for aritmetic operations of derived class types.
Definition JMath.hh:347