GeographicLib 2.7

Loading...
Searching...
No Matches
GeographicLib::LocalCartesian Class Reference

Local cartesian coordinates. More...

`#include <GeographicLib/LocalCartesian.hpp>`

## Public Member Functions
| LocalCartesian (real lat0, real lon0, real h0=0, const Geocentric &earth=Geocentric::WGS84())
| LocalCartesian (const Geocentric &earth=Geocentric::WGS84())
void | Reset (real lat0, real lon0, real h0=0)
void | Forward (real lat, real lon, real h, real &x, real &y, real &z) const
void | Forward (real lat, real lon, real h, real &x, real &y, real &z, std::vector< real > &M) const
void | Reverse (real x, real y, real z, real &lat, real &lon, real &h) const
void | Reverse (real x, real y, real z, real &lat, real &lon, real &h, std::vector< real > &M) const
Inspector functions
Math::real | LatitudeOrigin () const
Math::real | LongitudeOrigin () const
Math::real | HeightOrigin () const
Math::real | EquatorialRadius () const
Math::real | Flattening () const

## Detailed Description

Local cartesian coordinates.

Convert between geodetic coordinates latitude = lat, longitude = lon, height = h (measured vertically from the surface of the ellipsoid) to local cartesian coordinates (x, y, z). The origin of local cartesian coordinate system is at lat = lat0, lon = lon0, h = h0. The z axis is normal to the ellipsoid; the y axis points due north. The plane z = - h0 is tangent to the ellipsoid.

The conversions all take place via geocentric coordinates using a Geocentric object (by default Geocentric::WGS84()).

Example of use:

// Example of using the GeographicLib::LocalCartesian class
#include <iostream>
#include <exception>
#include <cmath>
#include <GeographicLib/Geocentric.hpp>
#include <GeographicLib/LocalCartesian.hpp>
using namespace std;
using namespace GeographicLib;
int main() {
try {
Geocentric earth(Constants::WGS84_a(), Constants::WGS84_f());
// Alternatively: const Geocentric& earth = Geocentric::WGS84();
const double lat0 = 48 + 50/60.0, lon0 = 2 + 20/60.0; // Paris
LocalCartesian proj(lat0, lon0, 0, earth);
{
// Sample forward calculation
double lat = 50.9, lon = 1.8, h = 0; // Calais
double x, y, z;
proj.Forward(lat, lon, h, x, y, z);
cout << x << " " << y << " " << z << "\n";
}
{
// Sample reverse calculation
double x = -38e3, y = 230e3, z = -4e3;
double lat, lon, h;
proj.Reverse(x, y, z, lat, lon, h);
cout << lat << " " << lon << " " << h << "\n";
}
}
catch (const exception& e) {
cerr << "Caught exception: " << e.what() << "\n";
return 1;
}
}
main
int main(int argc, const char *const argv[])
Definition Cart3Convert.cpp:52
Geocentric.hpp
Header for GeographicLib::Geocentric class.
LocalCartesian.hpp
Header for GeographicLib::LocalCartesian class.
GeographicLib::Constants::WGS84_f
static T WGS84_f()
Definition Constants.hpp:118
GeographicLib::Constants::WGS84_a
static T WGS84_a()
Definition Constants.hpp:112
GeographicLib::Geocentric
Geocentric coordinates
Definition Geocentric.hpp:67
GeographicLib::LocalCartesian::LocalCartesian
LocalCartesian(real lat0, real lon0, real h0=0, const Geocentric &earth=Geocentric::WGS84())
Definition LocalCartesian.hpp:64
GeographicLib
Namespace for GeographicLib.
Definition Accumulator.cpp:12
std
Definition NearestNeighbor.hpp:806

CartConvert is a command-line utility providing access to the functionality of Geocentric and LocalCartesian.

Definition at line 38 of file LocalCartesian.hpp.

## Constructor & Destructor Documentation

## ◆ LocalCartesian() [1/2]

GeographicLib::LocalCartesian::LocalCartesian | ( | real | lat0,
|  | real | lon0,
|  | real | h0 = 0,
|  | const Geocentric & | earth = Geocentric::WGS84() )
| inline

Constructor setting the origin.

Parameters

  [in] | lat0 | latitude at origin (degrees).
  [in] | lon0 | longitude at origin (degrees).
  [in] | h0 | height above ellipsoid at origin (meters); default 0.
  [in] | earth | Geocentric object for the transformation; default Geocentric::WGS84().

lat0 should be in the range [−90°, 90°].

Definition at line 64 of file LocalCartesian.hpp.

References Reset(), and GeographicLib::Geocentric::WGS84().

## ◆ LocalCartesian() [2/2]

GeographicLib::LocalCartesian::LocalCartesian | ( | const Geocentric & | earth = Geocentric::WGS84() | ) |
| inline explicit

Default constructor.

Parameters

  [in] | earth | Geocentric object for the transformation; default Geocentric::WGS84().

Sets lat0 = 0, lon0 = 0, h0 = 0.

Definition at line 77 of file LocalCartesian.hpp.

References Reset(), and GeographicLib::Geocentric::WGS84().

## Member Function Documentation

## ◆ Reset()

void GeographicLib::LocalCartesian::Reset | ( | real | lat0,
|  | real | lon0,
|  | real | h0 = 0 )

Reset the origin.

Parameters

  [in] | lat0 | latitude at origin (degrees).
  [in] | lon0 | longitude at origin (degrees).
  [in] | h0 | height above ellipsoid at origin (meters); default 0.

lat0 should be in the range [−90°, 90°].

Definition at line 16 of file LocalCartesian.cpp.

References GeographicLib::Math::AngNormalize(), GeographicLib::Math::LatFix(), and GeographicLib::Math::sincosd().

Referenced by LocalCartesian(), and LocalCartesian().

## ◆ Forward() [1/2]

void GeographicLib::LocalCartesian::Forward | ( | real | lat,
|  | real | lon,
|  | real | h,
|  | real & | x,
|  | real & | y,
|  | real & | z ) const
| inline

Convert from geodetic to local cartesian coordinates.

Parameters

  [in] | lat | latitude of point (degrees).
  [in] | lon | longitude of point (degrees).
  [in] | h | height of point above the ellipsoid (meters).
  [out] | x | local cartesian coordinate (meters).
  [out] | y | local cartesian coordinate (meters).
  [out] | z | local cartesian coordinate (meters).

lat should be in the range [−90°, 90°].

Definition at line 104 of file LocalCartesian.hpp.

Referenced by main().

## ◆ Forward() [2/2]

void GeographicLib::LocalCartesian::Forward | ( | real | lat,
|  | real | lon,
|  | real | h,
|  | real & | x,
|  | real & | y,
|  | real & | z,
|  | std::vector< real > & | M ) const
| inline

Convert from geodetic to local cartesian coordinates and return rotation matrix.

Parameters

  [in] | lat | latitude of point (degrees).
  [in] | lon | longitude of point (degrees).
  [in] | h | height of point above the ellipsoid (meters).
  [out] | x | local cartesian coordinate (meters).
  [out] | y | local cartesian coordinate (meters).
  [out] | z | local cartesian coordinate (meters).
  [out] | M | if the length of the vector is 9, fill with the rotation matrix in row-major order.

lat should be in the range [−90°, 90°].

Let v be a unit vector located at (lat, lon, h). We can express v as column vectors in one of two ways

- in east, north, up coordinates (where the components are relative to a local coordinate system at (lat, lon, h)); call this representation v1.
- in x, y, z coordinates (where the components are relative to the local coordinate system at (lat0, lon0, h0)); call this representation v0.

Then we have v0 = M ⋅ v1.

Definition at line 135 of file LocalCartesian.hpp.

## ◆ Reverse() [1/2]

void GeographicLib::LocalCartesian::Reverse | ( | real | x,
|  | real | y,
|  | real | z,
|  | real & | lat,
|  | real & | lon,
|  | real & | h ) const
| inline

Convert from local cartesian to geodetic coordinates.

Parameters

  [in] | x | local cartesian coordinate (meters).
  [in] | y | local cartesian coordinate (meters).
  [in] | z | local cartesian 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 minimizes |h |is returned, i.e., (lat, lon) corresponds to the closest point on the ellipsoid. The value of lon returned is in the range [−180°, 180°].

Definition at line 161 of file LocalCartesian.hpp.

Referenced by main().

## ◆ Reverse() [2/2]

void GeographicLib::LocalCartesian::Reverse | ( | real | x,
|  | real | y,
|  | real | z,
|  | real & | lat,
|  | real & | lon,
|  | real & | h,
|  | std::vector< real > & | M ) const
| inline

Convert from local cartesian to geodetic coordinates and return rotation matrix.

Parameters

  [in] | x | local cartesian coordinate (meters).
  [in] | y | local cartesian coordinate (meters).
  [in] | z | local cartesian 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

- in east, north, up coordinates (where the components are relative to a local coordinate system at (lat, lon, h)); call this representation v1.
- in x, y, z coordinates (where the components are relative to the local coordinate system at (lat0, lon0, h0)); call this representation v0.

Then we have v1 = MT ⋅ v0, where MT is the transpose of M.

Definition at line 191 of file LocalCartesian.hpp.

## ◆ LatitudeOrigin()

Math::real GeographicLib::LocalCartesian::LatitudeOrigin | ( |  | ) | const
| inline

Returns
  latitude of the origin (degrees).

Definition at line 208 of file LocalCartesian.hpp.

## ◆ LongitudeOrigin()

Math::real GeographicLib::LocalCartesian::LongitudeOrigin | ( |  | ) | const
| inline

Returns
  longitude of the origin (degrees).

Definition at line 213 of file LocalCartesian.hpp.

## ◆ HeightOrigin()

Math::real GeographicLib::LocalCartesian::HeightOrigin | ( |  | ) | const
| inline

Returns
  height of the origin (meters).

Definition at line 218 of file LocalCartesian.hpp.

## ◆ EquatorialRadius()

Math::real GeographicLib::LocalCartesian::EquatorialRadius | ( |  | ) | const
| inline

Returns
  a the equatorial radius of the ellipsoid (meters). This is the value of a inherited from the Geocentric object used in the constructor.

Definition at line 225 of file LocalCartesian.hpp.

## ◆ Flattening()

Math::real GeographicLib::LocalCartesian::Flattening | ( |  | ) | const
| inline

Returns
  f the flattening of the ellipsoid. This is the value inherited from the Geocentric object used in the constructor.

Definition at line 231 of file LocalCartesian.hpp.

The documentation for this class was generated from the following files:

- LocalCartesian.hpp
- LocalCartesian.cpp