Created
April 30, 2021 15:24
-
-
Save silgon/6f029742c054a18ef2829dce4291853d to your computer and use it in GitHub Desktop.
This file contains 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
import numpy as np | |
import matplotlib.pyplot as plt | |
n_dimensions = 2 | |
A = np.random.rand(n_dimensions) # source | |
B = np.random.rand(n_dimensions) # target | |
# linear function | |
n_steps = 50 | |
delta = (A-B)/n_steps | |
delta_array = np.ones((n_dimensions, n_steps))*delta[:,np.newaxis] | |
trajectory = A[:,np.newaxis]+delta_array.cumsum(1) | |
# plt.scatter(trajectory[0], trajectory[1], alpha=np.linspace(0.3,1, n_steps)) | |
# plt.show() | |
import scipy.interpolate as si | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def bspline(cv, n=100, degree=3): | |
cv = np.asarray(cv) | |
count = cv.shape[0] | |
degree = np.clip(degree, 1, count-1) | |
kv = np.array([0]*degree + list(range(count-degree+1)) | |
+ [count-degree]*degree, dtype='int') | |
u = np.linspace(0, (count-degree), n) | |
return np.array(si.splev(u, (kv, cv.T, degree))).T | |
cv = np.array([[50., 25.], # A point | |
[57., 2.], # intermediate point | |
[40., 4.], # intermediate point | |
[40., 14.]]) # B Point | |
p = bspline(cv, n=n_steps, degree=3) | |
plt.scatter(p[:, 0], p[:, 1], alpha=np.linspace(0.3, 1, n_steps)) | |
plt.show() |
Author
silgon
commented
Apr 30, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment