Main MRPT website > C++ reference for MRPT 1.9.9
conversions.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "topography-precomp.h" // Precompiled headers
11 
13 #include <mrpt/poses/CPoint3D.h>
14 #include <mrpt/poses/CPose3D.h>
15 #include <mrpt/math/utils.h>
16 #include <mrpt/math/geometry.h>
17 
18 using namespace std;
19 using namespace mrpt;
20 using namespace mrpt::math;
21 using namespace mrpt::utils;
22 using namespace mrpt::poses;
23 
25 {
26  return a.decimal_value == o.decimal_value;
27 }
29 {
30  return !(a == o);
31 }
33  const TGeodeticCoords& a, const TGeodeticCoords& o)
34 {
35  return a.lat == o.lat && a.lon == o.lon && a.height == o.height;
36 }
38  const TGeodeticCoords& a, const TGeodeticCoords& o)
39 {
40  return !(a == o);
41 }
42 
43 //#define M_PI_TOPO 3.141592653589793
44 // inline double DEG2RAD(const double x) { return x*M_PI_TOPO/180.0; }
45 
46 // Define a generic type for "precission numbers":
47 #ifdef HAVE_LONG_DOUBLE
48 typedef long double precnum_t;
49 #else
50 typedef double precnum_t;
51 #endif
52 
53 std::ostream& mrpt::topography::operator<<(std::ostream& out, const TCoords& o)
54 {
55  return out << o.getAsString();
56 }
57 
58 /*---------------------------------------------------------------
59  geocentricToENU_WGS84
60  ---------------------------------------------------------------*/
62  const mrpt::math::TPoint3D& P_geocentric_,
63  mrpt::math::TPoint3D& out_ENU_point,
64  const TGeodeticCoords& in_coords_origin)
65 {
66  // Generate reference 3D point:
67  TPoint3D P_geocentric_ref;
68  geodeticToGeocentric_WGS84(in_coords_origin, P_geocentric_ref);
69 
70  const double clat = cos(DEG2RAD(in_coords_origin.lat)),
71  slat = sin(DEG2RAD(in_coords_origin.lat));
72  const double clon = cos(DEG2RAD(in_coords_origin.lon)),
73  slon = sin(DEG2RAD(in_coords_origin.lon));
74 
75  // Compute the resulting relative coordinates:
76  // For using smaller numbers:
77  const mrpt::math::TPoint3D P_geocentric = P_geocentric_ - P_geocentric_ref;
78 
79  // Optimized calculation: Local transformed coordinates of P_geo(x,y,z)
80  // after rotation given by the transposed rotation matrix from ENU ->
81  // ECEF.
82  out_ENU_point.x = -slon * P_geocentric.x + clon * P_geocentric.y;
83  out_ENU_point.y = -clon * slat * P_geocentric.x -
84  slon * slat * P_geocentric.y + clat * P_geocentric.z;
85  out_ENU_point.z = clon * clat * P_geocentric.x +
86  slon * clat * P_geocentric.y + slat * P_geocentric.z;
87 }
88 
90  const std::vector<mrpt::math::TPoint3D>& in_geocentric_points,
91  std::vector<mrpt::math::TPoint3D>& out_ENU_points,
92  const TGeodeticCoords& in_coords_origin)
93 {
94  // Generate reference 3D point:
95  TPoint3D P_geocentric_ref;
96  geodeticToGeocentric_WGS84(in_coords_origin, P_geocentric_ref);
97 
98  const double clat = cos(DEG2RAD(in_coords_origin.lat)),
99  slat = sin(DEG2RAD(in_coords_origin.lat));
100  const double clon = cos(DEG2RAD(in_coords_origin.lon)),
101  slon = sin(DEG2RAD(in_coords_origin.lon));
102 
103  const size_t N = in_geocentric_points.size();
104  out_ENU_points.resize(N);
105  for (size_t i = 0; i < N; i++)
106  {
107  // Compute the resulting relative coordinates for using smaller numbers:
108  const mrpt::math::TPoint3D P_geocentric =
109  in_geocentric_points[i] - P_geocentric_ref;
110 
111  // Optimized calculation: Local transformed coordinates of P_geo(x,y,z)
112  // after rotation given by the transposed rotation matrix from ENU ->
113  // ECEF.
114  out_ENU_points[i].x = -slon * P_geocentric.x + clon * P_geocentric.y;
115  out_ENU_points[i].y = -clon * slat * P_geocentric.x -
116  slon * slat * P_geocentric.y +
117  clat * P_geocentric.z;
118  out_ENU_points[i].z = clon * clat * P_geocentric.x +
119  slon * clat * P_geocentric.y +
120  slat * P_geocentric.z;
121  }
122 }
123 
124 /*---------------------------------------------------------------
125  geodeticToENU_WGS84
126  ---------------------------------------------------------------*/
128  const TGeodeticCoords& in_coords, mrpt::math::TPoint3D& out_ENU_point,
129  const TGeodeticCoords& in_coords_origin)
130 {
131  // --------------------------------------------------------------------
132  // Explanation: We compute the earth-centric coordinates first,
133  // then make a system transformation to local XYZ coordinates
134  // using a system of three orthogonal vectors as local reference.
135  //
136  // See: http://en.wikipedia.org/wiki/Reference_ellipsoid
137  // (JLBC 21/DEC/2006) (Fixed: JLBC 9/JUL/2008)
138  // - Oct/2013, Emilio Sanjurjo: Fixed UP vector pointing exactly normal to
139  // ellipsoid surface.
140  // --------------------------------------------------------------------
141  // Generate 3D point:
142  TPoint3D P_geocentric;
143  geodeticToGeocentric_WGS84(in_coords, P_geocentric);
144 
145  geocentricToENU_WGS84(P_geocentric, out_ENU_point, in_coords_origin);
146 }
147 
148 /*---------------------------------------------------------------
149  ENU_axes_from_WGS84
150  ---------------------------------------------------------------*/
152  double in_longitude_reference_degrees, double in_latitude_reference_degrees,
153  double in_height_reference_meters, mrpt::math::TPose3D& out_ENU,
154  bool only_angles)
155 {
156  // See "coordinatesTransformation_WGS84" for more comments.
157  TPoint3D PPref;
160  in_latitude_reference_degrees, in_longitude_reference_degrees,
161  in_height_reference_meters),
162  PPref);
163 
164  const double clat = cos(DEG2RAD(in_latitude_reference_degrees)),
165  slat = sin(DEG2RAD(in_latitude_reference_degrees));
166  const double clon = cos(DEG2RAD(in_longitude_reference_degrees)),
167  slon = sin(DEG2RAD(in_longitude_reference_degrees));
168 
169  CMatrixDouble44 HM; // zeros by default
170  HM(0, 0) = -slon;
171  HM(0, 1) = -clon * slat;
172  HM(0, 2) = clon * clat;
173  HM(1, 0) = clon;
174  HM(1, 1) = -slon * slat;
175  HM(1, 2) = slon * clat;
176  HM(2, 0) = 0;
177  HM(2, 1) = clat;
178  HM(2, 2) = slat;
179  HM(3, 3) = 1;
180 
181  if (!only_angles)
182  {
183  HM(0, 3) = PPref.x;
184  HM(1, 3) = PPref.y;
185  HM(2, 3) = PPref.z;
186  }
187 
188  out_ENU = mrpt::math::TPose3D(CPose3D(HM));
189 }
190 
191 //*---------------------------------------------------------------
192 // geodeticToGeocentric_WGS84
193 // ---------------------------------------------------------------*/
195  const TGeodeticCoords& in_coords, mrpt::math::TPoint3D& out_point)
196 {
197  // --------------------------------------------------------------------
198  // See: http://en.wikipedia.org/wiki/Reference_ellipsoid
199  // Constants are for WGS84
200  // --------------------------------------------------------------------
201 
202  static const precnum_t a =
203  6378137L; // Semi-major axis of the Earth (meters)
204  static const precnum_t b = 6356752.3142L; // Semi-minor axis:
205 
206  static const precnum_t ae = acos(b / a); // eccentricity:
207  static const precnum_t cos2_ae_earth =
208  square(cos(ae)); // The cos^2 of the angular eccentricity of the Earth:
209  // // 0.993305619995739L;
210  static const precnum_t sin2_ae_earth =
211  square(sin(ae)); // The sin^2 of the angular eccentricity of the Earth:
212  // // 0.006694380004261L;
213 
214  const precnum_t lon = DEG2RAD(precnum_t(in_coords.lon));
215  const precnum_t lat = DEG2RAD(precnum_t(in_coords.lat));
216 
217  // The radius of curvature in the prime vertical:
218  const precnum_t N = a / std::sqrt(1 - sin2_ae_earth * square(sin(lat)));
219 
220  // Generate 3D point:
221  out_point.x = (N + in_coords.height) * cos(lat) * cos(lon);
222  out_point.y = (N + in_coords.height) * cos(lat) * sin(lon);
223  out_point.z = (cos2_ae_earth * N + in_coords.height) * sin(lat);
224 }
225 
226 /*---------------------------------------------------------------
227  geodeticToGeocentric_WGS84
228  ---------------------------------------------------------------*/
230  const TGeodeticCoords& in_coords, TGeocentricCoords& out_point,
231  const TEllipsoid& ellip)
232 {
233  static const precnum_t a =
234  ellip.sa; // Semi-major axis of the Earth (meters)
235  static const precnum_t b = ellip.sb; // Semi-minor axis:
236 
237  static const precnum_t ae = acos(b / a); // eccentricity:
238  static const precnum_t cos2_ae_earth =
239  square(cos(ae)); // The cos^2 of the angular eccentricity of the Earth:
240  // // 0.993305619995739L;
241  static const precnum_t sin2_ae_earth =
242  square(sin(ae)); // The sin^2 of the angular eccentricity of the Earth:
243  // // 0.006694380004261L;
244 
245  const precnum_t lon = DEG2RAD(precnum_t(in_coords.lon));
246  const precnum_t lat = DEG2RAD(precnum_t(in_coords.lat));
247 
248  // The radius of curvature in the prime vertical:
249  const precnum_t N = a / std::sqrt(1 - sin2_ae_earth * square(sin(lat)));
250 
251  // Generate 3D point:
252  out_point.x = (N + in_coords.height) * cos(lat) * cos(lon);
253  out_point.y = (N + in_coords.height) * cos(lat) * sin(lon);
254  out_point.z = (cos2_ae_earth * N + in_coords.height) * sin(lat);
255 }
256 
257 /*---------------------------------------------------------------
258  geocentricToGeodetic
259  ---------------------------------------------------------------*/
261  const TGeocentricCoords& in_point, TGeodeticCoords& out_coords,
262  const TEllipsoid& ellip)
263 {
264  const double sa2 = ellip.sa * ellip.sa;
265  const double sb2 = ellip.sb * ellip.sb;
266 
267  const double e2 = (sa2 - sb2) / sa2;
268  const double ep2 = (sa2 - sb2) / sb2;
269  const double p = sqrt(in_point.x * in_point.x + in_point.y * in_point.y);
270  const double theta = atan2(in_point.z * ellip.sa, p * ellip.sb);
271 
272  out_coords.lon = atan2(in_point.y, in_point.x);
273  out_coords.lat = atan2(
274  in_point.z + ep2 * ellip.sb * sin(theta) * sin(theta) * sin(theta),
275  p - e2 * ellip.sa * cos(theta) * cos(theta) * cos(theta));
276 
277  const double clat = cos(out_coords.lat);
278  const double slat = sin(out_coords.lat);
279  const double N = sa2 / sqrt(sa2 * clat * clat + sb2 * slat * slat);
280 
281  out_coords.height = p / clat - N;
282 
283  out_coords.lon = RAD2DEG(out_coords.lon);
284  out_coords.lat = RAD2DEG(out_coords.lat);
285 }
286 
287 /*---------------------------------------------------------------
288  UTMToGeodesic
289  ---------------------------------------------------------------*/
291  double X, double Y, int huso, char hem, double& out_lon /*degrees*/,
292  double& out_lat /*degrees*/, const TEllipsoid& ellip)
293 {
294  ASSERT_(hem == 's' || hem == 'S' || hem == 'n' || hem == 'N');
295 
296  X = X - 5e5;
297  if (hem == 's' || hem == 'S') Y = Y - 1e7;
298 
299  const precnum_t lon0 = huso * 6 - 183;
300  const precnum_t a2 = ellip.sa * ellip.sa;
301  const precnum_t b2 = ellip.sb * ellip.sb;
302  const precnum_t ep2 = (a2 - b2) / b2;
303  const precnum_t c = a2 / ellip.sb;
304  const precnum_t latp = Y / (6366197.724 * 0.9996);
305  const precnum_t clp2 = square(cos(latp));
306 
307  const precnum_t v = c * 0.9996 / sqrt(1 + ep2 * clp2);
308  const precnum_t na = X / v;
309  const precnum_t A1 = sin(2 * latp);
310  const precnum_t A2 = A1 * clp2;
311  const precnum_t J2 = latp + A1 * 0.5;
312  const precnum_t J4 = 0.75 * J2 + 0.25 * A2;
313  const precnum_t J6 = (5 * J4 + A2 * clp2) / 3;
314 
315  const precnum_t alp = 0.75 * ep2;
316  const precnum_t beta = (5.0 / 3.0) * alp * alp;
317  const precnum_t gam = (35.0 / 27.0) * alp * alp * alp;
318  const precnum_t B = 0.9996 * c * (latp - alp * J2 + beta * J4 - gam * J6);
319  const precnum_t nb = (Y - B) / v;
320  const precnum_t psi = (ep2 * square(na)) / 2 * clp2;
321  const precnum_t eps = na * (1 - psi / 3);
322  const precnum_t nu = nb * (1 - psi) + latp;
323  const precnum_t she = (exp(eps) - exp(-eps)) / 2;
324  const precnum_t dlon = atan2(she, cos(nu));
325  const precnum_t tau = atan2(cos(dlon) * tan(nu), 1);
326 
327  out_lon = RAD2DEG(dlon) + lon0;
328  out_lat = RAD2DEG(
329  latp +
330  (1 + ep2 * clp2 - 1.5 * ep2 * sin(latp) * cos(latp) * (tau - latp)) *
331  (tau - latp));
332 }
333 
335  const TGeodeticCoords& GeodeticCoords, TUTMCoords& UTMCoords, int& UTMZone,
336  char& UTMLatitudeBand, const TEllipsoid& ellip)
337 {
338  const double la = GeodeticCoords.lat;
339  char Letra;
340  if (la < -72)
341  Letra = 'C';
342  else if (la < -64)
343  Letra = 'D';
344  else if (la < -56)
345  Letra = 'E';
346  else if (la < -48)
347  Letra = 'F';
348  else if (la < -40)
349  Letra = 'G';
350  else if (la < -32)
351  Letra = 'H';
352  else if (la < -24)
353  Letra = 'J';
354  else if (la < -16)
355  Letra = 'K';
356  else if (la < -8)
357  Letra = 'L';
358  else if (la < 0)
359  Letra = 'M';
360  else if (la < 8)
361  Letra = 'N';
362  else if (la < 16)
363  Letra = 'P';
364  else if (la < 24)
365  Letra = 'Q';
366  else if (la < 32)
367  Letra = 'R';
368  else if (la < 40)
369  Letra = 'S';
370  else if (la < 48)
371  Letra = 'T';
372  else if (la < 56)
373  Letra = 'U';
374  else if (la < 64)
375  Letra = 'V';
376  else if (la < 72)
377  Letra = 'W';
378  else
379  Letra = 'X';
380 
381  const precnum_t lat = DEG2RAD(GeodeticCoords.lat);
382  const precnum_t lon = DEG2RAD(GeodeticCoords.lon);
383  const int Huso = mrpt::utils::fix((GeodeticCoords.lon / 6) + 31);
384  const precnum_t lon0 = DEG2RAD(Huso * 6 - 183);
385 
386  const precnum_t sa = ellip.sa;
387  const precnum_t sb = ellip.sb;
388  // const precnum_t e2 = (sa*sa-sb*sb)/(sa*sa);
389  const precnum_t ep2 = (sa * sa - sb * sb) / (sb * sb);
390  const precnum_t c = sa * sa / sb;
391  // const precnum_t alp = (sa-sb)/sa;
392 
393  const precnum_t Dlon = lon - lon0;
394  const precnum_t clat = cos(lat);
395  const precnum_t sDlon = sin(Dlon);
396  const precnum_t cDlon = cos(Dlon);
397 
398  const precnum_t A = clat * sDlon;
399  const precnum_t eps = 0.5 * log((1 + A) / (1 - A));
400  const precnum_t nu = atan2(tan(lat), cDlon) - lat;
401  const precnum_t v = 0.9996 * c / sqrt(1 + ep2 * clat * clat);
402  const precnum_t psi = 0.5 * ep2 * eps * eps * clat * clat;
403  const precnum_t A1 = sin(2 * lat);
404  const precnum_t A2 = A1 * clat * clat;
405  const precnum_t J2 = lat + 0.5 * A1;
406  const precnum_t J4 = 0.75 * J2 + 0.25 * A2;
407  const precnum_t J6 = (5.0 * J4 + A2 * clat * clat) / 3;
408  const precnum_t nalp = 0.75 * ep2;
409  const precnum_t nbet = (5.0 / 3.0) * nalp * nalp;
410  const precnum_t ngam = (35.0 / 27.0) * nalp * nalp * nalp;
411  const precnum_t B = 0.9996 * c * (lat - nalp * J2 + nbet * J4 - ngam * J6);
412 
413  UTMCoords.x = eps * v * (1 + psi / 3.0) + 500000;
414  UTMCoords.y = nu * v * (1 + psi) + B;
415  UTMCoords.z = GeodeticCoords.height;
416 
417  UTMZone = Huso;
418  UTMLatitudeBand = Letra;
419 }
420 
421 /*---------------------------------------------------------------
422  LatLonToUTM
423  ---------------------------------------------------------------*/
425  double la, double lo, double& xx, double& yy, int& out_UTM_zone,
426  char& out_UTM_latitude_band, const TEllipsoid& ellip)
427 {
428  // This method is based on public code by Gabriel Ruiz Martinez and Rafael
429  // Palacios.
430  // http://www.mathworks.com/matlabcentral/fileexchange/10915
431 
432  const double sa = ellip.sa;
433  const double sb = ellip.sb;
434  const double e2 = (sqrt((sa * sa) - (sb * sb))) / sb;
435 
436  const double e2cuadrada = e2 * e2;
437 
438  const double c = (sa * sa) / sb;
439 
440  const double lat = DEG2RAD(la);
441  const double lon = DEG2RAD(lo);
442 
443  const int Huso = mrpt::utils::fix((lo / 6) + 31);
444  double S = ((Huso * 6) - 183);
445  double deltaS = lon - DEG2RAD(S);
446 
447  char Letra;
448 
449  if (la < -72)
450  Letra = 'C';
451  else if (la < -64)
452  Letra = 'D';
453  else if (la < -56)
454  Letra = 'E';
455  else if (la < -48)
456  Letra = 'F';
457  else if (la < -40)
458  Letra = 'G';
459  else if (la < -32)
460  Letra = 'H';
461  else if (la < -24)
462  Letra = 'J';
463  else if (la < -16)
464  Letra = 'K';
465  else if (la < -8)
466  Letra = 'L';
467  else if (la < 0)
468  Letra = 'M';
469  else if (la < 8)
470  Letra = 'N';
471  else if (la < 16)
472  Letra = 'P';
473  else if (la < 24)
474  Letra = 'Q';
475  else if (la < 32)
476  Letra = 'R';
477  else if (la < 40)
478  Letra = 'S';
479  else if (la < 48)
480  Letra = 'T';
481  else if (la < 56)
482  Letra = 'U';
483  else if (la < 64)
484  Letra = 'V';
485  else if (la < 72)
486  Letra = 'W';
487  else
488  Letra = 'X';
489 
490  const double a = cos(lat) * sin(deltaS);
491  const double epsilon = 0.5 * log((1 + a) / (1 - a));
492  const double nu = atan(tan(lat) / cos(deltaS)) - lat;
493  const double v = (c / sqrt((1 + (e2cuadrada * square(cos(lat)))))) * 0.9996;
494  const double ta = 0.5 * e2cuadrada * square(epsilon) * square(cos(lat));
495  const double a1 = sin(2 * lat);
496  const double a2 = a1 * square(cos(lat));
497  const double j2 = lat + 0.5 * a1;
498  const double j4 = ((3.0 * j2) + a2) / 4.0;
499  const double j6 = ((5.0 * j4) + (a2 * square(cos(lat)))) / 3.0;
500  const double alfa = 0.75 * e2cuadrada;
501  const double beta = (5.0 / 3.0) * pow(alfa, 2.0);
502  const double gama = (35.0 / 27.0) * pow(alfa, 3.0);
503  const double Bm = 0.9996 * c * (lat - alfa * j2 + beta * j4 - gama * j6);
504 
505  xx = epsilon * v * (1 + (ta / 3.0)) + 500000;
506  yy = nu * v * (1 + ta) + Bm;
507 
508  if (yy < 0) yy += 9999999;
509 
510  out_UTM_zone = Huso;
511  out_UTM_latitude_band = Letra;
512 }
513 
514 /** 7-parameter Bursa-Wolf transformation:
515  * [ X Y Z ]_WGS84 = [ dX dY dZ ] + ( 1 + dS ) [ 1 RZ -RY; -RZ 1 RX; RY -RX 1
516  * ] [ X Y Z ]_local
517  * \sa transform10params
518  */
520  const mrpt::math::TPoint3D& p, const TDatum7Params& d,
522 {
523  const double scale = (1 + d.dS);
524 
525  o.x = d.dX + scale * (p.x + p.y * d.Rz - p.z * d.Ry);
526  o.y = d.dY + scale * (-p.x * d.Rz + p.y + p.z * d.Rx);
527  o.z = d.dZ + scale * (p.x * d.Ry - p.y * d.Rx + p.z);
528 }
529 
530 /** 7-parameter Bursa-Wolf transformation TOPCON:
531  * [ X Y Z ]_WGS84 = [ dX dY dZ ] + ( 1 + dS ) [ 1 RZ -RY; -RZ 1 RX; RY -RX 1
532  * ] [ X Y Z ]_local
533  * \sa transform10params
534  */
538 {
539  const double scale = (1 + d.dS);
540 
541  o.x = d.dX + scale * (d.m11 * p.x + d.m12 * p.y + d.m13 * p.z);
542  o.y = d.dY + scale * (d.m21 * p.x + d.m22 * p.y + d.m23 * p.z);
543  o.z = d.dZ + scale * (d.m31 * p.x + d.m32 * p.y + d.m33 * p.z);
544 }
545 
546 /** 10-parameter Molodensky-Badekas transformation:
547  * [ X Y Z ]_WGS84 = [ dX dY dZ ] + ( 1 + dS ) [ 1 RZ -RY; -RZ 1 RX; RY -RX 1
548  * ] [ X-Xp Y-Yp Z-Zp ]_local + [Xp Yp Zp]
549  * \sa transform7params
550  */
552  const mrpt::math::TPoint3D& p, const TDatum10Params& d,
554 {
555  const double scale = (1 + d.dS);
556 
557  const double px = p.x - d.Xp;
558  const double py = p.y - d.Yp;
559  const double pz = p.z - d.Zp;
560 
561  o.x = d.dX + scale * (px + py * d.Rz - pz * d.Ry) + d.Xp;
562  o.y = d.dY + scale * (-px * d.Rz + py + pz * d.Rx) + d.Yp;
563  o.z = d.dZ + scale * (px * d.Ry - py * d.Rx + pz) + d.Zp;
564 }
565 
566 /** Helmert 2D transformation:
567  * [ X Y ]_WGS84 = [ dX dY ] + ( 1 + dS ) [ cos(alpha) -sin(alpha);
568  * sin(alpha) cos(alpha) ] [ X-Xp Y-Yp Z-Zp ]_local + [Xp Yp Zp]
569  * \sa transformHelmert3D
570  */
572  const mrpt::math::TPoint2D& p, const TDatumHelmert2D& d,
574 {
575  const double scale = (1 + d.dS);
576 
577  const double px = p.x - d.Xp;
578  const double py = p.y - d.Yp;
579 
580  o.x = d.dX + scale * (px * cos(d.alpha) - py * sin(d.alpha)) + d.Xp;
581  o.y = d.dY + scale * (px * sin(d.alpha) + py * cos(d.alpha)) + d.Yp;
582 }
583 
584 /** Helmert 2D transformation:
585  * [ X Y ]_WGS84 = [ dX dY ] + ( 1 + dS ) [ cos(alpha) -sin(alpha);
586  * sin(alpha) cos(alpha) ] [ X-Xp Y-Yp Z-Zp ]_local + [Xp Yp Zp]
587  * \sa transformHelmert3D
588  */
592 {
593  o.x = d.a * p.x + d.b * p.y + d.c;
594  o.y = -d.b * p.x + d.a * p.y + d.d;
595 }
596 
597 /** Helmert 3D transformation:
598  * [ X Y ]_WGS84 = [ dX dY ] + ( 1 + dS ) [ cos(alpha) -sin(alpha);
599  * sin(alpha) cos(alpha) ] [ X-Xp Y-Yp Z-Zp ]_local + [Xp Yp Zp]
600  * \sa transformHelmert3D
601  */
603  const mrpt::math::TPoint3D& p, const TDatumHelmert3D& d,
605 {
606  TDatum7Params d2(d.dX, d.dY, d.dZ, -1 * d.Rx, -1 * d.Ry, -1 * d.Rz, d.dS);
607  transform7params(p, d2, o);
608 }
609 
610 /** Helmert 3D transformation:
611  * [ X Y ]_WGS84 = [ dX dY ] + ( 1 + dS ) [ cos(alpha) -sin(alpha);
612  * sin(alpha) cos(alpha) ] [ X-Xp Y-Yp Z-Zp ]_local + [Xp Yp Zp]
613  * \sa transformHelmert3D
614  */
618 {
619  o.x = d.a * p.x + d.b * p.y + d.c;
620  o.y = d.d * p.x + d.e * p.y + d.f;
621  o.z = p.z + d.g;
622 }
623 
624 /** 1D transformation:
625  * [ Z ]_WGS84 = (dy * X - dx * Y + Z)*(1+e)+DZ
626  * \sa transformHelmert3D
627  */
629  const mrpt::math::TPoint3D& p, const TDatum1DTransf& d,
631 {
632  o.x = p.x;
633  o.y = p.y;
634  o.z = (d.dY * p.x - d.dX * p.y + p.z) * (1 + d.dS) + d.DZ;
635 }
636 
637 /** 1D transformation:
638  * [ X;Y ]_WGS84 = [X;Y]_locales+[1 -sin(d.beta);0
639  * cos(d.beta)]*[x*d.dSx;y*d.dSy ]
640  * \sa transformHelmert3D
641  */
645 {
646  o.x = d.dX + p.x * d.dSx - p.y * d.dSy * sin(d.beta);
647  o.y = d.dY + p.y * d.dSy * cos(d.beta);
648  o.z = p.z;
649 }
650 
651 /** ENU to geocentric coordinates.
652  * \sa geodeticToENU_WGS84
653  */
655  const mrpt::math::TPoint3D& p, const TGeodeticCoords& in_coords_origin,
656  TGeocentricCoords& out_coords, const TEllipsoid& ellip)
657 {
658  // Generate reference 3D point:
659  TPoint3D P_geocentric_ref;
661  in_coords_origin, P_geocentric_ref, ellip);
662 
663  CVectorDouble P_ref(3);
664  P_ref[0] = P_geocentric_ref.x;
665  P_ref[1] = P_geocentric_ref.y;
666  P_ref[2] = P_geocentric_ref.z;
667 
668  // Z axis -> In direction out-ward the center of the Earth:
669  CVectorDouble REF_X(3), REF_Y(3), REF_Z(3);
670  math::normalize(P_ref, REF_Z);
671 
672  // 1st column: Starting at the reference point, move in the tangent
673  // direction
674  // east-ward: I compute this as the derivative of P_ref wrt "longitude":
675  // A_east[0] =-(N+in_height_meters)*cos(lat)*sin(lon); --> -Z[1]
676  // A_east[1] = (N+in_height_meters)*cos(lat)*cos(lon); --> Z[0]
677  // A_east[2] = 0; --> 0
678  // ---------------------------------------------------------------------------
679  CVectorDouble AUX_X(3);
680  AUX_X[0] = -REF_Z[1];
681  AUX_X[1] = REF_Z[0];
682  AUX_X[2] = 0;
683  math::normalize(AUX_X, REF_X);
684 
685  // 2nd column: The cross product:
686  math::crossProduct3D(REF_Z, REF_X, REF_Y);
687 
688  out_coords.x =
689  REF_X[0] * p.x + REF_Y[0] * p.y + REF_Z[0] * p.z + P_geocentric_ref.x;
690  out_coords.y =
691  REF_X[1] * p.x + REF_Y[1] * p.y + REF_Z[1] * p.z + P_geocentric_ref.y;
692  out_coords.z =
693  REF_X[2] * p.x + REF_Y[2] * p.y + REF_Z[2] * p.z + P_geocentric_ref.z;
694 }
void transformHelmert2D_TOPCON(const mrpt::math::TPoint2D &p, const TDatumHelmert2D_TOPCON &d, mrpt::math::TPoint2D &o)
Helmert 2D transformation: [ X Y ]_WGS84 = [ dX dY ] + ( 1 + dS ) [ cos(alpha) -sin(alpha); sin(alpha...
double sa
largest semiaxis of the reference ellipsoid (in meters)
Definition: data_types.h:93
double dX
Deltas (X,Y,Z)
Definition: data_types.h:227
double dX
Deltas (X,Y,Z)
Definition: data_types.h:281
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
void transformHelmert2D(const mrpt::math::TPoint2D &p, const TDatumHelmert2D &d, mrpt::math::TPoint2D &o)
Helmert 2D transformation: [ X Y ]_WGS84 = [ dX dY ] + ( 1 + dS ) [ cos(alpha) -sin(alpha); sin(alpha...
double x
X,Y coordinates.
double dS
Scale factor (in ppm) (Scale is 1+dS/1e6)
Definition: data_types.h:251
Parameters for a topographic transfomation.
Definition: data_types.h:337
Parameters for a topographic transfomation.
Definition: data_types.h:305
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:6502
double Rx
Rotation components.
Definition: data_types.h:285
void transform7params(const mrpt::math::TPoint3D &in_point, const TDatum7Params &in_datum, mrpt::math::TPoint3D &out_point)
7-parameter Bursa-Wolf transformation: [ X Y Z ]_WGS84 = [ dX dY dZ ] + ( 1 + dS ) [ 1 RZ -RY; -RZ 1 ...
void ENU_axes_from_WGS84(double in_longitude_reference_degrees, double in_latitude_reference_degrees, double in_height_reference_meters, mrpt::math::TPose3D &out_ENU, bool only_angles=false)
Returns the East-North-Up (ENU) coordinate system associated to the given point.
A set of geodetic coordinates: latitude, longitude and height, defined over a given geoid (typically...
Definition: data_types.h:196
double dS
Scale factor (in ppm) (Scale is 1+dS/1e6)
Definition: data_types.h:231
bool operator!=(const TCoords &a, const TCoords &o)
Definition: conversions.cpp:28
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
Definition: eigen_frwds.h:42
bool operator==(const TCoords &a, const TCoords &o)
Definition: conversions.cpp:24
double dS
Scale factor (Scale is 1+dS)
Definition: data_types.h:381
STL namespace.
double Xp
To be substracted to the input point.
Definition: data_types.h:283
void transform1D(const mrpt::math::TPoint3D &p, const TDatum1DTransf &d, mrpt::math::TPoint3D &o)
1D transformation: [ Z ]_WGS84 = (dy * X - dx * Y + Z)*(1+e)+DZ
void geodeticToENU_WGS84(const TGeodeticCoords &in_coords, mrpt::math::TPoint3D &out_ENU_point, const TGeodeticCoords &in_coords_origin)
Coordinates transformation from longitude/latitude/height to ENU (East-North-Up) X/Y/Z coordinates Th...
void geodeticToGeocentric(const TGeodeticCoords &in_coords, TGeocentricCoords &out_point, const TEllipsoid &ellip)
Coordinates transformation from longitude/latitude/height to geocentric X/Y/Z coordinates (with an sp...
double Rx
Rotation components.
Definition: data_types.h:342
A coordinate that is stored as a simple "decimal" angle in degrees, but can be retrieved/set in the f...
Definition: data_types.h:28
void geocentricToENU_WGS84(const mrpt::math::TPoint3D &in_geocentric_point, mrpt::math::TPoint3D &out_ENU_point, const TGeodeticCoords &in_coords_origin)
ENU to EFEC (Geocentric) coordinates.
Definition: conversions.cpp:61
void transformHelmert3D_TOPCON(const mrpt::math::TPoint3D &p, const TDatumHelmert3D_TOPCON &d, mrpt::math::TPoint3D &o)
Helmert 3D transformation: [ X Y ]_WGS84 = [ dX dY ] + ( 1 + dS ) [ cos(alpha) -sin(alpha); sin(alpha...
void transform10params(const mrpt::math::TPoint3D &in_point, const TDatum10Params &in_datum, mrpt::math::TPoint3D &out_point)
10-parameter Molodensky-Badekas transformation: [ X Y Z ]_WGS84 = [ dX dY dZ ] + ( 1 + dS ) [ 1 RZ -R...
void crossProduct3D(const T &v0, const U &v1, V &vOut)
Computes the cross product of two 3D vectors, returning a vector normal to both.
Definition: geometry.h:811
double dSx
Scale factor in X and Y.
Definition: data_types.h:399
T square(const T x)
Inline function for the square of a number.
Definition: bits.h:55
std::string getAsString() const
Return a std::string in the format "DEGdeg MIN&#39; SEC&#39;&#39;".
Definition: data_types.h:69
double Rx
Rotation components (in secs)
Definition: data_types.h:229
Parameters for a topographic transfomation.
Definition: data_types.h:361
void transfInterpolation(const mrpt::math::TPoint3D &p, const TDatumTransfInterpolation &d, mrpt::math::TPoint3D &o)
Interpolation: [ Z ]_WGS84 = (dy * X - dx * Y + Z)*(1+e)+DZ.
double sb
smallest semiaxis of the reference ellipsoid (in meters)
Definition: data_types.h:95
Parameters for a topographic transfomation.
Definition: data_types.h:376
A numeric matrix of compile-time fixed size.
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
TCoords lon
Longitude (in degrees)
Definition: data_types.h:213
void geodeticToUTM(const TGeodeticCoords &GeodeticCoords, TUTMCoords &UTMCoords, int &UTMZone, char &UTMLatitudeBand, const TEllipsoid &ellip=TEllipsoid::Ellipsoid_WGS84())
void geocentricToGeodetic(const TGeocentricCoords &in_point, TGeodeticCoords &out_coords, const TEllipsoid &ellip=TEllipsoid::Ellipsoid_WGS84())
Coordinates transformation from geocentric X/Y/Z coordinates to longitude/latitude/height.
const GLubyte * c
Definition: glext.h:6313
double lat
[deg], [deg], hgt over sea level[m]
GLubyte GLubyte b
Definition: glext.h:6279
const double eps
double dS
Scale factor (Scale is 1+dS)
Definition: data_types.h:287
double x
X,Y,Z coordinates.
#define DEG2RAD
double dS
Scale factor (Scale is 1+dS)
Definition: data_types.h:344
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
void UTMToGeodetic(double X, double Y, int zone, char hem, double &out_lon, double &out_lat, const TEllipsoid &ellip=TEllipsoid::Ellipsoid_WGS84())
Returns the Geodetic coordinates of the UTM input point.
void normalize(Scalar valMin, Scalar valMax)
Scales all elements such as the minimum & maximum values are shifted to the given values...
#define RAD2DEG
const GLdouble * v
Definition: glext.h:3678
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Parameters for a topographic transfomation.
Definition: data_types.h:278
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
void ENUToGeocentric(const mrpt::math::TPoint3D &in_ENU_point, const TGeodeticCoords &in_coords_origin, TGeocentricCoords &out_coords, const TEllipsoid &ellip)
ENU to geocentric coordinates.
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
std::ostream & operator<<(std::ostream &out, const TCoords &o)
Definition: conversions.cpp:53
double dX
Deltas (X,Y,Z)
Definition: data_types.h:340
double height
Geodetic height (in meters)
Definition: data_types.h:215
#define ASSERT_(f)
void geodeticToGeocentric_WGS84(const TGeodeticCoords &in_coords, mrpt::math::TPoint3D &out_point)
Coordinates transformation from longitude/latitude/height to geocentric X/Y/Z coordinates (with a WGS...
Lightweight 3D point.
double decimal_value
Also obtained directly through the double(void) operator using a TCoords anywhere were a double is ex...
Definition: data_types.h:33
void GeodeticToUTM(double in_latitude_degrees, double in_longitude_degrees, double &out_UTM_x, double &out_UTM_y, int &out_UTM_zone, char &out_UTM_latitude_band, const TEllipsoid &ellip=TEllipsoid::Ellipsoid_WGS84())
Convert latitude and longitude coordinates into UTM coordinates, computing the corresponding UTM zone...
Parameters for a topographic transfomation.
Definition: data_types.h:224
Lightweight 2D point.
Parameters for a topographic transfomation.
Definition: data_types.h:394
GLubyte GLubyte GLubyte a
Definition: glext.h:6279
GLfloat GLfloat p
Definition: glext.h:6305
void transformHelmert3D(const mrpt::math::TPoint3D &p, const TDatumHelmert3D &d, mrpt::math::TPoint3D &o)
Helmert3D transformation: [ X Y Z ]_WGS84 = [ dX dY dZ ] + ( 1 + dS ) [ 1 -RZ RY; RZ 1 -RX; -RY RX 1 ...
TCoords lat
Latitude (in degrees)
Definition: data_types.h:211
int fix(T x)
Rounds toward zero.
Definition: bits.h:168
void transform7params_TOPCON(const mrpt::math::TPoint3D &in_point, const TDatum7Params_TOPCON &in_datum, mrpt::math::TPoint3D &out_point)
7-parameter Bursa-Wolf transformation TOPCON: [ X Y Z ]_WGS84 = [ dX dY dZ ] + ( 1 + dS ) [ 1 RZ -RY;...
double precnum_t
Definition: conversions.cpp:50
double dX
Deltas (X,Y,Z)
Definition: data_types.h:379



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019