Transforms
Spatial transformation operations for 2D and 3D geometry: translation, rotation (with axis-specific shortcuts), uniform and non-uniform scaling, mirroring across a plane, centering on axes, and multi-geometry alignment. All operations return new geometry without modifying the inputs.
See also:
translate
Section titled “translate”function translate(vector: Vec3, geometries: AnyGeom | AnyGeom[]): AnyGeom | AnyGeom[]Move geometry by an offset vector along the X, Y, and Z axes.
Parameters:
| Name | Type | Description |
|---|---|---|
vector |
— | [dx, dy, dz] translation offset. |
geometries |
— | One geometry or an array of geometries to move. |
Returns: The translated geometry or array.
const { cube } = jscad.primitivesconst { translate } = jscad.transformsasync function main() { return translate([10, 0, 5], cube({ size: 4 }))}See also:
translateX
Section titled “translateX”function translateX(offset: number, geometries: AnyGeom | AnyGeom[]): AnyGeom | AnyGeom[]Move geometry along the X axis only.
Parameters:
| Name | Type | Description |
|---|---|---|
offset |
— | Distance to move along X. |
geometries |
— | One geometry or an array of geometries to move. |
Returns: The translated geometry or array.
const { sphere } = jscad.primitivesconst { translateX } = jscad.transformsasync function main() { return translateX(5, sphere({ radius: 2 }))}See also:
translateY
Section titled “translateY”function translateY(offset: number, geometries: AnyGeom | AnyGeom[]): AnyGeom | AnyGeom[]Move geometry along the Y axis only.
Parameters:
| Name | Type | Description |
|---|---|---|
offset |
— | Distance to move along Y. |
geometries |
— | One geometry or an array of geometries to move. |
Returns: The translated geometry or array.
See also:
translateZ
Section titled “translateZ”function translateZ(offset: number, geometries: AnyGeom | AnyGeom[]): AnyGeom | AnyGeom[]Move geometry along the Z axis only.
Parameters:
| Name | Type | Description |
|---|---|---|
offset |
— | Distance to move along Z. |
geometries |
— | One geometry or an array of geometries to move. |
Returns: The translated geometry or array.
See also:
rotate
Section titled “rotate”function rotate(angles: Vec3, geometries: AnyGeom | AnyGeom[]): AnyGeom | AnyGeom[]Rotate geometry around the X, Y, and Z axes by the given angles.
Rotations are applied in X → Y → Z order. All angles are in radians. Use the utils.degToRad() helper to convert from degrees.
Parameters:
| Name | Type | Description |
|---|---|---|
angles |
— | [rx, ry, rz] rotation angles in radians. |
geometries |
— | One geometry or an array of geometries to rotate. |
Returns: The rotated geometry or array.
const { cylinder } = jscad.primitivesconst { rotate } = jscad.transformsconst { degToRad } = jscad.utilsasync function main() { return rotate([degToRad(90), 0, 0], cylinder({ height: 8, radius: 2 }))}See also:
rotateX
Section titled “rotateX”function rotateX(angle: number, geometries: AnyGeom | AnyGeom[]): AnyGeom | AnyGeom[]Rotate geometry around the X axis by the given angle in radians.
Parameters:
| Name | Type | Description |
|---|---|---|
angle |
— | Rotation angle in radians. |
geometries |
— | One geometry or an array of geometries to rotate. |
Returns: The rotated geometry or array.
See also:
rotateY
Section titled “rotateY”function rotateY(angle: number, geometries: AnyGeom | AnyGeom[]): AnyGeom | AnyGeom[]Rotate geometry around the Y axis by the given angle in radians.
Parameters:
| Name | Type | Description |
|---|---|---|
angle |
— | Rotation angle in radians. |
geometries |
— | One geometry or an array of geometries to rotate. |
Returns: The rotated geometry or array.
See also:
rotateZ
Section titled “rotateZ”function rotateZ(angle: number, geometries: AnyGeom | AnyGeom[]): AnyGeom | AnyGeom[]Rotate geometry around the Z axis by the given angle in radians.
Parameters:
| Name | Type | Description |
|---|---|---|
angle |
— | Rotation angle in radians. |
geometries |
— | One geometry or an array of geometries to rotate. |
Returns: The rotated geometry or array.
See also:
function scale(factors: Vec3, geometries: AnyGeom | AnyGeom[]): AnyGeom | AnyGeom[]Scale geometry along the X, Y, and Z axes.
Parameters:
| Name | Type | Description |
|---|---|---|
factors |
— | [sx, sy, sz] scale factors. Values > 1 enlarge; values < 1 shrink. |
geometries |
— | One geometry or an array of geometries to scale. |
Returns: The scaled geometry or array.
const { sphere } = jscad.primitivesconst { scale } = jscad.transformsasync function main() { return scale([2, 1, 0.5], sphere({ radius: 3 }))}See also:
mirror
Section titled “mirror”function mirror( options: { origin?: Vec3; normal?: Vec3 }, geometries: AnyGeom | AnyGeom[] ): AnyGeom | AnyGeom[]Mirror (reflect) geometry across a plane defined by an origin and normal vector.
Parameters:
| Name | Type | Description |
|---|---|---|
options |
— | Mirror options. |
options.origin |
— | A point on the mirror plane. Default [0, 0, 0]. |
options.normal |
— | Normal vector of the mirror plane. Default [0, 0, 1]. |
geometries |
— | One geometry or an array of geometries to mirror. |
Returns: The mirrored geometry or array.
const { cylinder } = jscad.primitivesconst { mirror, translate } = jscad.transformsasync function main() { const half = translate([5, 0, 0], cylinder({ height: 10, radius: 2 })) return [half, mirror({ normal: [1, 0, 0] }, half)]}See also:
center
Section titled “center”function center( options: { axes?: [boolean, boolean, boolean]; relativeTo?: AnyGeom }, geometries: AnyGeom | AnyGeom[] ): AnyGeom | AnyGeom[]Move geometry so that its bounding box is centred on the specified axes.
Parameters:
| Name | Type | Description |
|---|---|---|
options |
— | Center options. |
options.axes |
— | Which axes to center on [x, y, z]. Default [true, true, true]. |
options.relativeTo |
— | Reference geometry; if given, centers relative to its bounding box. |
geometries |
— | One geometry or an array of geometries to center. |
Returns: The recentred geometry or array.
const { cuboid } = jscad.primitivesconst { center } = jscad.transformsasync function main() { return center({ axes: [true, true, false] }, cuboid({ size: [10, 6, 2] }))}See also:
function align( options: { modes?: Array<'min' | 'center' | 'max' | 'none'>; relativeTo?: AnyGeom[]; grouped?: boolean; }, ...geometries: AnyGeom[] ): AnyGeom[]Align multiple geometries relative to each other or to an absolute position.
Each axis independently snaps to the minimum, centre, or maximum of the combined bounding box.
Parameters:
| Name | Type | Description |
|---|---|---|
options |
— | Align options. |
options.modes |
— | Per-axis mode: ‘min’, ‘center’, ‘max’, or ‘none’. Default [‘none’, ‘none’, ‘none’]. |
options.relativeTo |
— | Align relative to these geometries’ bounding box instead of the inputs. |
options.grouped |
— | Move all inputs as a rigid group. Default false. |
geometries |
— | Two or more geometries to align. |
Returns: The aligned geometries as an array.
const { cube, cylinder } = jscad.primitivesconst { align } = jscad.transformsasync function main() { return align({ modes: ['min', 'center', 'min'] }, cube({ size: 8 }), cylinder({ height: 12, radius: 2 }))}See also: