Booleans
Union, intersection, and difference compose shapes in every representation — exact
BrepBoolean topology surgery in B-Rep, min/max in the implicit engine, and mesh
booleans as the fallback. The operators |, &, and - are shorthand for
Union, Intersect, and Subtract:
var block = Shape.Box(24, 24, 12);var post = Shape.Cylinder(radius: 7, height: 28).Translate(4, 4, 0);
var scene = new Scene();scene.Add(new Part("union", block | post, Palette.Steel, Matrix4d.CreateTranslation((-36, 0, 14))));scene.Add(new Part("intersection", block & post, Palette.Brass, Matrix4d.CreateTranslation((0, 0, 14))));scene.Add(new Part("difference", block - post, Palette.Coral, Matrix4d.CreateTranslation((36, 0, 14))));
A classic machined part is just a chain of differences:
var block = Shape.Box(60, 36, 16) - Shape.Cylinder(6, 30).Translate(-19, 0, 0) // through bore - Shape.Cylinder(6, 30).Translate(19, 0, 0) - Shape.Box(20, 40, 12).Translate(0, 0, 6); // milled top channel
var scene = new Scene();scene.Add(new Part("machined block", block, Palette.Sky, Matrix4d.CreateTranslation((0, 0, 8))));
In the B-Rep lowering the result is topologically sealed — it passes Validate()
and Euler–Poincaré with the correct genus, so downstream operations (tessellation,
STEP export, further booleans) get a watertight solid. For soft, blended joins use
smooth booleans instead.
Cuts that break out of more than one face
A tool does not have to stay inside the face it enters. Here a cross bore is placed high enough that its rim runs off the top of the walls it pierces, opening the plate into a channel — three faces cut by one cylinder:
var plate = Shape.Extrude(Sketch.Rectangle(60, 30), 12); // sketch extrusionvar channel = Shape.Cylinder(radius: 5, height: 80) .RotateX(-Math.PI / 2) // axis along Y .Translate(0, 0, 11); // rim runs off the top face
var scene = new Scene();scene.Add(new Part("channel", plate - channel, Palette.Steel));
That the plate is a sketch extrusion rather than a Shape.Box matters to the
kernel, though not to you: an extrusion’s side walls are bounded planar patches, so
the bore’s rim is a real circle of the wall’s plane with only an arc of it on the
wall. The exact conic is clipped to the arc the wall carries, in closed form, so the
arc’s ends land on the wall’s top edge exactly where the top face’s own cut begins —
which is what lets the pieces weld. The volume converges quadratically onto the
analytic answer, and matches the same plate built as a box to 1e-11.
Convex hull
Shape.Hull(operands...) (OpenSCAD’s hull()) wraps its operands in the tightest
convex skin — the quick way to make rounded pads and tapered transitions without
sketching them:
var pad = Shape.Hull( // rounded mounting pad: Shape.Sphere(4).Translate(-14, -9, 4), // the hull of four corner spheres Shape.Sphere(4).Translate(14, -9, 4), Shape.Sphere(4).Translate(14, 9, 4), Shape.Sphere(4).Translate(-14, 9, 4));
var stand = Shape.Hull( // tapered transition, disc to ball Shape.Cylinder(radius: 9, height: 4), Shape.Sphere(4.5).Translate(0, 0, 20));
var scene = new Scene();scene.Add(new Part("pad", pad, Palette.Sage, Matrix4d.CreateTranslation((-22, 0, 0))));scene.Add(new Part("stand", stand, Palette.Plum, Matrix4d.CreateTranslation((22, 0, 2))));
The honest support story: the hull is computed by quickhull over the operands’
mesh vertices. That is exact for polyhedral operands (boxes, polygonal
extrusions); curved operands contribute their tessellated vertices, so the result
is the hull of the tessellation — inscribed in the true hull, tightened by raising
MeshQuality.SegmentsPerCircle. Explain reports hulls as Bridged for every
target, and they can never become B-Rep (there is no mesh→B-Rep import) — see the
support matrix.