interpolatePath method

List<LatLng> interpolatePath(
  1. LatLng start,
  2. LatLng end,
  3. int numPoints
)

Implementation

List<LatLng> interpolatePath(LatLng start, LatLng end, int numPoints) {
  List<LatLng> points = [];

  // Calculate midpoints for curvature
  double midLat = (start.latitude + end.latitude) / 2;
  double midLng = (start.longitude + end.longitude) / 2;

  // Calculate distance for maximum arc height
  double latDistance = (end.latitude - start.latitude).abs();
  double lngDistance = (end.longitude - start.longitude).abs();
  double maxArcHeight = (latDistance + lngDistance) * 0.07;

  for (int i = 0; i <= numPoints; i++) {
    double fraction = i / numPoints;

    // Linear interpolation for base lat/lng
    double lat = start.latitude + (end.latitude - start.latitude) * fraction;
    double lng = start.longitude + (end.longitude - start.longitude) * fraction;

    // Calculate parabolic height adjustment
    double heightFactor = -4 * (fraction - 0.5) * (fraction - 0.5) + 1;
    double verticalOffset = maxArcHeight * heightFactor;

    // Apply arc offset to latitude (vertical curvature)
    lat += verticalOffset;

    points.add(LatLng(lat, lng));
  }

  return points;
}