私は空間曲線に合うように3次元座標(x,y,z)
を持っています。誰かがこれのための既存のルーチンをPythonで知っていますか?3次元空間での1次元曲線の補間/適合の取得 -
私が見つけたことから(https://docs.scipy.org/doc/scipy/reference/interpolate.html)、カーブを2次元座標にフィッティングするための既存のモジュールと、サーフェスを3次元座標のセットにフィッティングするための既存のモジュールがあります。私は真ん中の道を望んでいます - 曲線を3次元座標のセットにフィットさせます。
EDIT -
私はinterpolate.splprep()
とinterpolate.splenv()
を使用して、ここでは別のポストにこれを明示的に答えを見つけました。ここに私のデータポイントである:
21.735556483642707 7.9999120559310359 -0.7043281314370935
21.009401429607784 8.0101161320825103 -0.16388503829177037
20.199370045383134 8.0361339131845497 0.25664085801558179
19.318149385194054 8.0540100864979447 0.50434139043379278
18.405497793567243 8.0621753888918484 0.57169888018720161
17.952649703401562 8.8413995204241491 0.39316793526155014
17.539007529982641 9.6245700151356104 0.14326173861202204
17.100154581079089 10.416295524018977 0.011339000091976647
16.645143439968102 11.208477191735446 0.070252116425261066
16.198247656768263 11.967005154933993 0.31087815045809558
16.661378578010989 12.717314230004659 0.54140549139204996
17.126106263351478 13.503461982612732 0.57743407626794219
17.564249250974573 14.28890107482801 0.42307198199366186
17.968265052275274 15.031985807202176 0.10156997950061938
は私のコードは次のとおりです。
from scipy import interpolate
from mpl_toolkits.mplot3d import Axes3D
data = data.transpose()
#now we get all the knots and info about the interpolated spline
tck, u= interpolate.splprep(data, k=5)
#here we generate the new interpolated dataset,
#increase the resolution by increasing the spacing, 500 in this example
new = interpolate.splev(np.linspace(0,1,500), tck, der=0)
#now lets plot it!
fig = plt.figure()
ax = Axes3D(fig)
ax.plot(data[0], data[1], data[2], label='originalpoints', lw =2, c='Dodgerblue')
ax.plot(new[0], new[1], new[2], label='fit', lw =2, c='red')
ax.legend()
plt.savefig('junk.png')
plt.show()
これはイメージです:
あなたはフィット感が良くないことがわかります、しばらく私はすでに許容されているフィッティングオーダー値(k=5
)を使用しています。これは曲線が完全に凸ではないためですか?どのように私はフィット感を向上させることができるか知っていますか?
質問を更新しました。上記をご覧ください。 – ap21