輪郭に沿ってポイントをマークする x、y 座標のセットがあるとします。その長さに沿った特定の位置で評価し、補間された x、y 座標を復元できる輪郭のスプライン表現を作成する方法はありますか?
X 値と Y 値が 1:1 で対応することはあまりないため、一変量スプラインは私には適していません。二変量スプラインは問題ありませんが、二変量スプラインを評価するためのすべての関数を伝えることができる限り、scipy.interpolate
x、y 値を取得して 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)