Sketch.ellipse()
is a method in the cadquery
python library that is used to create an elliptical sketch in the 2D plane. This method is similar to the Sketch.circle()
method, but instead of a circle, it allows for the creation of an ellipse.
The syntax for the Sketch.ellipse()
method is as follows:
ellipse(center, major_radius, minor_radius, angle=0.0, startangle=0.0, endangle=360.0)
center
- This parameter specifies the center point of the ellipse. It takes a tuple of two values representing the X and Y coordinates of the center point.
major_radius
- This parameter specifies the length of the major axis of the ellipse.
minor_radius
- This parameter specifies the length of the minor axis of the ellipse.
angle
- This parameter specifies the rotation angle of the ellipse in degrees. The default value is 0.0 degrees.
startangle
- This parameter specifies the start angle of the ellipse in degrees. The default value is 0.0 degrees.
endangle
- This parameter specifies the end angle of the ellipse in degrees. The default value is 360.0 degrees.
The Sketch.ellipse()
method does not return any value. Instead, it creates a new ellipse sketch in the 2D plane.
Here is an example of using the Sketch.ellipse()
method to create an elliptical sketch:
import cadquery as cq
# Create a new sketch object in the XY plane
sketch = cq.Workplane("XY").sketch()
# Create an ellipse centered at the origin with a major radius of 5 and a minor radius of 2
center = (0, 0)
major_r = 5
minor_r = 2
sketch.ellipse(center, major_r, minor_r)
# Create an ellipse centered at (3, 3) with a major radius of 2 and a minor radius of 5
center = (3, 3)
major_r = 2
minor_r = 5
sketch.ellipse(center, major_r, minor_r)
# Display the created sketch
show_object(sketch)
This code will create a new sketch object in the XY plane, and use the Sketch.ellipse()
method to create two elliptical sketches. The first ellipse will be centered at the origin with a major radius of 5 and a minor radius of 2. The second ellipse will be centered at (3, 3) with a major radius of 2 and a minor radius of 5. Finally, the show_object()
method is used to display the created sketch.
The Sketch.ellipse()
method in the cadquery
python library is a useful tool for creating elliptical sketches in the 2D plane. By specifying the center point, major and minor radii, rotation angle and start/end angles, complex shapes can be created easily.