Struct Ellipsoid

A rotational reference ellipsoid stored canonically as equatorial semi-axis a and flattening f.

struct Ellipsoid(T)
  
if (isGeodesyScalar!T);

The semi-major axis defines the caller-selected linear unit. Operations combining an ellipsoid with heights or Cartesian coordinates require those values to use the same linear unit. Ellipsoid.init is intentionally invalid so accidental default construction cannot silently select a plausible Earth model.

General construction accepts finite a > 0 and -1 < f < 1. fromInverseFlattening accepts finite values less than -1 for prolate models and finite values greater than 1 for oblate models; construct spheres explicitly with sphere.

Checked factories return false for invalid parameters. Their throwing peers throw GeodesyValueException. Derived properties do not allocate.

Properties

NameTypeDescription
equatorialRadius[get] TEquatorial radius alias for the canonical semi-axis a.
firstEccentricitySquared[get] TSigned first eccentricity squared e² = f(2-f); negative for prolate ellipsoids.
flattening[get] TFlattening f.
inverseFlattening[get] TDerived inverse flattening 1/f; infinity for a sphere.
isValid[get] boolTrue when this value represents a finite rotational ellipsoid. Negative flattening denotes a prolate ellipsoid.
polarRadius[get] TPolar radius alias for the derived semi-axis b = a(1-f).
secondEccentricitySquared[get] TSigned second eccentricity squared (e′²); negative for prolate ellipsoids.
semiMajorAxis[get] TCanonical equatorial semi-axis a in the ellipsoid linear unit.
semiMinorAxis[get] TDerived polar semi-axis b = a(1-f).
thirdFlattening[get] TSigned third flattening n = f/(2-f).

Methods

NameDescription
fromAxes (semiMajorAxis, semiMinorAxis) Construct from canonical equatorial axis a and polar axis b or throw on invalid parameters.
fromFlattening (semiMajorAxis, flattening) Construct from semi-major axis and flattening or throw on invalid parameters.
fromInverseFlattening (semiMajorAxis, inverseFlattening) Construct from semi-major axis and inverse flattening or throw on invalid parameters.
sphere (radius) Construct a sphere or throw when the radius is invalid.
tryFromAxes (semiMajorAxis, semiMinorAxis, result) Construct from canonical equatorial axis a and polar axis b without throwing.
tryFromFlattening (semiMajorAxis, flattening, result) Construct from semi-major axis and flattening without throwing.
tryFromInverseFlattening (semiMajorAxis, inverseFlattening, result) Construct from semi-major axis and inverse flattening without throwing.
trySphere (radius, result) Construct a sphere without throwing; radius must be finite and positive.

Example

Prolate rotational ellipsoids are representable independently of geodesic admission.

import geodesy;

const prolate = Ellipsoid!double.fromFlattening(
    6_378_137.0,
    -0.01);

assert(prolate.isValid);
assert(prolate.flattening < 0.0);
assert(prolate.polarRadius > prolate.equatorialRadius);
assert(prolate.semiMinorAxis > prolate.semiMajorAxis);
assert(prolate.firstEccentricitySquared < 0.0);
assert(prolate.secondEccentricitySquared < 0.0);
assert(prolate.thirdFlattening < 0.0);

const fromInverse = Ellipsoid!double.fromInverseFlattening(
    6_378_137.0,
    -100.0);

assert(fromInverse.flattening == -0.01);

const fromAxes = Ellipsoid!double.fromAxes(
    6_378_137.0,
    6_441_918.37);

assert(fromAxes.flattening < 0.0);

Example

Example constructing Earth and spherical ellipsoids.

import geodesy;

const earth = wgs84!double();
assert(earth.isValid);
assert(earth.semiMajorAxis == 6_378_137.0);

const sphere = Ellipsoid!double.sphere(6_371_000.0);
assert(sphere.flattening == 0.0);
assert(sphere.semiMinorAxis == sphere.semiMajorAxis);

assert(!Ellipsoid!double.init.isValid);