简体   繁体   中英

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.

I have some 1d curve, given as a (n,) point array.

I would like to have it re-sampled k times, and have the results come from a cubic spline that passes through all points.

This can be done with 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.

I want to re-sample the curve at k same-time-intervals.

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])

Am I missing something with this?


3.

How can I re-sample the curve at equal distance intervals? (question 2 was equal time intervals)


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?


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:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM