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

 Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019