Sketch.polygon()
is a method in the cadquery
module that allows you to create a 2D polygon sketch. This method takes the following parameters:
points
: a list of (x, y) tuples representing the vertices of the polygonclosed
: a boolean value (default: True
) indicating whether the polygon should be closed (i.e., whether the last point should be connected to the first point).import cadquery as cq
# Create a square polygon
points = [
(0, 0),
(0, 1),
(1, 1),
(1, 0)
]
square = cq.Workplane("XY").polygon(points)
# Create a star polygon
points = [
(0, 0),
(0.5, 1),
(1, 0),
(0, 0.5),
(1, 0.5),
(0.5, 0),
]
star = cq.Workplane("XY").polygon(points)
In this example, we created two different polygons using Sketch.polygon()
: a square and a star.
Sketch.polygon()
returns a cadquery.Workplane
object representing the sketch of the polygon.
points
parameter must be a list of tuples.Sketch.polygon()
is a useful method in cadquery
that allows you to create 2D polygons for use in your CAD designs. With this method, you can easily create complex shapes that would otherwise be difficult to create using other methods.