在this question我询问社区如何计算样条基础。我的目标是通过预先计算bspline basis
来计算快于splev
的样条,并生成一条曲线通过做basis
到control point
点积。从a new scipy.interpolate.BSpline
interpolator被添加到scipy
。 It comes with a basis_element
function,我猜可以用它来返回用来计算样条的基础。如何从scipy.interpolate.BSpline提取BSpline基础
因此,例如,使用的代码from here与下面的输入:
import numpy as np
# Control points
cv = np.array([[ 50., 25., 0.],
[ 59., 12., 0.],
[ 50., 10., 0.],
[ 57., 2., 0.],
[ 40., 4., 0.],
[ 40., 14., 0.]])
kv = [0, 0, 0, 0, 1, 2, 3, 3, 3, 3] # knot vector
n = 10 # 10 samples (keeping it simple)
degree = 3 # Curve degree
我可以计算下面的B样条基:
[[ 1. 0. 0. 0. 0. 0. ]
[ 0.2962963 0.56481481 0.13271605 0.00617284 0. 0. ]
[ 0.03703704 0.51851852 0.39506173 0.04938272 0. 0. ]
[ 0. 0.25 0.58333333 0.16666667 0. 0. ]
[ 0. 0.07407407 0.54938272 0.36728395 0.00925926 0. ]
[ 0. 0.00925926 0.36728395 0.54938272 0.07407407 0. ]
[ 0. 0. 0.16666667 0.58333333 0.25 0. ]
[ 0. 0. 0.04938272 0.39506173 0.51851852 0.03703704]
[ 0. 0. 0.00617284 0.13271605 0.56481481 0.2962963 ]
[ 0. 0. 0. 0. 0. 1. ]]
使用np.dot
与basis
和control points
返回10个样品上曲线:
[[ 50. 25. 0. ]
[ 55.12654321 15.52469136 0. ]
[ 55..19753086 0. ]
[ 53.41666667 9.16666667 0. ]
[ 53.14506173 7.15432099 0. ]
[ 53.1882716 5.179. ]
[ 51.58333333 3.83333333 0. ]
[ 47.20987654 3.87654321 0. ]
[ 42.3179.7345679 0. ]
[ 40. 14. 0. ]]
问题:是否可以从scipy.interpolate.BSpline
中提取上述基础?
很显然,我必须使用它错了,因为当我尝试,我得到这样的:
from scipy.interpolate import BSpline
b = BSpline.basis_element(kv)
print b(np.linspace(kv[0],kv[-1],n)) # i'm not sure what these values represent
[ 0. 0.00256299 0.04495618 0.16555213 0.28691315 0.28691315
0.16555213 0.04495618 0.00256299 0. ]
感谢您澄清。我被术语混淆了。 – Fnord