computeOffset static method

Point<double> computeOffset(
  1. Point<double> from,
  2. double distance,
  3. double heading
)

Returns the Point resulting from moving a distance from an origin in the specified heading (expressed in degrees clockwise from north).

from The Point from which to start.

distance The distance to travel.

heading The heading in degrees clockwise from north.

Implementation

static Point<double> computeOffset(
    Point<double> from, double distance, double heading) {
  distance /= MathUtils.earthRadius;
  heading = toRadians(heading);
  // http://williams.best.vwh.net/avform.htm#LL
  final fromLat = toRadians(from.x);
  final fromLng = toRadians(from.y);
  final cosDistance = cos(distance);
  final sinDistance = sin(distance);
  final sinFromLat = sin(fromLat);
  final cosFromLat = cos(fromLat);
  final sinLat =
      cosDistance * sinFromLat + sinDistance * cosFromLat * cos(heading);
  final dLng = atan2(sinDistance * cosFromLat * sin(heading),
      cosDistance - sinFromLat * sinLat);
  return Point(toDegrees(asin(sinLat)), toDegrees(fromLng + dLng));
}