简体   繁体   中英

How can I sample a path described by two vectors (V1,V2) using equidistant samples in Numpy?

I am new to NumPy and I have been struggling with the following issue: I have a path that is described by two vectors v1 & v2 and I would like to sample it with equidistant samples using Numpy. Any suggestions how this can be done?

Sample vectors:

phi = np.arange(0, 1*np.pi, 0.1)
a = 1
v1 = a*phi*np.cos(phi)
v2 = a*phi*np.sin(phi)

Thanks!

Seems like this is what you're after:

# import numpy
import numpy as np

# V1 and V2 vectors
phi = np.arange(0, 1*np.pi, 0.1)
a = 1
v1 = a*phi*np.cos(phi)
v2 = a*phi*np.sin(phi)


# segmenting the lengths
dr = (np.diff(v1)**2 + np.diff(v2)**2)**.5
r = np.zeros_like(v1)

# integrating the path
r[1:] = np.cumsum(dr)

# regular spaced path
r_int = np.linspace(0, r.max(), 200)

# integrating the path
v1_int = np.interp(r_int, r, v1)
v2_int = np.interp(r_int, r, v2)

Cheers!

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