Skip to content

Commit 5f69d18

Browse files
author
Davide Faconti
committed
fix
1 parent 2942d22 commit 5f69d18

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

include/geodetic_utils/geodetic_conv.hpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,33 @@ static double kFirstEccentricitySquared = 6.69437999014 * 0.001;
1212
static double kSecondEccentricitySquared = 6.73949674228 * 0.001;
1313
static double kFlattening = 1 / 298.257223563;
1414

15+
16+
inline double rad2Deg(const double radians)
17+
{
18+
return (radians / M_PI) * 180.0;
19+
}
20+
21+
inline double deg2Rad(const double degrees)
22+
{
23+
return (degrees / 180.0) * M_PI;
24+
}
25+
1526
inline void Geodetic2Ecef(const double latitude, const double longitude, const double altitude,
1627
double* x, double* y, double* z)
1728
{
1829
// Convert geodetic coordinates to ECEF.
1930
// http://code.google.com/p/pysatel/source/browse/trunk/coord.py?r=22
20-
double lat_rad = deg2Rad(latitude);
21-
double lon_rad = deg2Rad(longitude);
22-
double xi = sqrt(1 - kFirstEccentricitySquared * sin(lat_rad) * sin(lat_rad));
23-
*x = (kSemimajorAxis / xi + altitude) * cos(lat_rad) * cos(lon_rad);
24-
*y = (kSemimajorAxis / xi + altitude) * cos(lat_rad) * sin(lon_rad);
25-
*z = (kSemimajorAxis / xi * (1 - kFirstEccentricitySquared) + altitude) * sin(lat_rad);
31+
const double lat_rad = deg2Rad(latitude);
32+
const double lon_rad = deg2Rad(longitude);
33+
const double sLat = sin(lat_rad);
34+
const double sLon = sin(lon_rad);
35+
const double cLat = cos(lat_rad);
36+
const double cLon = cos(lon_rad);
37+
38+
double xi = sqrt(1 - kFirstEccentricitySquared * sLat * sLat);
39+
*x = (kSemimajorAxis / xi + altitude) * cLat * cLon;
40+
*y = (kSemimajorAxis / xi + altitude) * cLat * sLon;
41+
*z = (kSemimajorAxis / xi * (1 - kFirstEccentricitySquared) + altitude) * sLat;
2642
}
2743

2844
void Ecef2Geodetic(const double x, const double y, const double z,
@@ -240,18 +256,6 @@ class GeodeticConverter
240256
return ret;
241257
}
242258

243-
inline static
244-
double rad2Deg(const double radians)
245-
{
246-
return (radians / M_PI) * 180.0;
247-
}
248-
249-
inline static
250-
double deg2Rad(const double degrees)
251-
{
252-
return (degrees / 180.0) * M_PI;
253-
}
254-
255259
double initial_latitude_;
256260
double initial_longitude_;
257261
double initial_altitude_;

0 commit comments

Comments
 (0)