def points_to_spline_entity(points, smooth=.0005, count=None):
from scipy.interpolate import splprep
if count is None:
count = len(points)
points = np.asanyarray(points)
closed = np.linalg.norm(points[0] - points[-1]) < tol.merge
knots, control, degree = splprep(points.T, s=smooth)[0]
control = np.transpose(control)
index = np.arange(len(control))
if closed:
control[0] = control[[0,-1]].mean(axis=0)
control = control[:-1]
index[-1] = index[0]
entity = BSpline(points = index,
knots = knots,
closed = closed)
return entity, control
评论列表
文章目录