I have the following piece of code. It generates the 3-D cubic spline of the given 3-D function given in parametric form. I pretty much adapted this to my case using the online documentation for splprep and splev.
But I have some things I don't understand. Here is the code:
%matplotlib inline
from numpy import arange, cos, linspace, pi, sin, random
from scipy.interpolate import splprep, splev
import matplotlib.pyplot as plt
# make ascending spiral in 3-space
t=linspace(0,1.75*2*pi,100)
x = sin(t)
y = cos(t)
z = t
# spline parameters
s=3.0 # smoothness parameter
k=3 # spline order
nest=-1 # estimate of number of knots needed (-1 = maximal)
# find the knot points
tck,u = splprep([x,y,z],s=s,k=k,nest=-1)
# evaluate spline, including interpolated points
xnew,ynew,znew = splev(linspace(0,1,400),tck)
I have a few questions regarding this implementation.
What exactly does the
(t,c,k)
tuple return in this case?. I read the documentation and it says it returns the knot points, the coefficients and the degree of the spline. Doesn't knot points have to be coordinates of the form (x, y, z)?. So we have to have"number of knots"
such coordinate points. But that's not what gets returned. We simply get returned an array oflength 11
.What does
u
return? (Documentation says it returns the values of the parameter. What does that mean?. The values of the parametert
?When I use nest = -1 (This is the default) it uses the maximal number of knot points needed (in this case they use
11
knot points). But how do I specify my own number of knot points, let's say 50 or 80 etc?
I am completely misunderstanding the documentation here. Can someone enlighten me may be using examples?
c
values are not the power coefficients of the overall curve. They are the control points. That is why "The 3D nature of the curve is expressed by coefficientsc
. " sentence might lead to miss-understanding of the concept. In order to get power coefficients of the curve i.e., ax^2 + bx + c ( or maybe cubic coeff.), you need to use these control points and apply some linear regression or interpolation. – Laquitalar