calculateRhumbDestination function

Position calculateRhumbDestination(
  1. Position origin,
  2. num distance,
  3. num bearing, [
  4. num radius = earthRadius,
])

Implementation

Position calculateRhumbDestination(Position origin, num distance, num bearing,
    [num radius = earthRadius]) {
  final R = radius > 0 ? radius : earthRadius;
  final delta = distance / R;
  final lambda1 = (origin.lng * math.pi) / 180;
  final phi1 = degreesToRadians(origin.lat);
  final theta = degreesToRadians(bearing);

  final dPhi = delta * math.cos(theta);
  var phi2 = phi1 + dPhi;

  // check for some daft bugger going past the pole, normalize latitude if so
  if (phi2.abs() > math.pi / 2) {
    phi2 = phi2 > 0 ? math.pi - phi2 : -math.pi - phi2;
  }

  final dPsi = math
      .log(math.tan(phi2 / 2 + math.pi / 4) / math.tan(phi1 / 2 + math.pi / 4));
  // E-W course becomes ill-conditioned with 0/0
  final q = dPsi.abs() > 10e-12 ? dPhi / dPsi : math.cos(phi1);

  final dLambda = (delta * math.sin(theta)) / q;
  final lambda2 = lambda1 + dLambda;

  // normalize to −180..+180°
  final lng = (((lambda2 * 180) / math.pi + 540) % 360) - 180;
  final lat = (phi2 * 180) / math.pi;

  return Position(lng, lat);
}