Contents



Learning Objectives

  • Understand the usage and flexibility of the polygon() function in OpenSCAD.
  • Learn how to create multiple-sided shapes with irregular, concave, and convex edges.
  • Learn how to create shapes with holes and multiple holes.

Introduction to polygon() function in OpenSCAD

The polygon() function in OpenSCAD is an extremely powerful tool that allows you to create a wide range of 2D shapes beyond basic squares and circles. By specifying a list of x,y coordinates, you can create irregular shapes with concave and convex edges. More importantly, you can even create shapes with holes and multiple holes in them.

The structure of the polygon() function is as follows:

polygon(points = [ [x, y], ... ], paths = [ [p1, p2, p3..], ...], convexity = N);

The points parameter specifies the list of x,y coordinates of the polygon.

The paths parameter defines the order in which these points are connected. If multiple paths are specified, you can create primary and secondary shapes, with secondary shapes subtracted from the primary shape, similar to the difference() function.

The convexity parameter defines the integer number of “inward” curves, i.e., the expected path crossings of an arbitrary line through the polygon.

Working with the polygon() function

TEXT:

  • Create a simple polygon without any holes, for example:
    polygon(points=[[0,0],[100,0],[130,50],[30,50]]);
    
  • To create a shape with one hole, use multiple paths:
    polygon(points=[[0,0],[100,0],[0,100],[10,10],[80,10],[10,80]], paths=[[0,1,2],[3,4,5]],convexity=10);
    
  • To create a shape with multiple holes, use the concat() function to combine your points and paths:
    a0 = [[0,0],[100,0],[130,50],[30,50]];     // main
    b0 = [1,0,3,2];
    a1 = [[20,20],[40,20],[30,30]];            // hole 1
    b1 = [4,5,6];
    a2 = [[50,20],[60,20],[40,30]];            // hole 2
    b2 = [7,8,9];
    a3 = [[65,10],[80,10],[80,40],[65,40]];    // hole 3
    b3 = [10,11,12,13];
    a4 = [[98,10],[115,40],[85,40],[85,10]];   // hole 4
    b4 = [14,15,16,17];
    a  = concat (a0,a1,a2,a3,a4);
    b  = [b0,b1,b2,b3,b4];
    polygon(a,b);
    

Review

In this lesson you learned:

  • What the polygon() function in OpenSCAD does and how to use it.
  • How to create irregular shapes with the polygon() function.
  • How to create shapes with holes and multiple holes in them.

Resources