Skip to main content

transforms

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.

Example

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

modeling/transforms.align(options, ...geometries)

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

Kind: static method of modeling/transforms
Returns: ObjectArray - the aligned geometry, or a list of aligned geometries

ParamTypeDefaultDescription
optionsObjectoptions for aligning
[options.modes]Array['center', 'center', 'min']the point on the geometries to align to for each axis. Valid options are "center", "max", "min", and "none".
[options.relativeTo]Array[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.
[options.grouped]Booleanfalseif true, transform all geometries by the same amount, maintaining the relative positions to each other.
...geometriesObjectthe geometries to align

Example

let alignedGeometries = align({modes: ['min', 'center', 'none'], relativeTo: [10, null, 10], grouped: true }, geometries)

modeling/transforms.center(options, ...objects)

Center the given objects using the given options.

Kind: static method of modeling/transforms
Returns: ObjectArray - the centered object, or a list of centered objects

ParamTypeDefaultDescription
optionsObjectoptions for centering
[options.axes]Array[true,true,true]axis of which to center, true or false
[options.relativeTo]Array[0,0,0]relative point of which to center the objects
...objectsObjectthe objects to center

Example

let myshape = center({axes: [true,false,false]}, sphere()) // center about the X axis

modeling/transforms.centerX(...objects)

Center the given objects about the X axis.

Kind: static method of modeling/transforms
Returns: ObjectArray - the centered object, or a list of centered objects

ParamTypeDescription
...objectsObjectthe objects to center

modeling/transforms.centerY(...objects)

Center the given objects about the Y axis.

Kind: static method of modeling/transforms
Returns: ObjectArray - the centered object, or a list of centered objects

ParamTypeDescription
...objectsObjectthe objects to center

modeling/transforms.centerZ(...objects)

Center the given objects about the Z axis.

Kind: static method of modeling/transforms
Returns: ObjectArray - the centered object, or a list of centered objects

ParamTypeDescription
...objectsObjectthe objects to center

modeling/transforms.mirror(options, ...objects)

Mirror the given objects using the given options.

Kind: static method of modeling/transforms
Returns: ObjectArray - the mirrored object, or a list of mirrored objects

ParamTypeDefaultDescription
optionsObjectoptions for mirror
[options.origin]Array[0,0,0]the origin of the plane
[options.normal]Array[0,0,1]the normal vector of the plane
...objectsObjectthe objects to mirror

Example

let myshape = mirror({normal: [0,0,10]}, cube({center: [0,0,15], radius: [20, 25, 5]}))

modeling/transforms.mirrorX(...objects)

Mirror the given objects about the X axis.

Kind: static method of modeling/transforms
Returns: ObjectArray - the mirrored object, or a list of mirrored objects

ParamTypeDescription
...objectsObjectthe objects to mirror

modeling/transforms.mirrorY(...objects)

Mirror the given objects about the Y axis.

Kind: static method of modeling/transforms
Returns: ObjectArray - the mirrored object, or a list of mirrored objects

ParamTypeDescription
...objectsObjectthe geometries to mirror

modeling/transforms.mirrorZ(...objects)

Mirror the given objects about the Z axis.

Kind: static method of modeling/transforms
Returns: ObjectArray - the mirrored object, or a list of mirrored objects

ParamTypeDescription
...objectsObjectthe geometries to mirror

modeling/transforms.rotate(angles, ...objects)

Rotate the given objects using the given options.

Kind: static method of modeling/transforms
Returns: ObjectArray - the rotated object, or a list of rotated objects

ParamTypeDescription
anglesArrayangle (RADIANS) of rotations about X, Y, and Z axis
...objectsObjectthe objects to rotate

Example

const newsphere = rotate([TAU / 8, 0, 0], sphere())

modeling/transforms.rotateX(angle, ...objects)

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

Kind: static method of modeling/transforms
Returns: ObjectArray - the rotated object, or a list of rotated objects

ParamTypeDescription
angleNumberangle (RADIANS) of rotations about X
...objectsObjectthe objects to rotate

modeling/transforms.rotateY(angle, ...objects)

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

Kind: static method of modeling/transforms
Returns: ObjectArray - the rotated object, or a list of rotated objects

ParamTypeDescription
angleNumberangle (RADIANS) of rotations about Y
...objectsObjectthe objects to rotate

modeling/transforms.rotateZ(angle, ...objects)

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

Kind: static method of modeling/transforms
Returns: ObjectArray - the rotated object, or a list of rotated objects

ParamTypeDescription
angleNumberangle (RADIANS) of rotations about Z
...objectsObjectthe objects to rotate

modeling/transforms.scale(factors, ...objects)

Scale the given objects using the given options.

Kind: static method of modeling/transforms
Returns: ObjectArray - the scaled object, or a list of scaled objects

ParamTypeDescription
factorsArrayX, Y, Z factors by which to scale the objects
...objectsObjectthe objects to scale

Example

let myshape = scale([5, 0, 10], sphere())

modeling/transforms.scaleX(factor, ...objects)

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

Kind: static method of modeling/transforms
Returns: ObjectArray - the scaled object, or a list of scaled objects

ParamTypeDescription
factorNumberX factor by which to scale the objects
...objectsObjectthe objects to scale

modeling/transforms.scaleY(factor, ...objects)

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

Kind: static method of modeling/transforms
Returns: ObjectArray - the scaled object, or a list of scaled objects

ParamTypeDescription
factorNumberY factor by which to scale the objects
...objectsObjectthe objects to scale

modeling/transforms.scaleZ(factor, ...objects)

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

Kind: static method of modeling/transforms
Returns: ObjectArray - the scaled object, or a list of scaled objects

ParamTypeDescription
factorNumberZ factor by which to scale the objects
...objectsObjectthe objects to scale

modeling/transforms.transform(matrix, ...objects)

Transform the given objects using the given matrix.

Kind: static method of modeling/transforms
Returns: ObjectArray - the transformed object, or a list of transformed objects

ParamTypeDescription
matrixmat4a transformation matrix
...objectsObjectthe objects to transform

Example

const newsphere = transform(mat4.rotateX(TAU / 8), sphere())

modeling/transforms.translate(offset, ...objects)

Translate the given objects using the given options.

Kind: static method of modeling/transforms
Returns: ObjectArray - the translated object, or a list of translated objects

ParamTypeDescription
offsetArrayoffset (vector) of which to translate the objects
...objectsObjectthe objects to translate

Example

const newsphere = translate([5, 0, 10], sphere())

modeling/transforms.translateX(offset, ...objects)

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

Kind: static method of modeling/transforms
Returns: ObjectArray - the translated object, or a list of translated objects

ParamTypeDescription
offsetNumberX offset of which to translate the objects
...objectsObjectthe objects to translate

modeling/transforms.translateY(offset, ...objects)

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

Kind: static method of modeling/transforms
Returns: ObjectArray - the translated object, or a list of translated objects

ParamTypeDescription
offsetNumberY offset of which to translate the geometries
...objectsObjectthe objects to translate

modeling/transforms.translateZ(offset, ...objects)

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

Kind: static method of modeling/transforms
Returns: ObjectArray - the translated object, or a list of translated objects

ParamTypeDescription
offsetNumberZ offset of which to translate the geometries
...objectsObjectthe objects to translate