startBearing static method

double startBearing(
  1. ILatLong p1,
  2. ILatLong p2
)

calculates the startbearing in degrees of the distance from p1 to p2 see https://www.movable-type.co.uk/scripts/latlong.html

Implementation

static double startBearing(final ILatLong p1, final ILatLong p2) {
  double longDiff = degToRadian(p2.longitude) - degToRadian(p1.longitude);
  double cosP2Lat = cos(degToRadian(p2.latitude));
  double y = sin(longDiff) * cosP2Lat;
  double x = cos(degToRadian(p1.latitude)) * sin(degToRadian(p2.latitude)) - sin(degToRadian(p1.latitude)) * cosP2Lat * cos(longDiff);
  double c = atan2(y, x);
  double result = (c * 180 / pi + 360) % 360;
  return result;
}