meta data for this page
This is an old revision of the document!
Shape Transformations
The 'transforms' are accessed through the modeling API using the following:
const { translate, scale, rotateX } = require('@jscad/modeling').transforms
The 'transforms' return a single shape or an array of shapes depending on the given shapes.
const newshape = align({modes: ['none', 'center', 'none']}, oldshape) /* Returns a single shape */ const newshapes = align({modes: ['min', 'center', 'none'], alignTo: [10, null, 10], grouped: true }, oldshape, [oldshape0, oldshape1]) /* Returns an array of new shapes*/
| Transform | Notes |
|---|---|
| const newshape = align({modes: ['min', 'center', 'none'], alignTo: [10, null, 10], grouped: true}, oldshape) | See API documentation |
| const newshape = center({axes: [true, true, false], center: [15, 10, 0]}, oldshape) | See API documentation |
| const newshape = centerX(oldshape) | See API |
| const newshape = centerY(oldshape) | See API |
| const newshape = centerZ(oldshape) | See API |
| const newshape = mirror({origin: [5, 5, 5], normal: [0, 0, 10]}, oldshape)) | See API |
| const newshape = mirrorX(oldshape) | See API |
| const newshape = mirrorY(oldshape) | See API |
| const newshape = mirrorZ(oldshape) | See API |
| 2D Transformations | 3D Transformations |
|---|---|
| 2Dshape = 2Dshape.translate([-2, -2]); | 3Dshape = 3Dshape.translate([1,2,3]); |
| 2Dshape = 2Dshape.rotateZ(20); | 3Dshape = 3Dshape.rotateX(90); |
| 3Dshape = 3Dshape.rotateY(-180); | |
| 3Dshape = 3Dshape.rotateZ(45); | |
| 2Dshape = 2Dshape.rotate(center, axis, degrees); | 3Dshape = 3Dshape.rotate(center, axis, degrees); |
| 2Dshape = 2Dshape.rotateEulerAngles(alpha, beta, gamma, position); | 3Dshape = 3Dshape.rotateEulerAngles(alpha, beta, gamma, position); |
| 2Dshape = 2Dshape.scale([0.7, 0.9]); | 3Dshape = 3Dshape.scale([1,2,3]); |
| 2Dshape = 2Dshape.center([true,true]); /* center X & Y axis */ | 3Dshape = 3Dshape.center([true,true,true]); /* center X & Y & Z axis */ |
| 2Dshape = 2Dshape.mirroredX(); | 3Dshape = 3Dshape.mirroredX(); |
| 2Dshape = 2Dshape.mirroredY(); | 3Dshape = 3Dshape.mirroredY(); |
| 3Dshape = 3Dshape.mirroredZ(); | |
| 2Dshape = 2Dshape.mirrored(plane); | 3Dshape = 3Dshape.mirrored(plane); |
| 2Dshape = 2Dshape.transform(matrix); | 3Dshape = 3Dshape.transform(matrix); |
| /* not supported yet */ | 3Dshape = 3Dshape.setColor(r,g,b); /* a = 1.0 */ |
| 3Dshape = 3Dshape.setColor(r,g,b,a); | |
| 3Dshape = 3Dshape.setColor([r,g,b]); /* a = 1.0 */ | |
| 3Dshape = 3Dshape.setColor([r,g,b,a]); | |
| 2Dshape = 2Dshape.expand(0.2, 8); /* radius, resolution */ | 3Dshape = 3Dshape.expand(0.2, 8); /* radius, resolution */ |
| 2Dshape = 2Dshape.contract(0.2, 8); /* radius, resolution */ | 3Dshape = 3Dshape.contract(0.2, 8); /* radius, resolution */ |
Note: Shape transformations can be chained together. Example:
var 3Dshape = CSG.cube().rotate(45).translate([20,0,10]).setColor(1,0.5,0.3);