[英]Python: How to resample a 3d curve given by points as spline in equal distances?
Allow me to separate this to increasing difficulty questions:请允许我将其与难度增加的问题分开:
1. 1.
I have some 1d curve, given as a (n,)
point array.我有一些 1d 曲线,作为(n,)
点数组给出。
I would like to have it re-sampled k
times, and have the results come from a cubic spline that passes through all points.我想让它重新采样k
次,并且结果来自通过所有点的三次样条。
This can be done with interp1d这可以用interp1d来完成
2. The curve is given at non-same-interval samples as an array of shape (n, 2)
where (:, 0)
represents the sample time, and (:, 1)
represent the sample values. 2.曲线在非相同间隔样本处以形状为(n, 2)
的数组给出(n, 2)
其中(:, 0)
表示采样时间, (:, 1)
表示样本值。
I want to re-sample the curve at k same-time-intervals.我想在 k 个相同时间间隔重新采样曲线。
How can this be done?如何才能做到这一点?
I thought i could do t_sampler = interp1d(np.arange(0,k),arr[:, 0])
for the time, then interp1d(t_sampler(np.arange(0,k)), arr[:, 1])
我以为我可以暂时执行t_sampler = interp1d(np.arange(0,k),arr[:, 0])
,然后执行interp1d(t_sampler(np.arange(0,k)), arr[:, 1])
Am I missing something with this?我错过了什么吗?
3. 3.
How can I re-sample the curve at equal distance intervals?如何以相等的距离间隔重新采样曲线? (question 2 was equal time intervals) (问题 2 是相等的时间间隔)
4. 4.
What if the curve is 3d given by an array of shape (n, 4)
, where (:,0)
are the (non uniform) sampling times, and the rest are the locations sampled?如果曲线是由形状(n, 4)
数组给出的 3d 曲线,其中(:,0)
是(非均匀)采样时间,其余是采样的位置,该怎么办?
Sorry for many-questionsin-single-question, they seemed too similar to open a new question for every one.很抱歉,单问题中的多问题,它们似乎太相似了,无法为每个问题打开一个新问题。
Partial answer;部分回答; for 1 and 2 I would do this:对于 1 和 2,我会这样做:
from scipy.interpolate import interp1d
import numpy as np
# dummy data
x = np.arange(-100,100,10)
y = x**2 + np.random.normal(0,1, len(x))
# interpolate:
f = interp1d(x,y, kind='cubic')
# resample at k intervals, with k = 100:
k = 100
# generate x axis:
xnew = np.linspace(np.min(x), np.max(x), k)
# call f on xnew to sample y values:
ynew = f(xnew)
plt.scatter(x,y)
plt.plot(xnew, ynew)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.