computeHeading static method

num 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 num computeHeading(Point from, Point to) {
  // http://williams.best.vwh.net/avform.htm#Crs

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