NETGeographicLib  1.50.1
Public Member Functions | List of all members
NETGeographicLib::Geocentric Class Reference

.NET wrapper for GeographicLib::Geocentric. More...

#include <NETGeographicLib/Geocentric.h>

Public Member Functions

 Geocentric (double a, double f)
 
 Geocentric ()
 
 Geocentric (const GeographicLib::Geocentric &g)
 
 ~Geocentric ()
 
void Forward (double lat, double lon, double h, [System::Runtime::InteropServices::Out] double% X, [System::Runtime::InteropServices::Out] double% Y, [System::Runtime::InteropServices::Out] double% Z)
 
void Forward (double lat, double lon, double h, [System::Runtime::InteropServices::Out] double% X, [System::Runtime::InteropServices::Out] double% Y, [System::Runtime::InteropServices::Out] double% Z, [System::Runtime::InteropServices::Out] array< double, 2 >^% M)
 
void Reverse (double X, double Y, double Z, [System::Runtime::InteropServices::Out] double% lat, [System::Runtime::InteropServices::Out] double% lon, [System::Runtime::InteropServices::Out] double% h)
 
void Reverse (double X, double Y, double Z, [System::Runtime::InteropServices::Out] double% lat, [System::Runtime::InteropServices::Out] double% lon, [System::Runtime::InteropServices::Out] double% h, [System::Runtime::InteropServices::Out] array< double, 2 >^% M)
 

Inspector functions

double EquatorialRadius [get]
 
double Flattening [get]
 
System::IntPtr ^ GetUnmanaged ()
 

Detailed Description

.NET wrapper for GeographicLib::Geocentric.

This class allows .NET applications to access GeographicLib::Geocentric.

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 = 90°. 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.

C# Example:

using System;
namespace example_Geocentric
{
class Program
{
static void Main(string[] args)
{
try {
Geocentric earth = new Geocentric( Constants.WGS84.EquatorialRadius,
Constants.WGS84.Flattening);
// Alternatively: Geocentric earth = new Geocentric();
{
// Sample forward calculation
double lat = 27.99, lon = 86.93, h = 8820; // Mt Everest
double X, Y, Z;
earth.Forward(lat, lon, h, out X, out Y, out Z);
Console.WriteLine( String.Format( "{0} {1} {2}",
Math.Floor(X / 1000 + 0.5),
Math.Floor(Y / 1000 + 0.5),
Math.Floor(Z / 1000 + 0.5) ) );
}
{
// Sample reverse calculation
double X = 302e3, Y = 5636e3, Z = 2980e3;
double lat, lon, h;
earth.Reverse(X, Y, Z, out lat, out lon, out h);
Console.WriteLine(String.Format("{0} {1} {2}", lat, lon, h));
}
}
catch (GeographicErr e) {
Console.WriteLine( String.Format( "Caught exception: {0}", e.Message ) );
}
}
}
}

Managed C++ Example:

using namespace System;
using namespace NETGeographicLib;
int main(array<System::String ^> ^/*args*/)
{
try {
// Alternatively: Geocentric earth = new Geocentric();
{
// 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);
Console::WriteLine( String::Format( "{0} {1} {2}",
Math::Floor(X / 1000 + 0.5),
Math::Floor(Y / 1000 + 0.5),
Math::Floor(Z / 1000 + 0.5) ) );
}
{
// Sample reverse calculation
double X = 302e3, Y = 5636e3, Z = 2980e3;
double lat, lon, h;
earth->Reverse(X, Y, Z, lat, lon, h);
Console::WriteLine(String::Format("{0} {1} {2}", lat, lon, h));
}
}
catch (GeographicErr^ e) {
Console::WriteLine( String::Format( "Caught exception: {0}", e->Message ) );
return -1;
}
return 0;
}

Visual Basic Example:

Imports NETGeographicLib
Module example_Geocentric
Sub Main()
Try
Dim earth As Geocentric = New Geocentric(Constants.WGS84.EquatorialRadius,
Constants.WGS84.Flattening)
' Alternatively: Geocentric earth = new Geocentric();
' Sample forward calculation
Dim lat As Double = 27.99, lon = 86.93, h = 8820 ' Mt Everest
Dim X, Y, Z As Double
earth.Forward(lat, lon, h, X, Y, Z)
Console.WriteLine(String.Format("{0} {1} {2}",
Math.Floor(X / 1000 + 0.5),
Math.Floor(Y / 1000 + 0.5),
Math.Floor(Z / 1000 + 0.5)))
' Sample reverse calculation
X = 302000.0 : Y = 5636000.0 : Z = 2980000.0
earth.Reverse(X, Y, Z, lat, lon, h)
Console.WriteLine(String.Format("{0} {1} {2}", lat, lon, h))
Catch ex As GeographicErr
Console.WriteLine(String.Format("Caught exception: {0}", ex.Message))
End Try
End Sub
End Module

INTERFACE DIFFERENCES:
A default constructor is provided that assumes WGS84 parameters.

The EquatorialRadius and Flattening functions are implemented as properties.

The Forward and Reverse functions return rotation matrices as 2D, 3 × 3 arrays rather than vectors.

Definition at line 68 of file Geocentric.h.

Constructor & Destructor Documentation

◆ Geocentric() [1/3]

NETGeographicLib::Geocentric::Geocentric ( double  a,
double  f 
)

Constructor for a ellipsoid with

Parameters
[in]aequatorial radius (meters).
[in]fflattening of ellipsoid. Setting f = 0 gives a sphere. Negative f gives a prolate ellipsoid.
Exceptions
GeographicErrif a or (1 − f ) a is not positive.

◆ Geocentric() [2/3]

NETGeographicLib::Geocentric::Geocentric ( )

A default constructor which assumes WGS84.

Referenced by ~Geocentric().

◆ Geocentric() [3/3]

NETGeographicLib::Geocentric::Geocentric ( const GeographicLib::Geocentric g)

A constructor that is initialized from an unmanaged GeographicLib::Geocentric. For internal use only.

Parameters
[in]gAn existing GeographicLib::Geocentric.

◆ ~Geocentric()

NETGeographicLib::Geocentric::~Geocentric ( )
inline

The destructor calls the finalizer.

Definition at line 103 of file Geocentric.h.

References Geocentric().

Member Function Documentation

◆ Forward() [1/2]

void NETGeographicLib::Geocentric::Forward ( double  lat,
double  lon,
double  h,
[System::Runtime::InteropServices::Out] double%  X,
[System::Runtime::InteropServices::Out] double%  Y,
[System::Runtime::InteropServices::Out] double%  Z 
)

Convert from geodetic to geocentric coordinates.

Parameters
[in]latlatitude of point (degrees).
[in]lonlongitude of point (degrees).
[in]hheight of point above the ellipsoid (meters).
[out]Xgeocentric coordinate (meters).
[out]Ygeocentric coordinate (meters).
[out]Zgeocentric coordinate (meters).

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

◆ Forward() [2/2]

void NETGeographicLib::Geocentric::Forward ( double  lat,
double  lon,
double  h,
[System::Runtime::InteropServices::Out] double%  X,
[System::Runtime::InteropServices::Out] double%  Y,
[System::Runtime::InteropServices::Out] double%  Z,
[System::Runtime::InteropServices::Out] array< double, 2 >^%  M 
)

Convert from geodetic to geocentric coordinates and return rotation matrix.

Parameters
[in]latlatitude of point (degrees).
[in]lonlongitude of point (degrees).
[in]hheight of point above the ellipsoid (meters).
[out]Xgeocentric coordinate (meters).
[out]Ygeocentric coordinate (meters).
[out]Zgeocentric coordinate (meters).
[out]Ma 3 × 3 rotation matrix.

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 geocentric X, Y, Z coordinates; call this representation v0.

Then we have v0 = Mv1.

◆ Reverse() [1/2]

void NETGeographicLib::Geocentric::Reverse ( double  X,
double  Y,
double  Z,
[System::Runtime::InteropServices::Out] double%  lat,
[System::Runtime::InteropServices::Out] double%  lon,
[System::Runtime::InteropServices::Out] double%  h 
)

Convert from geocentric to geodetic to coordinates.

Parameters
[in]Xgeocentric coordinate (meters).
[in]Ygeocentric coordinate (meters).
[in]Zgeocentric coordinate (meters).
[out]latlatitude of point (degrees).
[out]lonlongitude of point (degrees).
[out]hheight 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°).

◆ Reverse() [2/2]

void NETGeographicLib::Geocentric::Reverse ( double  X,
double  Y,
double  Z,
[System::Runtime::InteropServices::Out] double%  lat,
[System::Runtime::InteropServices::Out] double%  lon,
[System::Runtime::InteropServices::Out] double%  h,
[System::Runtime::InteropServices::Out] array< double, 2 >^%  M 
)

Convert from geocentric to geodetic to coordinates.

Parameters
[in]Xgeocentric coordinate (meters).
[in]Ygeocentric coordinate (meters).
[in]Zgeocentric coordinate (meters).
[out]latlatitude of point (degrees).
[out]lonlongitude of point (degrees).
[out]hheight of point above the ellipsoid (meters).
[out]Ma 3 × 3 rotation matrix.

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 geocentric X, Y, Z coordinates; call this representation v0.

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

◆ GetUnmanaged()

System::IntPtr ^ NETGeographicLib::Geocentric::GetUnmanaged ( )
Returns
a pointer to the unmanaged GeographicLib::Geocentric.

Property Documentation

◆ EquatorialRadius

double NETGeographicLib::Geocentric::EquatorialRadius
get
Returns
a the equatorial radius of the ellipsoid (meters). This is the value used in the constructor.

Definition at line 210 of file Geocentric.h.

◆ Flattening

double NETGeographicLib::Geocentric::Flattening
get
Returns
f the flattening of the ellipsoid. This is the value used in the constructor.

Definition at line 210 of file Geocentric.h.


The documentation for this class was generated from the following file:
NETGeographicLib::Geocentric
.NET wrapper for GeographicLib::Geocentric.
Definition: Geocentric.h:69
NETGeographicLib::GeographicErr
Exception class for NETGeographicLib.
Definition: NETGeographicLib.h:133
NETGeographicLib::Geocentric::Geocentric
Geocentric()
main
int main(int argc, const char *const argv[])
NETGeographicLib::Constants::WGS84::EquatorialRadius
static double EquatorialRadius
The equatorial radius in meters.
Definition: NETGeographicLib.h:222
NETGeographicLib::Constants::WGS84::Flattening
static double Flattening
The flattening of the ellipsoid.
Definition: NETGeographicLib.h:224
NETGeographicLib::Geocentric::Forward
void Forward(double lat, double lon, double h, [System::Runtime::InteropServices::Out] double% X, [System::Runtime::InteropServices::Out] double% Y, [System::Runtime::InteropServices::Out] double% Z)
NETGeographicLib
Definition: Accumulator.h:14
NETGeographicLib::Geocentric::Reverse
void Reverse(double X, double Y, double Z, [System::Runtime::InteropServices::Out] double% lat, [System::Runtime::InteropServices::Out] double% lon, [System::Runtime::InteropServices::Out] double% h)