cadquery
Sketch
Workplane
Assembly

Sketch.polygon()

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 polygon
  • closed: 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).

Example Usage

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.

Return Type

Sketch.polygon() returns a cadquery.Workplane object representing the sketch of the polygon.

Limits & Notes

  • The points parameter must be a list of tuples.
  • The minimum number of points required is 3.
  • The polygon is created on the XY plane.

Conclusion

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.