def test_rational_spline_from_circular_arc_has_expected_parameters(): arc = ConstructionArc(end_angle=90) spline = rational_bspline_from_arc(end_angle=arc.end_angle) assert spline.degree == 2 cpoints = spline.control_points assert len(cpoints) == 3 assert cpoints[0].isclose((1, 0, 0)) assert cpoints[1].isclose((1, 1, 0)) assert cpoints[2].isclose((0, 1, 0)) weights = spline.weights() assert len(weights) == 3 assert weights[0] == 1.0 assert weights[1] == math.cos(math.pi / 4) assert weights[2] == 1.0 # as BSpline constructor() s2 = BSpline.from_arc(arc) assert spline.control_points == s2.control_points
end_angle=165, dxfattribs={ "layer": "source arc", "color": ezdxf.const.RED, } ) # create a SPLINE entity from ARC, in your scenario these are the source # entities of your DXF document! spline = msp.add_spline(dxfattribs={ "layer": "B-Spline", "color": ezdxf.const.YELLOW, }) # create a B-spline construction tool from ARC arc_tool = arc.construction_tool() bspline = BSpline.from_arc(arc_tool) spline.apply_construction_tool(bspline) # Recreate ARC from SPLINE, if you ASSUME or KNOW it is an ARC: # for spline in msp.query("SPLINE): # ... # 1. get the B-spline construction tool from the SPLINE entity bspline = spline.construction_tool() max_t = bspline.max_t # calculate 3 significant points and 2 check points of the SPLINE: start, chk1, middle, chk2, end = bspline.points([ 0, max_t * 0.25, max_t * 0.5, max_t * 0.75, max_t ]) # create an arc from 3 points:
# ------------------------------------------------------------------------------ # Create SPLINE from ARC # # The BSpline.from_arc() method creates a rational B-spline that is a perfect # circular arc. # ------------------------------------------------------------------------------ doc, msp = new_doc() arc = msp.add_arc( (0, 0), radius=3, start_angle=30, end_angle=330, dxfattribs={"layer": "ENTITY"}, ) s = BSpline.from_arc(arc.construction_tool()) spline = msp.add_spline(dxfattribs={"layer": "SPLINE"}) spline.apply_construction_tool(s) add_control_frame(spline) add_control_polyline(spline) save(DIR / "spline_from_arc.dxf") # ------------------------------------------------------------------------------ # Create SPLINE from ELLIPSE # # The BSpline.from_ellipse() method creates a rational B-spline that is a # perfect elliptic arc. # ------------------------------------------------------------------------------ doc, msp = new_doc() ellipse = msp.add_ellipse(