GeographicLib
1.21
|
Geocentric coordinates More...
#include <GeographicLib/Geocentric.hpp>
Public Member Functions | |
Geocentric (real a, real f) | |
Geocentric () | |
void | Forward (real lat, real lon, real h, real &X, real &Y, real &Z) const throw () |
void | Forward (real lat, real lon, real h, real &X, real &Y, real &Z, std::vector< real > &M) const throw () |
void | Reverse (real X, real Y, real Z, real &lat, real &lon, real &h) const throw () |
void | Reverse (real X, real Y, real Z, real &lat, real &lon, real &h, std::vector< real > &M) const throw () |
Inspector functions | |
bool | Init () const throw () |
Math::real | MajorRadius () const throw () |
Math::real | Flattening () const throw () |
Static Public Attributes | |
static const Geocentric | WGS84 |
Friends | |
class | LocalCartesian |
class | MagneticCircle |
class | MagneticModel |
class | GravityCircle |
class | GravityModel |
class | NormalGravity |
class | SphericalHarmonic |
class | SphericalHarmonic1 |
class | SphericalHarmonic2 |
Geocentric coordinates
Convert between geodetic coordinates latitude = lat, longitude = lon, height = h (measured vertically from the surface of the ellipsoid) to geocentric coordinates (X, Y, Z). The origin of geocentric coordinates is at the center of the earth. The Z axis goes thru the north pole, lat = 90o. The X axis goes thru lat = 0, lon = 0. Geocentric coordinates are also known as earth centered, earth fixed (ECEF) coordinates.
The conversion from geographic to geocentric coordinates is straightforward. For the reverse transformation we use
Several changes have been made to ensure that the method returns accurate results for all finite inputs (even if h is infinite). The changes are described in Appendix B of
See Geocentric coordinates for more information.
The errors in these routines are close to round-off. Specifically, for points within 5000 km of the surface of the ellipsoid (either inside or outside the ellipsoid), the error is bounded by 7 nm (7 nanometers) for the WGS84 ellipsoid. See Geocentric coordinates for further information on the errors.
Example of use:
// Example of using the GeographicLib::Geocentric class // $Id: fea8cd4d5464b6029d6a135a25230892f52f318f $ #include <iostream> #include <exception> #include <cmath> #include <GeographicLib/Geocentric.hpp> using namespace std; using namespace GeographicLib; int main() { try { Geocentric earth(Constants::WGS84_a(), Constants::WGS84_f()); // Alternatively: const Geocentric& earth = Geocentric::WGS84; { // Sample forward calculation double lat = 27.99, lon = 86.93, h = 8820; // Mt Everest double X, Y, Z; earth.Forward(lat, lon, h, X, Y, Z); cout << floor(X / 1000 + 0.5) << " " << floor(Y / 1000 + 0.5) << " " << floor(Z / 1000 + 0.5) << "\n"; } { // Sample reverse calculation double X = 302e3, Y = 5636e3, Z = 2980e3; double lat, lon, h; earth.Reverse(X, Y, Z, lat, lon, h); cout << lat << " " << lon << " " << h << "\n"; } } catch (const exception& e) { cerr << "Caught exception: " << e.what() << "\n"; return 1; } return 0; }
CartConvert is a command-line utility providing access to the functionality of Geocentric and LocalCartesian.
GeographicLib::Geocentric::Geocentric | ( | real | a, |
real | f | ||
) |
Constructor for a ellipsoid with
[in] | a | equatorial radius (meters). |
[in] | f | flattening of ellipsoid. Setting f = 0 gives a sphere. Negative f gives a prolate ellipsoid. If f > 1, set flattening to 1/f. |
An exception is thrown if either of the axes of the ellipsoid is non-positive.
Definition at line 22 of file Geocentric.cpp.
References GeographicLib::Math::isfinite().
GeographicLib::Geocentric::Geocentric | ( | ) | [inline] |
A default constructor (for use by NormalGravity).
Definition at line 119 of file Geocentric.hpp.
void GeographicLib::Geocentric::Forward | ( | real | lat, |
real | lon, | ||
real | h, | ||
real & | X, | ||
real & | Y, | ||
real & | Z | ||
) | const throw () [inline] |
Convert from geodetic to geocentric coordinates.
[in] | lat | latitude of point (degrees). |
[in] | lon | longitude of point (degrees). |
[in] | h | height of point above the ellipsoid (meters). |
[out] | X | geocentric coordinate (meters). |
[out] | Y | geocentric coordinate (meters). |
[out] | Z | geocentric coordinate (meters). |
lat should be in the range [-90, 90]; lon and lon0 should be in the range [-180, 360].
Definition at line 134 of file Geocentric.hpp.
Referenced by main().
void GeographicLib::Geocentric::Forward | ( | real | lat, |
real | lon, | ||
real | h, | ||
real & | X, | ||
real & | Y, | ||
real & | Z, | ||
std::vector< real > & | M | ||
) | const throw () [inline] |
Convert from geodetic to geocentric coordinates and return rotation matrix.
[in] | lat | latitude of point (degrees). |
[in] | lon | longitude of point (degrees). |
[in] | h | height of point above the ellipsoid (meters). |
[out] | X | geocentric coordinate (meters). |
[out] | Y | geocentric coordinate (meters). |
[out] | Z | geocentric coordinate (meters). |
[out] | M | if the length of the vector is 9, fill with the rotation matrix in row-major order. |
Let v be a unit vector located at (lat, lon, h). We can express v as column vectors in one of two ways
Then we have v0 = M . v1.
Definition at line 163 of file Geocentric.hpp.
void GeographicLib::Geocentric::Reverse | ( | real | X, |
real | Y, | ||
real | Z, | ||
real & | lat, | ||
real & | lon, | ||
real & | h | ||
) | const throw () [inline] |
Convert from geocentric to geodetic to coordinates.
[in] | X | geocentric coordinate (meters). |
[in] | Y | geocentric coordinate (meters). |
[in] | Z | geocentric coordinate (meters). |
[out] | lat | latitude of point (degrees). |
[out] | lon | longitude of point (degrees). |
[out] | h | height of point above the ellipsoid (meters). |
In general there are multiple solutions and the result which maximizes h is returned. If there are still multiple solutions with different latitudes (applies only if Z = 0), then the solution with lat > 0 is returned. If there are still multiple solutions with different longitudes (applies only if X = Y = 0) then lon = 0 is returned. The value of h returned satisfies h >= - a (1 - e2) / sqrt(1 - e2 sin2lat). The value of lon returned is in the range [-180, 180).
Definition at line 195 of file Geocentric.hpp.
Referenced by main().
void GeographicLib::Geocentric::Reverse | ( | real | X, |
real | Y, | ||
real | Z, | ||
real & | lat, | ||
real & | lon, | ||
real & | h, | ||
std::vector< real > & | M | ||
) | const throw () [inline] |
Convert from geocentric to geodetic to coordinates.
[in] | X | geocentric coordinate (meters). |
[in] | Y | geocentric coordinate (meters). |
[in] | Z | geocentric coordinate (meters). |
[out] | lat | latitude of point (degrees). |
[out] | lon | longitude of point (degrees). |
[out] | h | height of point above the ellipsoid (meters). |
[out] | M | if the length of the vector is 9, fill with the rotation matrix in row-major order. |
Let v be a unit vector located at (lat, lon, h). We can express v as column vectors in one of two ways
Then we have v1 = M^T . v0, where M^T is the transpose of M.
Definition at line 224 of file Geocentric.hpp.
bool GeographicLib::Geocentric::Init | ( | ) | const throw () [inline] |
Definition at line 243 of file Geocentric.hpp.
Math::real GeographicLib::Geocentric::MajorRadius | ( | ) | const throw () [inline] |
Definition at line 248 of file Geocentric.hpp.
Math::real GeographicLib::Geocentric::Flattening | ( | ) | const throw () [inline] |
Definition at line 255 of file Geocentric.hpp.
friend class LocalCartesian [friend] |
Definition at line 66 of file Geocentric.hpp.
friend class MagneticCircle [friend] |
Definition at line 67 of file Geocentric.hpp.
friend class MagneticModel [friend] |
Definition at line 68 of file Geocentric.hpp.
friend class GravityCircle [friend] |
Definition at line 69 of file Geocentric.hpp.
friend class GravityModel [friend] |
Definition at line 70 of file Geocentric.hpp.
friend class NormalGravity [friend] |
Definition at line 71 of file Geocentric.hpp.
friend class SphericalHarmonic [friend] |
Definition at line 72 of file Geocentric.hpp.
friend class SphericalHarmonic1 [friend] |
Definition at line 73 of file Geocentric.hpp.
friend class SphericalHarmonic2 [friend] |
Definition at line 74 of file Geocentric.hpp.
const Geocentric GeographicLib::Geocentric::WGS84 [static] |
A global instantiation of Geocentric with the parameters for the WGS84 ellipsoid.
Definition at line 272 of file Geocentric.hpp.