Make a polygon for each item on the stack. By default, each polygon is created by inscribing it in a circle of the specified diameter, such that the first vertex is oriented in the x direction. Alternatively, each polygon can be created by circumscribing it around
(
self: T,
nSides: int,
diameter: float,
forConstruction: bool = False,
circumscribed: bool = False,
)
| 2647 | return self.eachpoint(lambda loc: e.moved(loc), True) |
| 2648 | |
| 2649 | def polygon( |
| 2650 | self: T, |
| 2651 | nSides: int, |
| 2652 | diameter: float, |
| 2653 | forConstruction: bool = False, |
| 2654 | circumscribed: bool = False, |
| 2655 | ) -> T: |
| 2656 | """ |
| 2657 | Make a polygon for each item on the stack. |
| 2658 | |
| 2659 | By default, each polygon is created by inscribing it in a circle of the |
| 2660 | specified diameter, such that the first vertex is oriented in the x direction. |
| 2661 | Alternatively, each polygon can be created by circumscribing it around |
| 2662 | a circle of the specified diameter, such that the midpoint of the first edge |
| 2663 | is oriented in the x direction. Circumscribed polygons are thus rotated by |
| 2664 | pi/nSides radians relative to the inscribed polygon. This ensures the extent |
| 2665 | of the polygon along the positive x-axis is always known. |
| 2666 | This has the advantage of not requiring additional formulae for purposes such as |
| 2667 | tiling on the x-axis (at least for even sided polygons). |
| 2668 | |
| 2669 | :param nSides: number of sides, must be >= 3 |
| 2670 | :param diameter: the diameter of the circle for constructing the polygon |
| 2671 | :param circumscribed: circumscribe the polygon about a circle |
| 2672 | :type circumscribed: true to create the polygon by circumscribing it about a circle, |
| 2673 | false to create the polygon by inscribing it in a circle |
| 2674 | :return: a polygon wire |
| 2675 | """ |
| 2676 | |
| 2677 | # pnt is a vector in local coordinates |
| 2678 | angle = 2.0 * math.pi / nSides |
| 2679 | radius = diameter / 2.0 |
| 2680 | if circumscribed: |
| 2681 | radius /= math.cos(angle / 2.0) |
| 2682 | pnts = [] |
| 2683 | for i in range(nSides + 1): |
| 2684 | o = angle * i |
| 2685 | if circumscribed: |
| 2686 | o += angle / 2.0 |
| 2687 | pnts.append(Vector(radius * math.cos(o), radius * math.sin(o), 0,)) |
| 2688 | p = Wire.makePolygon(pnts, forConstruction) |
| 2689 | |
| 2690 | return self.eachpoint(lambda loc: p.moved(loc), True) |
| 2691 | |
| 2692 | def polyline( |
| 2693 | self: T, |