所以,在我的问题困扰了很多,做了很多研究之后,我终于有了答案。scipy中的所有东西都是可用的,我把我的代码放在这里,希望其他人能发现它有用。在
该函数接受一个N-d点数组、一个曲线阶数、一个周期状态(打开或关闭),并将沿着该曲线返回N个样本。有一些方法可以确保曲线样本是等距的,但目前我将集中讨论这个问题,因为它都是关于速度的。在
值得注意的是:我似乎无法超越20度的曲线。当然,这已经是过火了,但我觉得值得一提。在
同样值得注意的是:在我的机器上,下面的代码可以在0.017s内计算出100000个样本import numpy as np
import scipy.interpolate as si
def bspline(cv, n=100, degree=3, periodic=False):
""" Calculate n samples on a bspline
cv : Array ov control vertices
n : Number of samples to return
degree: Curve degree
periodic: True - Curve is closed
False - Curve is open
"""
# If periodic, extend the point array by count+degree+1
cv = np.asarray(cv)
count = len(cv)
if periodic:
factor, fraction = divmod(c