Created
May 29, 2022 23:18
-
-
Save dirediredock/d9b5b66821171b8c591da5eb619bcd84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# by Matias I. Bofarull Oddo - 2022.05.29 | |
from random import randint | |
import matplotlib.pyplot as plt | |
points = [[randint(0, 999) for _ in range(2)] for _ in range(4)] | |
def linear_interpolation(array, line_ratio): | |
new_X = ((1 - line_ratio) * array[0][0]) + (line_ratio * array[1][0]) | |
new_Y = ((1 - line_ratio) * array[0][1]) + (line_ratio * array[1][1]) | |
return [new_X, new_Y] | |
fig = plt.figure(figsize=(9, 9)) | |
ax = fig.add_subplot(111) | |
X = [coord_pair[0] for coord_pair in points] | |
Y = [coord_pair[1] for coord_pair in points] | |
ax.plot(X, Y, zorder=0) | |
ax.scatter(X, Y, s=100) | |
curve_points = 99 | |
for i in range(curve_points): | |
ratio = (i + 0.5) / curve_points | |
midpoint_A = linear_interpolation(points[0:2], ratio) | |
midpoint_B = linear_interpolation(points[1:3], ratio) | |
midpoint_C = linear_interpolation(points[2:4], ratio) | |
points_AB = [midpoint_A, midpoint_B] | |
points_BC = [midpoint_B, midpoint_C] | |
midpoint_AB = linear_interpolation(points_AB, ratio) | |
midpoint_BC = linear_interpolation(points_BC, ratio) | |
points_final = [midpoint_AB, midpoint_BC] | |
point = linear_interpolation(points_final, ratio) | |
ax.scatter(point[0], point[1], s=600, c="none", edgecolor="k") | |
plt.show() |
Author
dirediredock
commented
May 29, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment