def test_curve2_fitting(self): A = geom.Vertex((0.0, 0.0, 0.0)) B = geom.Vertex((0.5, 2.0, 0.0)) C = geom.Vertex((1.0, 2.0, 1.0)) curve = geom.BaseCurve((A, B, C), mmath.interp_bezier_curve_2) points = list(geom.sample_curve_samples(curve, 100)) vals = fit.fit_bezier_curve(points, mmath.interp_bezier_curve_2) self.assertTrue(np.allclose(np.array(vals), np.array([A, B, C]))) if HUMAN_READABLE_TESTS: print(DELIMETER) print(vals) print([A, B, C]) print(DELIMETER)
def plot_bezier_curve(points, function, figname): points_xs = [p[0] for p in points] points_ys = [p[1] for p in points] cpoints = fit.fit_bezier_curve(list(zip(points_xs, points_ys, [0] * len(points_xs))), function) cpoints_xs = [p[0] for p in cpoints] cpoints_ys = [p[1] for p in cpoints] curve = geom.BaseCurve([geom.Vertex(p) for p in cpoints], function) curve_points = list(geom.sample_curve_samples(curve, 100)) curve_xs = [p.x for p in curve_points] curve_ys = [p.y for p in curve_points] plt.plot(points_xs, points_ys, "o", color = "blue", label = "Input points") plt.plot(cpoints_xs, cpoints_ys, "o", color = "red", label = "Control points") plt.plot(curve_xs, curve_ys, color = "green", label = "Bezier curve") plt.grid() plt.legend() plt.savefig(OUT_GRAPH_DIR + figname) plt.show()
def plot_bezier_curve(points, function, figname): points_xs = [p[0] for p in points] points_ys = [p[1] for p in points] cpoints = fit.fit_bezier_curve( list(zip(points_xs, points_ys, [0] * len(points_xs))), function) cpoints_xs = [p[0] for p in cpoints] cpoints_ys = [p[1] for p in cpoints] curve = geom.BaseCurve([geom.Vertex(p) for p in cpoints], function) curve_points = list(geom.sample_curve_samples(curve, 100)) curve_xs = [p.x for p in curve_points] curve_ys = [p.y for p in curve_points] plt.plot(points_xs, points_ys, "o", color="blue", label="Input points") plt.plot(cpoints_xs, cpoints_ys, "o", color="red", label="Control points") plt.plot(curve_xs, curve_ys, color="green", label="Bezier curve") plt.grid() plt.legend() plt.savefig(OUT_GRAPH_DIR + figname) plt.show()