Function nearestPointOnSegment

Find the nearest point on a bounded oriented ellipsoidal geodesic segment.

GeodesicSegmentNearestResult!T nearestPointOnSegment(T)(
  const Geodesic!T solver,
  const GeographicCoordinate!T start,
  const GeographicCoordinate!T end,
  const GeographicCoordinate!T target
) @safe
if (isGeodesyScalar!T);

This is the throwing counterpart of tryNearestPointOnSegment.

Throws

GeodesyValueException when the solver/segment is invalid or the local ellipsoidal interception does not produce a finite converged result.

Example

Example finding the nearest bounded-segment point with throwing semantics.

const solver =
    Geodesic!double.fromEllipsoid(
        Ellipsoid!double.fromInverseFlattening(
            6_378_137.0,
            298.257223563));

const a =
    GeographicCoordinate!double.fromComponents(
        Latitude!double.fromDegrees(48.0),
        Longitude!double.fromDegrees(10.0));

const b =
    GeographicCoordinate!double.fromComponents(
        Latitude!double.fromDegrees(48.0),
        Longitude!double.fromDegrees(12.0));

const target =
    GeographicCoordinate!double.fromComponents(
        Latitude!double.fromDegrees(48.4),
        Longitude!double.fromDegrees(8.0));

const result =
    nearestPointOnSegment(
        solver,
        a,
        b,
        target);

assert(result.kind == GeodesicSegmentNearestKind.start);