The Sketch.spline() method in CadQuery is used to create a spline curve in a 2D sketch.
Sketch.spline(control_points, degree=None)
control_points (list): List of points that define the spline curve. Each point should be a tuple of x, y coordinates.degree (int, optional): Degree of the spline curve. Defaults to None, which indicates an automatic curve degree selection.The Sketch.spline() method returns a Wire object that represents the spline curve.
Here is an example usage of Sketch.spline() to create a spline curve:
import cadquery as cq
# Create a new 2D sketch in the XY plane
sketch = cq.Workplane("XY").newSketch()
# Define the control points for the spline curve
control_points = [(0, 0), (1, 1), (2, 0), (3, -1), (4, 0)]
# Create the spline curve
spline_wire = sketch.spline(control_points)
# Extrude the spline curve to create a solid shape
solid = sketch.extrude(1.0)
In this example, we first create a new sketch in the XY plane using cq.Workplane("XY").newSketch(). We then define a list of control points to describe our desired spline curve.
Next, we call sketch.spline(control_points) to create the spline curve in our sketch. The spline() method returns a Wire object that represents the curve.
Finally, we extrude the sketch into a 3D shape using sketch.extrude(1.0).
control_points parameter for Sketch.spline() should contain at least 3 points to define a non-degenerate spline curve.degree is set to None, CadQuery will automatically select a degree for the spline curve based on the number of control points. However, manual selection of the curve degree may result in better results for certain types of curves.