Skip to content

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[]): AnyGeom

Combine 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.primitives
const { union } = jscad.booleans
async function main() {
return union(cube({ size: 6 }), sphere({ radius: 4 }))
}

See also:

function subtract(base: AnyGeom, ...cutters: AnyGeom[]): AnyGeom

Subtract 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.primitives
const { subtract } = jscad.booleans
async function main() {
return subtract(cube({ size: 10 }), sphere({ radius: 6 }))
}

See also:

function intersect(...geometries: AnyGeom[]): AnyGeom

Compute 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.primitives
const { intersect } = jscad.booleans
async function main() {
return intersect(cube({ size: 8 }), sphere({ radius: 5 }))
}

See also:

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.booleans
const { sphere } = jscad.primitives
const { translate } = jscad.transforms
async function main() {
const pair = sphere({ radius: 2 })
const shifted = translate([6,0,0], sphere({ radius: 2 }))
return scission(pair)
}

See also: