2D shapes

Renders the 3D model in your browser. The first run downloads the Python runtime (≈30 MB).
from cadbuildr.foundation import *


class Shapes2DAssembly(Assembly):
    """Five 2D shape primitives extruded for visualization.

    `RectangleRounded(center, w, h, radius)` — filleted rectangle.
    `Trapezoid(center, w_top, w_bottom, h)` — symmetric trapezoid.
    `Triangle(p1, p2, p3)` — flat triangle from 3 sketch points.
    `ConvexHull(points)` — 2D convex hull of an arbitrary point set.
    Existing `RegularPolygon(center, n_sides, radius)` rounds out the set.
    """

    def __init__(self):
        class Rounded(Part):
            def __init__(self):
                s = Sketch(self.xy())
                self.add_operation(Extrusion(
                    RectangleRounded(s.origin, w=20, h=12, radius=3), end=2,
                ))
                self.paint("tan")

        class Trap(Part):
            def __init__(self):
                s = Sketch(self.xy())
                self.add_operation(Extrusion(
                    Trapezoid(s.origin, w_top=8, w_bottom=20, h=10), end=2,
                ))
                self.translate([30, 0, 0])
                self.paint("bright_yellow")

        class Tri(Part):
            def __init__(self):
                s = Sketch(self.xy())
                self.add_operation(Extrusion(
                    Triangle(Point(s, 0, 0), Point(s, 15, 0), Point(s, 7, 12)), end=2,
                ))
                self.translate([60, 0, 0])
                self.paint("bright_red")

        class Hull(Part):
            def __init__(self):
                s = Sketch(self.xy())
                pts = [Point(s, 0, 0), Point(s, 15, 0), Point(s, 15, 10),
                       Point(s, 0, 10), Point(s, 7, 5)]  # last point is interior
                self.add_operation(Extrusion(ConvexHull(points=pts), end=2))
                self.translate([90, 0, 0])
                self.paint("light_green")

        self.add_component(Rounded())
        self.add_component(Trap())
        self.add_component(Tri())
        self.add_component(Hull())


show(Shapes2DAssembly())

A handful of 2D primitives that compose with Extrusion, Lathe, Sweep, and Loft:

RectangleRounded(center, w, h, radius)        # filleted rectangle
Trapezoid(center, w_top, w_bottom, h)         # symmetric trapezoid
Triangle(p1, p2, p3)                          # triangle from 3 sketch points
ConvexHull(points)                            # 2D convex hull (monotone chain)
Text(sketch, text, size)                      # glyph outlines; see Sketches → Text

RegularPolygon, Hexagon, Circle, Ellipse, Rectangle, and Square are documented separately — those are the existing canonical 2D types.