Предположим, что у меня есть набор координат x, y, которые отмечают точки вдоль контура. Есть ли способ, которым я могу построить сплайн-представление контура, которое я могу оценить в определенном положении по его длине, и восстановить интерполированные координаты x, y?
Часто бывает не так, что существует соответствие 1:1 между значениями X и Y, поэтому одномерные сплайны мне не подходят. Двумерные сплайны были бы точными, но насколько я могу рассказать обо всех функциях для оценки двумерных сплайнов в scipy.interpolate
, возьмем значения x, y и return z, тогда как мне нужно дать z и вернуть x, y (поскольку x, y - точки на линии, причем каждый z сопоставляется с единственным x, y).
Вот эскиз того, что я хотел бы сделать:
import numpy as np
from matplotlib.pyplot import plot
# x,y coordinates of contour points, not monotonically increasing
x = np.array([ 2., 1., 1., 2., 2., 4., 4., 3.])
y = np.array([ 1., 2., 3., 4., 2., 3., 2., 1.])
# f: X --> Y might not be a 1:1 correspondence
plot(x,y,'-o')
# get the cumulative distance along the contour
dist = [0]
for ii in xrange(x.size-1):
dist.append(np.sqrt((x[ii+1]-x[ii])**2 + (y[ii+1]-y[ii])**2))
d = np.array(dist)
# build a spline representation of the contour
spl = ContourSpline(x,y,d)
# resample it at smaller distance intervals
interp_d = np.linspace(d[0],d[-1],1000)
interp_x,interp_y = spl(interp_d)