calculateRhumbBearing function

num calculateRhumbBearing(
  1. Position from,
  2. Position to
)

Returns the bearing from ‘this’ Point to destination Point along a rhumb line. Adapted from Geodesy: https://github.com/chrisveness/geodesy/blob/master/latlon-spherical.js Returns Bearing in degrees from north. example

var p1 = Position.named(lng: 51.127, lat: 1.338);
var p2 = Position.named(lng: 50.964, lat: 1.853);
var d = p1.rhumbBearingTo(p2); // 116.7 m

Implementation

num calculateRhumbBearing(Position from, Position to) {
  // φ => phi
  // Δλ => deltaLambda
  // Δψ => deltaPsi
  // θ => theta
  num phi1 = degreesToRadians(from.lat);
  num phi2 = degreesToRadians(to.lat);
  num deltaLambda = degreesToRadians(to.lng - from.lng);
  // if deltaLambda over 180° take shorter rhumb line across the anti-meridian:
  if (deltaLambda > math.pi) {
    deltaLambda -= 2 * math.pi;
  }
  if (deltaLambda < -math.pi) {
    deltaLambda += 2 * math.pi;
  }

  double deltaPsi = math
      .log(math.tan(phi2 / 2 + math.pi / 4) / math.tan(phi1 / 2 + math.pi / 4));

  double theta = math.atan2(deltaLambda, deltaPsi);

  return (radiansToDegrees(theta) + 360) % 360;
}