Function tryGeodeticToGeocentric

Convert latitude, longitude and ellipsoidal height to Earth-centred XYZ.

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

Use this checked operation when you want to handle conversion failure without an exception. On success, result holds X, Y and Z in the same linear unit as the input height and ellipsoid axes.

Implements the forward direction of EPSG coordinate operation method 9602 (Geographic/geocentric conversions). Longitude is interpreted relative to the prime meridian defining the geocentric X axis; conventional EPSG geocentric systems use Greenwich.

Ellipsoidal height and ellipsoid axes must use the same linear unit. The returned X/Y/Z components use that unit. No datum transformation is performed.

Parameters

NameDescription
source Finite geodetic latitude, longitude, and ellipsoidal height.
ellipsoid Valid spherical or oblate reference ellipsoid in the same linear unit as source.ellipsoidalHeight.
result Receives the geocentric coordinate on success.

Returns

true when a finite representable Cartesian result is produced; false for an invalid ellipsoid or when finite inputs overflow or otherwise produce a non-finite result in scalar type T.

No allocation is performed.

Example

Example converting a geographic position to Earth-centred XYZ without exceptions.

import geodesy;

const source = GeodeticCoordinate!double.fromComponents(
    Latitude!double.fromDegrees(53.0),
    Longitude!double.fromDegrees(2.0),
    73.0);

const xyz = geodeticToGeocentric(source, wgs84!double());
assert(xyz.x > 0.0);

GeocentricCoordinate!double checked;
assert(tryGeodeticToGeocentric(source, wgs84!double(), checked));