def test_control_points_1(self): #index = np.array([0,1,2]) points = self.spline.get_control_points() self.assertEquals(points.shape, (3, 4, 3)) #print(points) for i in range(3): with self.subTest(segmentNum=i): p0 = points[i][0] p3 = points[i][3] expected_p0 = self.control_points[i] expected_p3 = self.control_points[i + 1] self.assert_numpy_arrays_equal(p0, expected_p0, precision=8) self.assert_numpy_arrays_equal(p3, expected_p3, precision=8) bezier = SvBezierCurve([points[i][k] for k in range(4)]) t_min_spline = self.spline.tknots[i] t_max_spline = self.spline.tknots[i + 1] #print(f"Spline #{i}: {t_min_spline}, {t_max_spline}") t_spline = np.linspace(t_min_spline, t_max_spline, num=10) t_bezier = np.linspace(0, 1, num=10) pts_spline = self.spline.eval(t_spline) pts_bezier = bezier.evaluate_array(t_bezier) self.assert_numpy_arrays_equal(pts_bezier, pts_spline, precision=6)
def to_bezier(self): points = self.get_control_points() if not self.is_bezier(): n = len(points) p = self.get_degree() raise UnsupportedCurveTypeException( f"Curve with {n} control points and {p}'th degree can not be converted into Bezier curve" ) return SvBezierCurve(points)
curves_out = [] for radius1s, radius2s, teeth_counts, tangent_ks in zip_long_repeat( radius1_in, radius2_in, teeth_count_in, tangent_k_in): for radius1, radius2, teeth_count, tangent_k in zip_long_repeat( radius1s, radius2s, teeth_counts, tangent_ks): circle1 = SvCircle(Matrix(), radius1) circle2 = SvCircle(Matrix(), radius2) t_min, t_max = circle1.get_u_bounds() t1s = np.linspace(t_min, t_max, num=teeth_count, endpoint=False) dt = (t_max - t_min) / teeth_count / 2 t2s = np.linspace(t_min + dt, t_max - dt, num=teeth_count) points1 = circle1.evaluate_array(t1s) tangents1 = circle1.tangent_array(t1s) points2 = circle2.evaluate_array(t2s) tangents2 = circle2.tangent_array(t2s) tangents1 *= tangent_k tangents2 *= tangent_k points = interweave(points1, points2) tangents = interweave(tangents1, tangents2) _, new_curves = SvBezierCurve.build_tangent_curve(points, tangents, cyclic=True, concat=True) curves_out.append(new_curves[0])
def to_bezier(self): u_min, u_max = self.get_u_bounds() p1 = self.evaluate(u_min) p2 = self.evaluate(u_max) return SvBezierCurve([p1, p2])
""" in verts_in v out curve_out C """ import numpy as np from sverchok.data_structure import zip_long_repeat, ensure_nesting_level from sverchok.utils.curve import SvCurve from sverchok.utils.curve.bezier import SvBezierCurve curve_out = [] for verts in verts_in: verts = np.array(verts) curve = SvBezierCurve.interpolate(verts, metric='POINTS') curve_out.append(curve)
def get_bezier_arc(self): cpts = np.array([self.p1, self.vertex, self.p2]) return SvBezierCurve(cpts)