Transformations

Transformation methods return a new Shape — they do not mutate the original.

translate

.translate([x, y, z]) — Moves a shape.

const s = sphere(10).translate([20, 0, 5]);
const result = box(40, 40, 5).add(s);

rotate

.rotate([rx, ry, rz]) — Rotates a shape in degrees around X, Y, Z axes (applied in that order).

const result = cylinder(5, 30).rotate([90, 0, 0]);   // lay on its side

scale

.scale(factor) — Uniform scale with a single number, or non-uniform with an array.

shape.scale(2)              // double in all axes
shape.scale([2, 1, 0.5])    // non-uniform

mirror

.mirror([nx, ny, nz]) — Mirrors the shape across the plane defined by the given normal vector.

const half  = extrude([[0,0],[10,0],[10,15],[0,10]], 5);
const other = half.mirror([1, 0, 0]);
const result = half.add(other);

bbox

.bbox() — Returns the bounding box of the shape: { min: [x,y,z], max: [x,y,z] }.

const b = box(30, 20, 10);
const bb = b.bbox();
// bb.max[2] === 5  (half-height, centered at origin)

Useful for stacking shapes:

const base = box(40, 40, 5);
const top  = sphere(10).translate([0, 0, base.bbox().max[2] + 10]);
const result = base.add(top);