Booleans
CSG (Constructive Solid Geometry) operations for combining, subtracting, and intersecting 2D and 3D geometry. All operations return new geometry without modifying the inputs.
See also:
function union(...geometries: AnyGeom[]): AnyGeomCombine two or more geometries into a single solid by merging their volumes.
All inputs must be the same dimension (all Geom2 or all Geom3).
Parameters:
| Name | Type | Description |
|---|---|---|
geometries |
— | Two or more geometry objects to merge. |
Returns: The union of all input geometries.
const { cube, sphere } = jscad.primitivesconst { union } = jscad.booleansasync function main() { return union(cube({ size: 6 }), sphere({ radius: 4 }))}See also:
subtract
Section titled “subtract”function subtract(base: AnyGeom, ...cutters: AnyGeom[]): AnyGeomSubtract one or more geometries from a base solid.
The first argument is the base; subsequent arguments are the cutters. All inputs must be the same dimension.
Parameters:
| Name | Type | Description |
|---|---|---|
base |
— | The solid to cut from. |
cutters |
— | One or more geometries to subtract from the base. |
Returns: The base with the cutter volumes removed.
const { cube, sphere } = jscad.primitivesconst { subtract } = jscad.booleansasync function main() { return subtract(cube({ size: 10 }), sphere({ radius: 6 }))}See also:
intersect
Section titled “intersect”function intersect(...geometries: AnyGeom[]): AnyGeomCompute the intersection (overlapping volume) of two or more geometries.
The result contains only the regions present in all inputs. All inputs must be the same dimension.
Parameters:
| Name | Type | Description |
|---|---|---|
geometries |
— | Two or more geometry objects to intersect. |
Returns: The intersection of all input geometries.
const { cube, sphere } = jscad.primitivesconst { intersect } = jscad.booleansasync function main() { return intersect(cube({ size: 8 }), sphere({ radius: 5 }))}See also:
scission
Section titled “scission”function scission(geometry: Geom3): Geom3[]Split a 3D geometry into its disconnected solid parts.
Useful when a model contains multiple non-touching shells that need to be individually coloured, positioned, or exported separately.
Parameters:
| Name | Type | Description |
|---|---|---|
geometry |
— | A Geom3 that may contain multiple disconnected shells. |
Returns: Array of Geom3, one per disconnected component.
const { scission } = jscad.booleansconst { sphere } = jscad.primitivesconst { translate } = jscad.transformsasync function main() { const pair = sphere({ radius: 2 }) const shifted = translate([6,0,0], sphere({ radius: 2 })) return scission(pair)}See also: