Open rougier opened 9 years ago
This is a piece of code by Bas Swinckels posted on stack overflow that allow to sample a path at regular interval.
import matplotlib.pyplot as plt import numpy as np a = 1 phi = np.arange(0, 10*np.pi, 0.1) x = a*phi*np.cos(phi) y = a*phi*np.sin(phi) dr = (np.diff(x)**2 + np.diff(y)**2)**.5 # segment lengths r = np.zeros_like(x) r[1:] = np.cumsum(dr) # integrate path r_int = np.linspace(0, r.max(), 200) # regular spaced path x_int = np.interp(r_int, r, x) # interpolate y_int = np.interp(r_int, r, y) plt.subplot(1,2,1) plt.plot(x, y, 'o-') plt.title('Original') plt.axis([-32,32,-32,32]) plt.subplot(1,2,2) plt.plot(x_int, y_int, 'o-') plt.title('Interpolated') plt.axis([-32,32,-32,32]) plt.show()
Neat, thanks!
This is a piece of code by Bas Swinckels posted on stack overflow that allow to sample a path at regular interval.