for p, t in zip(data, tangents): msp.add_line(p, p + t, dxfattribs={ 'color': 5, 'layer': f'Estimated tangents ({METHOD})' }) # local interpolation: a normalized tangent vector for each data point is required, s = local_cubic_bspline_interpolation( data, tangents=[t.normalize() for t in tangents]) # or set argument 'method' for automatic tangent estimation, default method is '5-points' interpolation # s = local_cubic_bspline_interpolation(data, method=METHOD) msp.add_spline(dxfattribs={ 'color': 3, 'layer': f'Local interpolation ({METHOD})' }).apply_construction_tool(s) # global interpolation: take first and last vector from 'tangents' as start- and end tangent m1, m2 = estimate_end_tangent_magnitude(data, method='chord') s = global_bspline_interpolation(data, tangents=(tangents[0].normalize(m1), tangents[-1].normalize(m2))) msp.add_spline(dxfattribs={ 'color': 4, 'layer': f'Global interpolation ({METHOD})' }).apply_construction_tool(s) doc.set_modelspace_vport(5, center=(4, 1)) doc.saveas(DIR / f'sine-wave-{METHOD}.dxf')
'layer': 'BricsCAD B-spline', 'color': 2 }) zoom.extents(msp) doc.saveas(DIR / 'concept-0-fit-points-only.dxf') # ------------------------------------------------------------------------------ # SPLINE from fit points WITH given end tangents. # ------------------------------------------------------------------------------ # 2. Store fit points, start- and end tangent values in DXF file: doc, msp = setup() # Tangent estimation method: "Total Chord Length", # returns sum of chords for m1 and m2 m1, m2 = estimate_end_tangent_magnitude(points, method='chord') # Multiply tangent vectors by total chord length for global interpolation: start_tangent = Vec3.from_deg_angle(100) * m1 end_tangent = Vec3.from_deg_angle(-100) * m2 # Interpolate control vertices from fit points and end derivatives as constraints s = global_bspline_interpolation(points, degree=3, tangents=(start_tangent, end_tangent)) msp.add_spline(dxfattribs={ 'color': 4, 'layer': 'Global Interpolation' }).apply_construction_tool(s) # Result matches the BricsCAD interpolation if fit points, start- and end # tangents are stored explicit in the DXF file. spline = msp.add_spline(points,