Background
- I want to generate a unit-length cubic spline (arc length of 1), with way- or control-points as the input.
- I then want to generate another unit-length cubic spline in the same way, having it smoothly connect from the previous spline.
I want to do this iteratively (over and over again) and using SciPy or another easy-to-use library in Python.
What I've tried
To demonstrate, let's consider that I initially have 10 waypoints, i.e.:
y0 = np.array([
[-18., -20.],
[-18., 18.],
[-14., 18.],
[-14., -18.],
[-10., -18.],
[-10., 18.],
[ -6., 18.],
[ -6., -18.],
[ -2., -18.],
[ -2., 18.]
])
plt.plot(y0[:,0], y0[:,1], 'bx')
It's pretty straightforward to generate a unit-length spline using scipy.interpolate.CubicSpline
like so:
x0 = np.linspace(0, 1, y0.shape[0])
f0 = CubicSpline(x0, y0, bc_type='natural')
Now, let's suppose I receive 10 new waypoints. In an attempt to continue the spline, I repeat the previous procedure, including the last waypoint and incrementing the independent variable interval:
y1 = np.array([
[ -2., 18.],
[ 2., 18.],
[ 2., -18.],
[ 6., -18.],
[ 6., 18.],
[ 10., 18.],
[ 10., -18.],
[ 14., -18.],
[ 14., 18.],
[ 18., 18.],
[ 18., -20.]
])
plt.plot(y1[:,0], y1[:,1], 'gx')
x1 = np.linspace(1, 2, y1.shape[0])
f1 = CubicSpline(x1, y1, bc_type='natural')
Now, if we plot these interpolants, there will obviously be a lack of smoothness between the last waypoint of the first interpolant.
plt.plot(y0[:,0], y0[:,1], 'b-')
plt.plot(y1[:,0], y1[:,1], 'g-')
plt.show()
Going forward
- Is there a way to constrain the curvature at the beginning of the second spline?
- I suppose generating the splines with the control points as the inputs would give a straightforward way to enforce smoothness between splines.
- Is there a straightforward way to implement arc-length reparameterisation?