曲线样条(python)

时间:2012-10-09 11:05:47

标签: python interpolation spline

给定2D平面中的一系列点[(x0,y0), (x1,y1), ...],我想找到一个通过这些点的spline curve

1D样条线scipy.interpolate中的类需要增加x,因为这些x - 坐标的列表不一定要增加(即曲线不是函数,{{1而是一个参数化的曲线)。 不幸的是,它都不是f(x)=y的功能(否则通过切换x和y坐标,问题很容易解决)。

我尝试使用单变量插值类,但这没有达到预期的效果。如何使用y计算此样条曲线?

1 个答案:

答案 0 :(得分:4)

您需要重新考虑如何看待这个问题:实际上x是曲线的参数化(通常表示时间为ty是{{} 1}}协调:

x,y

然后您可以使用各种scipy.interpolate函数,例如:

L = [(x0,y0), (x1,y1), ...]
X = numpy.array(L).T
# Equivalently (but less generally):
# X = [[P[0] for P in L], [ P[1] for P in L ]]

t,X = enumerate(L) # here t[0]==0 and X[0]==(x0,x1,..), X[1]==(y0,y1,..)
# or to name in a more confusing manner but match the docs: x,y = enumerate(L)

例如f = scipy.interpolate.interp1d(t, X) (0,0)之间的直线:

(1,1)
相关问题