interpolate static method
Returns the Point which lies the given fraction of the way between the origin Point and the destination Point.
from The Point from which to start.
to The Point toward which to travel.
fraction A fraction of the distance to travel.
Returns The interpolated Point.
Implementation
static Point<double> interpolate(
Point<double> from, Point<double> to, double fraction) {
// http://en.wikipedia.org/wiki/Slerp
final fromLat = toRadians(from.x);
final fromLng = toRadians(from.y);
final toLat = toRadians(to.x);
final toLng = toRadians(to.y);
final cosFromLat = cos(fromLat);
final cosToLat = cos(toLat);
// Computes Spherical interpolation coefficients.
final angle = computeAngleBetween(from, to);
final sinAngle = sin(angle);
if (sinAngle < 1E-6) {
return Point(from.x + fraction * (to.x - from.x),
from.y + fraction * (to.y - from.y));
}
final a = sin((1 - fraction) * angle) / sinAngle;
final b = sin(fraction * angle) / sinAngle;
// Converts from polar to vector and interpolate.
final x = a * cosFromLat * cos(fromLng) + b * cosToLat * cos(toLng);
final y = a * cosFromLat * sin(fromLng) + b * cosToLat * sin(toLng);
final z = a * sin(fromLat) + b * sin(toLat);
// Converts interpolated vector back to polar.
final lat = atan2(z, sqrt(x * x + y * y));
final lng = atan2(y, x);
return Point(toDegrees(lat), toDegrees(lng));
}