def discretize_bspline(control, knots, count=None, scale=1.0):
'''
Given a B-Splines control points and knot vector, return
a sampled version of the curve.
Arguments
----------
control: (o,d) list of control points of the b- spline.
knots: (j) list of knots
count: int, number of sections to discretize the spline in to.
If not specified, RES_LENGTH will be used to inform this.
Returns
----------
discrete: (count,d) list of points, a polyline of the B-spline.
'''
# evaluate the b-spline using scipy/fitpack
from scipy.interpolate import splev
# (n, d) control points where d is the dimension of vertices
control = np.array(control)
degree = len(knots) - len(control) - 1
if count is None:
norm = np.linalg.norm(np.diff(control, axis=0), axis=1).sum()
count = int(np.clip(norm / (res.seg_frac*scale),
res.min_sections*len(control),
res.max_sections*len(control)))
ipl = np.linspace(knots[0], knots[-1], count)
discrete = splev(ipl, [knots, control.T, degree])
discrete = np.column_stack(discrete)
return discrete
评论列表
文章目录