Skip to content

Measurements

Non-destructive queries on 2D and 3D geometry: bounding box, centroid, axis-aligned dimensions, surface area, and volume. None of these functions modify the geometry; all return plain numbers or arrays.

See also:

function measureBoundingBox(geometry: AnyGeom): [Vec3, Vec3]

Compute the axis-aligned bounding box of a geometry.

Returns two corner points [min, max] that define the smallest axis-aligned box enclosing the geometry.

Parameters:

Name Type Description
geometry — Any geometry object (Geom2, Geom3, or Path2).

Returns: [[minX, minY, minZ], [maxX, maxY, maxZ]] bounding box corners.

const { sphere } = jscad.primitives
const { measureBoundingBox } = jscad.measurements
async function main() {
const ball = sphere({ radius: 5 })
const [[minX, minY, minZ], [maxX, maxY, maxZ]] = measureBoundingBox(ball)
return { kind: 'plaintext', text: 'height: ' + (maxZ - minZ) }
}

See also:

function measureCenter(geometry: AnyGeom): Vec3

Measure the centre point of a geometry’s bounding box.

Parameters:

Name Type Description
geometry — Any geometry object (Geom2, Geom3, or Path2).

Returns: [cx, cy, cz] centre of the bounding box.

const { cylinder } = jscad.primitives
const { measureCenter } = jscad.measurements
async function main() {
const c = measureCenter(cylinder({ height: 10, radius: 3 }))
return { kind: 'plaintext', text: JSON.stringify(c) }
}

See also:

function measureDimensions(geometry: AnyGeom): Vec3

Measure the overall dimensions (width, depth, height) of a geometry.

Equivalent to subtracting the bounding box min from the max.

Parameters:

Name Type Description
geometry — Any geometry object (Geom2, Geom3, or Path2).

Returns: [width, depth, height] dimensions.

const { cuboid } = jscad.primitives
const { measureDimensions } = jscad.measurements
async function main() {
const [w, d, h] = measureDimensions(cuboid({ size: [8, 4, 2] }))
return { kind: 'plaintext', text: w + ' x ' + d + ' x ' + h }
}

See also:

function measureArea(geometry: Geom2 | Geom3): number

Measure the surface area of a 2D or 3D geometry.

For Geom2, returns the area of the filled region. For Geom3, returns the total surface area of all faces.

Parameters:

Name Type Description
geometry — A Geom2 or Geom3 geometry object.

Returns: Surface area in square units.

const { sphere } = jscad.primitives
const { measureArea } = jscad.measurements
async function main() {
const area = measureArea(sphere({ radius: 5 }))
return { kind: 'plaintext', text: 'Surface area: ' + area.toFixed(2) }
}

See also:

function measureVolume(geometry: Geom3): number

Measure the volume enclosed by a 3D geometry.

Parameters:

Name Type Description
geometry — A closed Geom3 solid.

Returns: Volume in cubic units.

const { sphere } = jscad.primitives
const { measureVolume } = jscad.measurements
async function main() {
const vol = measureVolume(sphere({ radius: 5 }))
return { kind: 'plaintext', text: 'Volume: ' + vol.toFixed(2) }
}

See also: