computeHeading static method

double computeHeading(
  1. Point<num> from,
  2. Point<num> to
)

Returns the heading from one Point to another Point. Headings are expressed in degrees clockwise from North within the range [-180,180).

return The heading in degrees clockwise from north.

Implementation

static double computeHeading(Point from, Point to) {
  // http://williams.best.vwh.net/avform.htm#Crs

  double fromLat = toRadians(from.x);
  double fromLng = toRadians(from.y);
  double toLat = toRadians(to.x);
  double toLng = toRadians(to.y);
  double dLng = toLng - fromLng;
  double heading = atan2(sin(dLng) * cos(toLat),
      cos(fromLat) * sin(toLat) - sin(fromLat) * cos(toLat) * cos(dLng));
  return MathUtils.wrap(toDegrees(heading), -180, 180);
}