modeling/transforms

All shapes (primitives or the results of operations) can be transformed, such as scaled or rotated. In all cases, the function returns the results, and never changes the original shapes.

Source:
Example
const { center, rotateX, translate } = require('@jscad/modeling').transforms

Methods

(static) align(options, …geometries) → {Object|Array}

Source:

Align the boundaries of the given geometries using the given options.

Example
let alignedGeometries = align({modes: ['min', 'center', 'none'], relativeTo: [10, null, 10], grouped: true }, geometries)
Parameters:
Name Type Attributes Description
options Object

options for aligning

Properties
Name Type Attributes Default Description
modes Array <optional>
['center', 'center', 'min']

the point on the geometries to align to for each axis. Valid options are "center", "max", "min", and "none".

relativeTo Array <optional>
[0,0,0]

The point one each axis on which to align the geometries upon. If the value is null, then the corresponding value from the group's bounding box is used.

grouped Boolean <optional>
false

if true, transform all geometries by the same amount, maintaining the relative positions to each other.

geometries Object <repeatable>

the geometries to align

Returns:

the aligned geometry, or a list of aligned geometries

Type
Object | Array

(static) center(options, …geometries) → {Object|Array}

Source:

Center the given geometries using the given options.

Example
let myshape = center({axes: [true,false,false]}, sphere()) // center about the X axis
Parameters:
Name Type Attributes Description
options Object

options for centering

Properties
Name Type Attributes Default Description
axes Array <optional>
[true,true,true]

axis of which to center, true or false

relativeTo Array <optional>
[0,0,0]

relative point of which to center the geometries

geometries Object <repeatable>

the geometries to center

Returns:

the centered geometry, or a list of centered geometries

Type
Object | Array

(static) centerX(…geometries) → {Object|Array}

Source:

Center the given geometries about the X axis.

Parameters:
Name Type Attributes Description
geometries Object <repeatable>

the geometries to center

Returns:

the centered geometry, or a list of centered geometry

Type
Object | Array

(static) centerY(…geometries) → {Object|Array}

Source:

Center the given geometries about the Y axis.

Parameters:
Name Type Attributes Description
geometries Object <repeatable>

the geometries to center

Returns:

the centered geometry, or a list of centered geometry

Type
Object | Array

(static) centerZ(…geometries) → {Object|Array}

Source:

Center the given geometries about the Z axis.

Parameters:
Name Type Attributes Description
geometries Object <repeatable>

the geometries to center

Returns:

the centered geometry, or a list of centered geometry

Type
Object | Array

(static) mirror(options, …geometries) → {Object|Array}

Source:

Mirror the given geometries using the given options.

Example
let myshape = mirror({normal: [0,0,10]}, cube({center: [0,0,15], radius: [20, 25, 5]}))
Parameters:
Name Type Attributes Description
options Object

options for mirror

Properties
Name Type Attributes Default Description
origin Array <optional>
[0,0,0]

the origin of the plane

normal Array <optional>
[0,0,1]

the normal vector of the plane

geometries Object <repeatable>

the geometries to mirror

Returns:

the mirrored geometry, or a list of mirrored geometry

Type
Object | Array

(static) mirrorX(…geometries) → {Object|Array}

Source:

Mirror the given geometries about the X axis.

Parameters:
Name Type Attributes Description
geometries Object <repeatable>

the geometries to mirror

Returns:

the mirrored geometry, or a list of mirrored geometry

Type
Object | Array

(static) mirrorY(…geometries) → {Object|Array}

Source:

Mirror the given geometries about the Y axis.

Parameters:
Name Type Attributes Description
geometries Object <repeatable>

the geometries to mirror

Returns:

the mirrored geometry, or a list of mirrored geometry

Type
Object | Array

(static) mirrorZ(…objects) → {Object|Array}

Source:

Mirror the given object(s) about the Z axis.

Parameters:
Name Type Attributes Description
objects Object <repeatable>

the geometries to mirror

Returns:

the mirrored geometry, or a list of mirrored geometry

Type
Object | Array

(static) rotate(angles, …geometries) → {Object|Array}

Source:

Rotate the given geometries using the given options.

Example
const newsphere = rotate([Math.PI / 4, 0, 0], sphere())
Parameters:
Name Type Attributes Description
angles Array

angle (RADIANS) of rotations about X, Y, and Z axis

geometries Object <repeatable>

the geometries to rotate

Returns:

the rotated geometry, or a list of rotated geometries

Type
Object | Array

(static) rotateX(angle, …geometries) → {Object|Array}

Source:

Rotate the given object(s) about the X axis, using the given options.

Parameters:
Name Type Attributes Description
angle Number

angle (RADIANS) of rotations about X

geometries Object <repeatable>

the geometries to rotate

Returns:

the rotated geometry, or a list of rotated geometries

Type
Object | Array

(static) rotateY(angle, …geometries) → {Object|Array}

Source:

Rotate the given object(s) about the Y axis, using the given options.

Parameters:
Name Type Attributes Description
angle Number

angle (RADIANS) of rotations about Y

geometries Object <repeatable>

the geometries to rotate

Returns:

the rotated geometry, or a list of rotated geometries

Type
Object | Array

(static) rotateZ(angle, …geometries) → {Object|Array}

Source:

Rotate the given object(s) about the Z axis, using the given options.

Parameters:
Name Type Attributes Description
angle Number

angle (RADIANS) of rotations about Z

geometries Object <repeatable>

the geometries to rotate

Returns:

the rotated geometry, or a list of rotated geometries

Type
Object | Array

(static) scale(factors, …geometries) → {Object|Array}

Source:

Scale the given geometries using the given options.

Example
let myshape = scale([5, 0, 10], sphere())
Parameters:
Name Type Attributes Description
factors Array

X, Y, Z factors by which to scale the geometries

geometries Object <repeatable>

the geometries to scale

Returns:

the scaled geometry, or a list of scaled geometries

Type
Object | Array

(static) scaleX(factor, …geometries) → {Object|Array}

Source:

Scale the given geometries about the X axis using the given options.

Parameters:
Name Type Attributes Description
factor Number

X factor by which to scale the geometries

geometries Object <repeatable>

the geometries to scale

Returns:

the scaled geometry, or a list of scaled geometries

Type
Object | Array

(static) scaleY(factor, …geometries) → {Object|Array}

Source:

Scale the given geometries about the Y axis using the given options.

Parameters:
Name Type Attributes Description
factor Number

Y factor by which to scale the geometries

geometries Object <repeatable>

the geometries to scale

Returns:

the scaled geometry, or a list of scaled geometries

Type
Object | Array

(static) scaleZ(factor, …geometries) → {Object|Array}

Source:

Scale the given geometries about the Z axis using the given options.

Parameters:
Name Type Attributes Description
factor Number

Z factor by which to scale the geometries

geometries Object <repeatable>

the geometries to scale

Returns:

the scaled geometry, or a list of scaled geometries

Type
Object | Array

(static) transform(matrix, …geometries) → {Object|Array}

Source:

Transform the given geometries using the given matrix.

Example
const newsphere = transform(mat4.rotateX(Math.PI/4), sphere())
Parameters:
Name Type Attributes Description
matrix mat4

a transformation matrix

geometries Object <repeatable>

the geometries to transform

Returns:

the transformed geometry, or a list of transformed geometries

Type
Object | Array

(static) translate(offset, …geometries) → {Object|Array}

Source:

Translate the given geometries using the given options.

Example
const newsphere = translate([5, 0, 10], sphere())
Parameters:
Name Type Attributes Description
offset Array

offset (vector) of which to translate the geometries

geometries Object <repeatable>

the geometries to translate

Returns:

the translated geometry, or a list of translated geometries

Type
Object | Array

(static) translateX(offset, …geometries) → {Object|Array}

Source:

Translate the given geometries along the X axis using the given options.

Parameters:
Name Type Attributes Description
offset Number

X offset of which to translate the geometries

geometries Object <repeatable>

the geometries to translate

Returns:

the translated geometry, or a list of translated geometries

Type
Object | Array

(static) translateY(offset, …geometries) → {Object|Array}

Source:

Translate the given geometries along the Y axis using the given options.

Parameters:
Name Type Attributes Description
offset Number

Y offset of which to translate the geometries

geometries Object <repeatable>

the geometries to translate

Returns:

the translated geometry, or a list of translated geometries

Type
Object | Array

(static) translateZ(offset, …geometries) → {Object|Array}

Source:

Translate the given geometries along the Z axis using the given options.

Parameters:
Name Type Attributes Description
offset Number

Z offset of which to translate the geometries

geometries Object <repeatable>

the geometries to translate

Returns:

the translated geometry, or a list of translated geometries

Type
Object | Array