rhumbLineDistance method

Length rhumbLineDistance(
  1. LatLng point
)

Calculates the rhumb line distance to another point.

Rhumb lines are straight lines on a Mercator projection map, making this method useful for navigation purposes.

point: The other point to which the rhumb line distance is calculated. Returns the distance as a Length object.

Implementation

Length rhumbLineDistance(LatLng point) {
  double phi1 = latitude.radians;
  double phi2 = point.latitude.radians;
  double deltaPhi = phi2 - phi1;
  double lambda1 = longitude.radians;
  double lambda2 = point.longitude.radians;
  double deltaLambda = lambda2 - lambda1;

  double deltaPsi = log(tan(pi / 4 + phi2 / 2) / tan(pi / 4 + phi1 / 2));
  double q = (deltaPsi.abs() > 1e-12) ? deltaPhi / deltaPsi : cos(phi1);

  double d =
      sqrt(deltaPhi * deltaPhi + q * q * deltaLambda * deltaLambda) * R;
  return Length(m: d);
}