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, …objects) → {Object|Array}

Source:

Center the given objects 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 objects

objects Object <repeatable>

the objects to center

Returns:

the centered object, or a list of centered objects

Type
Object | Array

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

Source:

Center the given objects about the X axis.

Parameters:
Name Type Attributes Description
objects Object <repeatable>

the objects to center

Returns:

the centered object, or a list of centered objects

Type
Object | Array

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

Source:

Center the given objects about the Y axis.

Parameters:
Name Type Attributes Description
objects Object <repeatable>

the objects to center

Returns:

the centered object, or a list of centered objects

Type
Object | Array

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

Source:

Center the given objects about the Z axis.

Parameters:
Name Type Attributes Description
objects Object <repeatable>

the objects to center

Returns:

the centered object, or a list of centered objects

Type
Object | Array

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

Source:

Mirror the given objects 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

objects Object <repeatable>

the objects to mirror

Returns:

the mirrored object, or a list of mirrored objects

Type
Object | Array

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

Source:

Mirror the given objects about the X axis.

Parameters:
Name Type Attributes Description
objects Object <repeatable>

the objects to mirror

Returns:

the mirrored object, or a list of mirrored objects

Type
Object | Array

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

Source:

Mirror the given objects about the Y axis.

Parameters:
Name Type Attributes Description
objects Object <repeatable>

the geometries to mirror

Returns:

the mirrored object, or a list of mirrored objects

Type
Object | Array

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

Source:

Mirror the given objects about the Z axis.

Parameters:
Name Type Attributes Description
objects Object <repeatable>

the geometries to mirror

Returns:

the mirrored object, or a list of mirrored objects

Type
Object | Array

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

Source:

Rotate the given objects using the given options.

Example
const newsphere = rotate([TAU / 8, 0, 0], sphere())
Parameters:
Name Type Attributes Description
angles Array

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

objects Object <repeatable>

the objects to rotate

Returns:

the rotated object, or a list of rotated objects

Type
Object | Array

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

Source:

Rotate the given objects about the X axis, using the given options.

Parameters:
Name Type Attributes Description
angle Number

angle (RADIANS) of rotations about X

objects Object <repeatable>

the objects to rotate

Returns:

the rotated object, or a list of rotated objects

Type
Object | Array

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

Source:

Rotate the given objects about the Y axis, using the given options.

Parameters:
Name Type Attributes Description
angle Number

angle (RADIANS) of rotations about Y

objects Object <repeatable>

the objects to rotate

Returns:

the rotated object, or a list of rotated objects

Type
Object | Array

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

Source:

Rotate the given objects about the Z axis, using the given options.

Parameters:
Name Type Attributes Description
angle Number

angle (RADIANS) of rotations about Z

objects Object <repeatable>

the objects to rotate

Returns:

the rotated object, or a list of rotated objects

Type
Object | Array

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

Source:

Scale the given objects 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 objects

objects Object <repeatable>

the objects to scale

Returns:

the scaled object, or a list of scaled objects

Type
Object | Array

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

Source:

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

Parameters:
Name Type Attributes Description
factor Number

X factor by which to scale the objects

objects Object <repeatable>

the objects to scale

Returns:

the scaled object, or a list of scaled objects

Type
Object | Array

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

Source:

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

Parameters:
Name Type Attributes Description
factor Number

Y factor by which to scale the objects

objects Object <repeatable>

the objects to scale

Returns:

the scaled object, or a list of scaled objects

Type
Object | Array

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

Source:

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

Parameters:
Name Type Attributes Description
factor Number

Z factor by which to scale the objects

objects Object <repeatable>

the objects to scale

Returns:

the scaled object, or a list of scaled objects

Type
Object | Array

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

Source:

Transform the given objects using the given matrix.

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

a transformation matrix

objects Object <repeatable>

the objects to transform

Returns:

the transformed object, or a list of transformed objects

Type
Object | Array

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

Source:

Translate the given objects 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 objects

objects Object <repeatable>

the objects to translate

Returns:

the translated object, or a list of translated objects

Type
Object | Array

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

Source:

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

Parameters:
Name Type Attributes Description
offset Number

X offset of which to translate the objects

objects Object <repeatable>

the objects to translate

Returns:

the translated object, or a list of translated objects

Type
Object | Array

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

Source:

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

Parameters:
Name Type Attributes Description
offset Number

Y offset of which to translate the geometries

objects Object <repeatable>

the objects to translate

Returns:

the translated object, or a list of translated objects

Type
Object | Array

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

Source:

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

Parameters:
Name Type Attributes Description
offset Number

Z offset of which to translate the geometries

objects Object <repeatable>

the objects to translate

Returns:

the translated object, or a list of translated objects

Type
Object | Array