Main MRPT website > C++ reference for MRPT 1.9.9
test.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 |
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 <mrpt/topography.h>
11 #include <iostream>
12 
13 using namespace mrpt;
14 using namespace mrpt::poses;
15 using namespace mrpt::math;
16 using namespace std;
17 
18 void TestGPS_coords()
19 {
20  // ENU:
22  RAD2DEG(0.6408472493152757), // lat
23  RAD2DEG(-0.0780454933097760), // lon
24  53.200600 // height meters
25  );
26 
28  RAD2DEG(0.6408615769267271), // lat
29  RAD2DEG(-0.0780621148947297), // lon
30  56.210100 // meters
31  );
32 
33  cout << "Point 0: lat=" << p0.lat << " lon=" << p0.lon
34  << " alt=" << p0.height << endl;
35  cout << "Point 1: lat=" << p1.lat << " lon=" << p1.lon
36  << " alt=" << p1.height << endl;
37 
40  cout << "ENU XYZ coords: " << p << endl;
41 
42  // Geocentric:
43  const mrpt::topography::TGeodeticCoords pt0(32.0, -10.0, 0.0);
44  const mrpt::topography::TGeodeticCoords pt1(32.0, -10.0, 500.0);
45 
46  mrpt::math::TPoint3D geo0, geo1;
49  cout << "P0 XYZ geocentric coords: " << geo0 << endl;
50  cout << "P1 XYZ geocentric coords: " << geo1 << endl;
51 
52  // ENU_axes_from_WGS84
53  mrpt::math::TPose3D pose_ENU;
55  pt0.lon, pt0.lat, pt0.height, pose_ENU);
56  cout << "ENU system of coordinates for lat=" << pt0.lat
57  << " lon=" << pt0.lon << " alt=" << pt0.height << " is: \n"
58  << mrpt::poses::CPose3D(pose_ENU)
60  << endl;
61 
62  cout << "P0->P1: " << (geo1 - geo0) << endl;
63  cout << "(p1.h-p0.h)*ENU_Z: "
64  << (pt1.height - pt0.height) *
65  mrpt::poses::CPose3D(pose_ENU)
67  .block<3, 1>(0, 2)
68  .transpose()
69  << endl;
70 
71  // UTM:
72  // See: http://www.mathworks.com/matlabcentral/fileexchange/10915
73  cout << endl << "UTM coordinate test:" << endl;
74 
75  double lats[] = {40.3154333, 46.283900, 37.577833,
76  28.645650, 38.855550, 25.061783};
77  double lons[] = {-3.4857166, 7.8012333, -119.95525,
78  -17.759533, -94.7990166, 121.640266};
79  int zone;
80  char band;
81  for (size_t i = 0; i < sizeof(lats) / sizeof(lats[0]); i++)
82  {
83  topography::TUTMCoords UTMCoords;
84  const double la = lats[i];
85  const double lo = lons[i];
86  // mrpt::topography::LatLonToUTM( la,lo, x,y,zone,band );
88  topography::TGeodeticCoords(la, lo, 0), UTMCoords, zone, band);
89  cout << "Lat: " << la << " Lon: " << lo << " x: " << UTMCoords.x
90  << " y: " << UTMCoords.y << " zone: " << zone << " band: " << band
91  << endl;
92  }
93 }
94 
96 {
97  const double lon0 = -3.733572031; // RAD2DEG( 0.6408472493152757L );
98  const double lat0 = 37.89250616; // RAD2DEG(-0.0780454933097760L );
99  const double h0 = 515.579; // 53.200600; // meters
100 
101  cout << endl;
102  cout << format("Point: lon=%.012f lat=%.012f h=%.04f\n", lon0, lat0, h0);
103 
106  mrpt::topography::TGeodeticCoords(lon0, lat0, h0), p);
107 
108  cout << "In geocentric coords: " << p << endl;
109 }
110 
111 // ------------------------------------------------------
112 // MAIN
113 // ------------------------------------------------------
114 int main()
115 {
116  try
117  {
118  TestGPS_coords();
120  return 0;
121  }
122  catch (exception& e)
123  {
124  cout << "MRPT exception caught: " << e.what() << endl;
125  return -1;
126  }
127  catch (...)
128  {
129  printf("Untyped exception!!");
130  return -1;
131  }
132 }
TestGPS_coords
void TestGPS_coords()
Definition: vision_stereo_rectify/test.cpp:18
mrpt::topography::ENU_axes_from_WGS84
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.
Definition: conversions.cpp:150
mrpt::topography::geodeticToENU_WGS84
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...
Definition: conversions.cpp:126
topography.h
mrpt::poses::CPose3D::getRotationMatrix
void getRotationMatrix(mrpt::math::CMatrixDouble33 &ROT) const
Get the 3x3 rotation matrix.
Definition: CPose3D.h:232
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
p
GLfloat GLfloat p
Definition: glext.h:6305
mrpt::poses
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CHierarchicalMapMHPartition.h:25
mrpt::RAD2DEG
double RAD2DEG(const double x)
Radians to degrees.
Definition: core/include/mrpt/core/bits_math.h:48
mrpt::topography::geodeticToUTM
void geodeticToUTM(const TGeodeticCoords &GeodeticCoords, TUTMCoords &UTMCoords, int &UTMZone, char &UTMLatitudeBand, const TEllipsoid &ellip=TEllipsoid::Ellipsoid_WGS84())
Definition: conversions.cpp:333
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::topography::geodeticToGeocentric_WGS84
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...
Definition: conversions.cpp:193
mrpt::topography::TGeodeticCoords
A set of geodetic coordinates: latitude, longitude and height, defined over a given geoid (typically,...
Definition: data_types.h:195
mrpt::format
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
mrpt::math::TPoint3D::x
double x
X,Y,Z coordinates.
Definition: lightweight_geom_data.h:385
mrpt::math::TPose3D
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
Definition: lightweight_geom_data.h:603
mrpt::poses::CPoseOrPoint::getHomogeneousMatrixVal
MATRIX44 getHomogeneousMatrixVal() const
Returns the corresponding 4x4 homogeneous transformation matrix for the point(translation) or pose (t...
Definition: CPoseOrPoint.h:275
mrpt::math::CMatrixFixedNumeric
A numeric matrix of compile-time fixed size.
Definition: CMatrixFixedNumeric.h:40
TestGeoid2Geocentric
void TestGeoid2Geocentric()
Definition: vision_stereo_rectify/test.cpp:95
mrpt::math::TPoint3D
Lightweight 3D point.
Definition: lightweight_geom_data.h:378
mrpt::math::TPoint3D::y
double y
Definition: lightweight_geom_data.h:385
transpose
GLsizei GLboolean transpose
Definition: glext.h:4133
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST