Function tryGeocentricToGeodetic

Convert geocentric Cartesian coordinates to geodetic coordinates.

bool tryGeocentricToGeodetic(T)(
  const GeocentricCoordinate!T source,
  const Ellipsoid!T ellipsoid,
  out GeodeticCoordinate!T result
) pure nothrow @nogc @safe
if (isGeodesyScalar!T);

Implements the reverse direction of EPSG coordinate operation method 9602. X/Y/Z and the ellipsoid axes must use the same linear unit; the returned ellipsoidal height uses that unit. No datum transformation is performed.

The exact geocentre has no unique geodetic inverse and is rejected. On the rotation axis, longitude is indeterminate and is canonically returned as zero. The implementation provides robust spherical/oblate inverse semantics across the documented domain.

Numerical accuracy contract for the validated terrestrial domain:

- ellipsoids: WGS 84, GRS 80, and Airy 1830; - latitude: the full legal range; - ellipsoidal height: -20 km through +100 km.

Within that domain, float results reproduce represented Cartesian position within 2 m and ellipsoidal height within 0.1 m. double and real reproduce represented Cartesian position within 1 mm. These are numerical conversion-error bounds, not datum, survey, GNSS, observation, or physical-position accuracy claims.

Parameters

NameDescription
source Finite geocentric Cartesian coordinate.
ellipsoid Valid spherical or oblate reference ellipsoid using the same linear unit as the Cartesian components.
result Receives the geodetic coordinate on success.

Returns

true when a defined finite representable inverse exists; false for an invalid ellipsoid, the exact geocentre, or an unrepresentable result.

No allocation is performed.

References

EPSG Guidance Note 7-2, method 9602; T. Fukushima, Journal of Geodesy 79 (2006); H. Vermeille, direct geocentric-to-geodetic transformation; C. F. F. Karney, GeographicLib Geocentric.

Example

Example using bool tryGeocentricToGeodetic(T)( const GeocentricCoordinate!T source, const Ellipsoid!T ellipsoid, out Geode.

import geodesy;

const xyz = GeocentricCoordinate!double.fromComponents(
    3_771_793.968,
      140_253.342,
    5_124_304.349);

const geo = geocentricToGeodetic(xyz, wgs84!double());
assert(geo.latitude.degrees > 53.0);

GeodeticCoordinate!double checked;
assert(tryGeocentricToGeodetic(xyz, wgs84!double(), checked));