def test_linspace(): start = 5 stop = 11 num = 4 result = [5.0, 7.0, 9.0, 11.0] to_check = utilities.linspace(start, stop, num) assert to_check == result
def get_basis(b_spline_cpts): degree=4 # spans = helpers.find_spans(degree, knot_vector, 6, knots, helpers.find_span_linear) x = b_spline_cpts[0::2] y = b_spline_cpts[1::2] b_spline_cpts = mvpuai.reshape_coords_to_tuples(b_spline_cpts) a = len(b_spline_cpts) knot_vector = utilities.generate_knot_vector(degree, len(b_spline_cpts)) start = knot_vector[degree] stop = knot_vector[-(degree + 1)] knots = utilities.linspace(start, stop, 101, decimals=6) spans = helpers.find_spans(degree, knot_vector, len(b_spline_cpts), knots, helpers.find_span_linear) basis = helpers.basis_functions(degree, knot_vector, spans, knots) eval_points = [] for idx in range(len(knots)): crvpt = [0.0 for _ in range(4)] for i in range(0, degree + 1): crvpt[:] = [crv_p + (basis[idx][i] * ctl_p) for crv_p, ctl_p in zip(crvpt, b_spline_cpts[spans[idx] - degree + i])] eval_points.append(crvpt) return eval_points#
def get_b_spline(ctrl_pts): ######### ctrl_pts = mvpuai.reshape_coords_to_tuples(ctrl_pts) def get_degree_of_b_spline(num_of_ctrl_pts: int): if num_of_ctrl_pts >= 5: degree = 4 elif num_of_ctrl_pts >= 1: degree = num_of_ctrl_pts - 1 else: degree = 0 return degree degree = get_degree_of_b_spline(len(ctrl_pts)) knot_vector = utilities.generate_knot_vector(degree, len(ctrl_pts)) start = knot_vector[degree] stop = knot_vector[-(degree + 1)] return utilities.linspace(start, stop, 101, decimals=6)