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:
measureBoundingBox
Section titled “measureBoundingBox”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.primitivesconst { measureBoundingBox } = jscad.measurementsasync 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:
measureCenter
Section titled “measureCenter”function measureCenter(geometry: AnyGeom): Vec3Measure 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.primitivesconst { measureCenter } = jscad.measurementsasync function main() { const c = measureCenter(cylinder({ height: 10, radius: 3 })) return { kind: 'plaintext', text: JSON.stringify(c) }}See also:
measureDimensions
Section titled “measureDimensions”function measureDimensions(geometry: AnyGeom): Vec3Measure 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.primitivesconst { measureDimensions } = jscad.measurementsasync function main() { const [w, d, h] = measureDimensions(cuboid({ size: [8, 4, 2] })) return { kind: 'plaintext', text: w + ' x ' + d + ' x ' + h }}See also:
measureArea
Section titled “measureArea”function measureArea(geometry: Geom2 | Geom3): numberMeasure 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.primitivesconst { measureArea } = jscad.measurementsasync function main() { const area = measureArea(sphere({ radius: 5 })) return { kind: 'plaintext', text: 'Surface area: ' + area.toFixed(2) }}See also:
measureVolume
Section titled “measureVolume”function measureVolume(geometry: Geom3): numberMeasure the volume enclosed by a 3D geometry.
Parameters:
| Name | Type | Description |
|---|---|---|
geometry |
— | A closed Geom3 solid. |
Returns: Volume in cubic units.
const { sphere } = jscad.primitivesconst { measureVolume } = jscad.measurementsasync function main() { const vol = measureVolume(sphere({ radius: 5 })) return { kind: 'plaintext', text: 'Volume: ' + vol.toFixed(2) }}See also: