10 #ifndef GEOGRAPHIC_TO_CARTESIAN 11 #define GEOGRAPHIC_TO_CARTESIAN 16 #include <geometry_msgs/Point32.h> 17 #include <geographic_msgs/GeoPoint.h> 18 #include <geodesy/utm.h> 20 inline geometry_msgs::Point32 geographic_to_cartesian (geographic_msgs::GeoPoint actual_coordinate_geo, geographic_msgs::GeoPoint origin_geo)
22 geodesy::UTMPoint actual_coordinate_UTM(actual_coordinate_geo);
23 geodesy::UTMPoint origin_UTM(origin_geo);
25 geometry_msgs::Point32 actual_coordinate_cartesian;
33 if(
int(actual_coordinate_UTM.zone)==60 && origin_UTM.zone==1 ) {
34 geographic_msgs::GeoPoint geo_180_w;
35 geographic_msgs::GeoPoint geo_180_e;
36 geo_180_w.longitude = 179.9999999;
37 geo_180_w.latitude = actual_coordinate_geo.latitude;
38 geo_180_w.altitude = actual_coordinate_geo.altitude;
39 geo_180_e.longitude = -179.9999999;
40 geo_180_e.latitude = actual_coordinate_geo.latitude;
41 geo_180_e.altitude = actual_coordinate_geo.altitude;
42 geodesy::UTMPoint utm_180_w(geo_180_w);
43 geodesy::UTMPoint utm_180_e(geo_180_e);
44 actual_coordinate_cartesian.x = actual_coordinate_UTM.easting - utm_180_w.easting + utm_180_e.easting - origin_UTM.easting;
45 }
else if( origin_UTM.zone==60 &&
int(actual_coordinate_UTM.zone)==1 ) {
46 geographic_msgs::GeoPoint geo_180_w;
47 geographic_msgs::GeoPoint geo_180_e;
48 geo_180_w.longitude = 179.9999999;
49 geo_180_w.latitude = actual_coordinate_geo.latitude;
50 geo_180_w.altitude = actual_coordinate_geo.altitude;
51 geo_180_e.longitude = -179.9999999;
52 geo_180_e.latitude = actual_coordinate_geo.latitude;
53 geo_180_e.altitude = actual_coordinate_geo.altitude;
54 geodesy::UTMPoint utm_180_w(geo_180_w);
55 geodesy::UTMPoint utm_180_e(geo_180_e);
56 actual_coordinate_cartesian.x = actual_coordinate_UTM.easting - utm_180_e.easting + utm_180_w.easting - origin_UTM.easting;
57 }
else if(
int(actual_coordinate_UTM.zone) < origin_UTM.zone ) {
58 int quotient_from_int_division = (int) ( std::max(std::abs(actual_coordinate_geo.longitude),std::abs(origin_geo.longitude))/6 );
59 double border_longitude = quotient_from_int_division * 6.0 *pow(-1,std::signbit(std::max(actual_coordinate_geo.longitude,origin_geo.longitude)));
60 geographic_msgs::GeoPoint geo_w;
61 geographic_msgs::GeoPoint geo_e;
62 geo_w.longitude = border_longitude - 0.0000001;
63 geo_w.latitude = actual_coordinate_geo.latitude;
64 geo_w.altitude = actual_coordinate_geo.altitude;
65 geo_e.longitude = border_longitude + 0.0000001;
66 geo_e.latitude = actual_coordinate_geo.latitude;
67 geo_e.altitude = actual_coordinate_geo.altitude;
68 geodesy::UTMPoint utm_w(geo_w);
69 geodesy::UTMPoint utm_e(geo_e);
70 actual_coordinate_cartesian.x = actual_coordinate_UTM.easting - utm_w.easting + utm_e.easting - origin_UTM.easting;
71 }
else if( origin_UTM.zone <
int(actual_coordinate_UTM.zone) ) {
72 int quotient_from_int_division = (int) ( std::max(std::abs(actual_coordinate_geo.longitude),std::abs(origin_geo.longitude))/6 );
73 double border_longitude = quotient_from_int_division * 6.0 *pow(-1,std::signbit(std::max(actual_coordinate_geo.longitude,origin_geo.longitude)));
74 geographic_msgs::GeoPoint geo_w;
75 geographic_msgs::GeoPoint geo_e;
76 geo_w.longitude = border_longitude - 0.0000001;
77 geo_w.latitude = actual_coordinate_geo.latitude;
78 geo_w.altitude = actual_coordinate_geo.altitude;
79 geo_e.longitude = border_longitude + 0.0000001;
80 geo_e.latitude = actual_coordinate_geo.latitude;
81 geo_e.altitude = actual_coordinate_geo.altitude;
82 geodesy::UTMPoint utm_w(geo_w);
83 geodesy::UTMPoint utm_e(geo_e);
84 actual_coordinate_cartesian.x = actual_coordinate_UTM.easting - utm_e.easting + utm_w.easting - origin_UTM.easting;
89 actual_coordinate_cartesian.x = actual_coordinate_UTM.easting -origin_UTM.easting;
93 if( origin_UTM.band==
'N' && actual_coordinate_UTM.band==
'M' ) {
94 geographic_msgs::GeoPoint geo_0_n;
95 geographic_msgs::GeoPoint geo_0_s;
96 geo_0_n.longitude = actual_coordinate_geo.longitude;
97 geo_0_n.latitude = 0.0000001;
98 geo_0_n.altitude = actual_coordinate_geo.altitude;
99 geo_0_s.longitude = actual_coordinate_geo.longitude;
100 geo_0_s.latitude = -0.0000001;
101 geo_0_s.altitude = actual_coordinate_geo.altitude;
102 geodesy::UTMPoint utm_0_n(geo_0_n);
103 geodesy::UTMPoint utm_0_s(geo_0_s);
104 actual_coordinate_cartesian.y = actual_coordinate_UTM.northing - utm_0_s.northing + utm_0_n.northing - origin_UTM.northing;
105 }
else if( actual_coordinate_UTM.band==
'N' && origin_UTM.band==
'M' ) {
106 geographic_msgs::GeoPoint geo_0_n;
107 geographic_msgs::GeoPoint geo_0_s;
108 geo_0_n.longitude = actual_coordinate_geo.longitude;
109 geo_0_n.latitude = 0.0000001;
110 geo_0_n.altitude = actual_coordinate_geo.altitude;
111 geo_0_s.longitude = actual_coordinate_geo.longitude;
112 geo_0_s.latitude = -0.0000001;
113 geo_0_s.altitude = actual_coordinate_geo.altitude;
114 geodesy::UTMPoint utm_0_n(geo_0_n);
115 geodesy::UTMPoint utm_0_s(geo_0_s);
116 actual_coordinate_cartesian.y = actual_coordinate_UTM.northing - utm_0_n.northing + utm_0_s.northing - origin_UTM.northing;
121 actual_coordinate_cartesian.y = actual_coordinate_UTM.northing-origin_UTM.northing;
125 actual_coordinate_cartesian.z = actual_coordinate_UTM.altitude-origin_UTM.altitude;
127 return actual_coordinate_cartesian;