【问题标题】:Python: How to resample a 3d curve given by points as spline in equal distances?Python:如何将由点给出的 3d 曲线重新采样为等距离的样条曲线?
【发布时间】:2020-04-06 09:01:52
【问题描述】:

请允许我将其与难度增加的问题分开:


1.

我有一些一维曲线,以(n,) 点数组的形式给出。

我想让它重新采样k 次,并让结果来自通过所有点的三次样条。

这可以通过interp1d来完成


2. 该曲线以非相同间隔的样本作为形状数组(n, 2) 给出,其中(:, 0) 代表样本时间,(:, 1) 代表样本值。

我想以 k 个相同的时间间隔重新采样曲线。

如何做到这一点?

我当时想我可以做t_sampler = interp1d(np.arange(0,k),arr[:, 0]),然后interp1d(t_sampler(np.arange(0,k)), arr[:, 1])

我错过了什么吗?


3.

如何以相等的距离间隔重新采样曲线? (问题 2 是相等的 时间 间隔)


4.

如果曲线是由形状为 (n, 4) 的数组给出的 3d 曲线,其中 (:,0) 是(非均匀)采样时间,其余的是采样位置?


很抱歉,对于单个问题中的许多问题,它们似乎太相似了,无法为每个问题打开一个新问题。

【问题讨论】:

  • 2. 对您有用吗? 3 - 你有没有尝试制作一个 poly 或 interp1d 交换 x 和 y(时间和距离),然后做与 2. 相同的操作?
  • 查看 splprep 的曲线和沿 rhe 曲线的距离
  • @wwii 2. 在interp1d(t_sampler(np.arange(0,k)), arr[:, 1]) 上给我"A value in x_new is below the interpolation " "range.",我不知道为什么
  • 可能相关:ValueError: A value in x_new is above the interpolation range. - ...? ... 没有minimal reproducible example(强调最小,可重现)将很难提供帮助。
  • Sorry for many-questionsin-single-question, - 提出多个问题的一个问题是可能会有一个或多个问题的问答,但不会有一个涵盖所有问题的问答。您应该使用minimal reproducible example 一次询问一个,如果合适的话,部分或全部可能会被标记为重复

标签: python arrays numpy scipy curve-fitting


【解决方案1】:

部分答案;对于 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)

【讨论】:

  • 这解决了1。对于2,我不太确定,因为interp1d希望x和y的长度相同,因此不能直接在xnew上插值采样的y跨度>
  • 我想我在那种情况下误解了 2。您可以分享数据示例吗?
  • 是我不明白。这解决了 1 和 2。
猜你喜欢
  • 1970-01-01
  • 2021-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-06
  • 1970-01-01
  • 1970-01-01
  • 2018-01-05
相关资源
最近更新 更多