Skip to content

Instantly share code, notes, and snippets.

@M-Haris72
Created February 15, 2025 07:45
Show Gist options
  • Save M-Haris72/b5e85008d940374817542f3b5a9b24ba to your computer and use it in GitHub Desktop.
Save M-Haris72/b5e85008d940374817542f3b5a9b24ba to your computer and use it in GitHub Desktop.
This function returns interpolated points between two given points based on the specified number of interpolations. It can be used when interpolation of points within a given range is required.
def interpolate_points(list_of_points, num_of_time_interpolations):
interpolated_points = []
for i in range(len(points) - 1):
x1, y1 = points[i]
x2, y2 = points[i + 1]
interpolated_points.append((x1, y1))
for j in range(1, num_interpolations + 1):
t = j / (num_interpolations + 1)
x_new = x1 + (x2 - x1) * t
y_new = y1 + (y2 - y1) * t
interpolated_points.append((x_new, y_new))
interpolated_points.append(points[-1])
return interpolated_points
@M-Haris72
Copy link
Author

Implemented interpolate_points function to compute interpolated points between consecutive points in a list.
The function takes a list of points and a specified number of interpolations.
It inserts evenly spaced points between each pair of consecutive points.
This is useful for smooth transitions and detailed interpolation in datasets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment