OpenSCAD 2D primitives & extrusion
2D primitives live in the XY plane and become 3D when you extrude them
with linear_extrude (push them up along Z) or
rotate_extrude (sweep them around the Z axis to make
rotationally-symmetric parts). Most non-boxy real-world parts are
cheapest to build this way.
circle
circle(r);
circle(d=diameter);
Like sphere, takes r OR d and honors $fn/$fa/$fs. Use $fn=6 for a hexagon, $fn=3 for an equilateral triangle.
square
square(size, center=false);
square([w, h], center=false);
A 2D rectangle. size can be a single number (square) or a 2-vector [width, height].
polygon
The escape hatch for any 2D shape you can describe with a list of points.
polygon(points = [[0,0], [20,0], [20,10], [10,15], [0,10]]);
// With holes (multiple paths):
polygon(
points = [[0,0],[20,0],[20,20],[0,20],
[5,5],[15,5],[15,15],[5,15]],
paths = [[0,1,2,3], [4,5,6,7]] // outer + inner hole
);
text
Generates 2D text using a system or imported font. Becomes 3D when you linear_extrude it.
text("PrintPal", size=10, font="Liberation Sans:style=Bold",
halign="center", valign="center");
linear_extrude(height=2)
text("v1.2", size=5);
Parameters: size, font, halign, valign, direction, spacing, language, script.
import (2D)
import("logo.svg");
import("profile.dxf");
SVG support is the modern path; many people use SVG so they can author shapes in Inkscape or Figma and extrude them in OpenSCAD.
linear_extrude
Push a 2D shape straight up along Z. The flagship 2D→3D operator.
linear_extrude(height, center=false, convexity=10,
twist=0, slices=20, scale=1) { ... }
| Parameter | Type | Description |
|---|---|---|
height | number | Extrusion length in mm. |
center | bool | Center along Z. |
twist | number | Total twist in degrees from base to top. Makes a spiral. |
slices | int | Number of intermediate cross-sections (smoothness of the twist). |
scale | number or 2-vector | Scale factor at the top. 0 tapers to a point (pyramid/cone). |
convexity | int | Render hint for shapes with holes. |
Examples
linear_extrude(height=10) circle(d=20, $fn=64);
// Twisted vase profile
linear_extrude(height=60, twist=180, slices=60, scale=1.4, $fn=64)
polygon([[0,0], [20,0], [15,8], [25,15], [0,18]]);
// 3D nameplate
linear_extrude(height=3)
text("Hello", size=15, halign="center", valign="center");
rotate_extrude
Sweep a 2D shape around the Z axis. The 2D profile must sit entirely on the +X side of the Y axis (no negative X values). Use it for bottles, vases, wheels, pulleys, knobs — anything rotationally symmetric.
rotate_extrude(angle=360, convexity=10) { ... }
Vase
rotate_extrude($fn=120)
polygon([
[0,0], [22,0], [18,15],
[26,40], [14,55], [0,55]
]);
Torus (offset circle, swept)
rotate_extrude($fn=128)
translate([20, 0, 0])
circle(r=5, $fn=48);
Pass angle=120 to sweep only 120°. Combine with rotate to position multiple pie pieces — perfect for blade housings and fan ducts.
projection
Convert a 3D shape back into 2D — useful for generating DXF/SVG drawings from your model.
projection(cut=false) cube([40,20,10]); // silhouette
projection(cut=true)
translate([0,0,-5]) cylinder(h=10, d=20); // cross-section at Z=0
offset
Grow or shrink a 2D shape. Round corners with r, chamfer with delta + chamfer=true.
offset(r=3) square([40, 20]); // rounded rectangle
offset(delta=-1) polygon([[0,0],[10,0],[5,10]]); // shrink by 1 mm
offset(delta=2, chamfer=true) square([10,10]); // chamfered
Vases, bottles, gears, signs — all great extrusion candidates
Tell the AI agent "bud vase, 60 mm tall, twisted hexagonal profile" and it will pick rotate_extrude or linear_extrude with twist, generate the polygon, and render in seconds.