Skip to content
Mark Moissette edited this page Mar 31, 2013 · 11 revisions

[[TOC]]

Overview

  • Solids can be translated, rotated and scaled .

There are two syntax variations for transformations : ie either a dotted notation

shape.translate([0,10,0])
shape.rotate([45, 0, 0])
shape.scale([10,10,15])
shape.union(othershape)
shape.subtract(othershape)
shape.intersect(othershape)

or

translate([obj1,obj2])
  • you can chain transforms as well:

      shape.translate([0,10,0]).rotate([0,50,0])
    

* **important** unlike in the v0.2 version, all transform modify the object they are applied to, they do **not** return a copy of the object with the transforms applied to it.

clone

While not a transformation , it is very usefull when combined with transforms: object.clone() makes a deep copy (copies all of the attributes of the original object) of an object and returns it.

For example, let's say you want to have a cube with two cylindrical holes You can do that by writing :

cube = new Cube({size:20,center:true})
hole = new Cylinder({h:20, r:2})

cube.subtract(hole.translate([5,0,0]))
cube.subtract(hole.translate([-10,0,0]))#the hole was already translated once! so any subsequent transform gets added to the previous ones
assembly.add(cube)

or

cube = new Cube({size:20,center:true})
hole = new Cylinder({h:20, r:2})

#here we keep the original one, but translate the cloned versions
cube.subtract(hole.clone().translate([5,0,0]))
cube.subtract(hole.clone().translate([-5,0,0]))

translate

Translates (moves) the object along the specified vector (x,y,z).

shape.translate([0,10,0])

or (using the power of coffeescript)

shape.translate [0,10,0]

rotate

Rotates the object by the specified degrees about the origin of the coordinate system or around an arbitrary axis When a rotation is specified for multiple axes the the rotation is applied in the following order: x, y, z.

shape.rotate [10,10,-90]

scale

Scales the element using the specified vector

shape.scale [2,1,1]

union

Create an object which is the combination of 2 or more objects.

shape1.union(shape2)
  or
shape1.union([shape2, shape3, shape4])

subtract

Create an object which is the difference between two or more objects.

shape1.subtract(shape2)
  or
shape1.subtract([shape2, shape3, shape4])

intersect

Create an object defined by the space where 2 or more objects overlap.

shape1.intersect(shape2)
  or
shape1.intersect([shape2, shape3, shape4])

mirroring

Solids can be mirrored in any plane in 3D space

cube = new Cube()
cube1 = cube.clone().mirroredX() # cube is mirrored in the x=0 plane
cube2 = cube.clone().mirroredY() # cube is mirrored in the y=0 plane
cube3 = cube.clone().mirroredZ() # cube is mirrored in the z=0 plane

Or create a specific plane to use for mirroring plane = new Plane([1,0,1]) cube.mirrored(plane)

Group transforms

The union, subtract, and intersect transformations can also take a list of objects.

For example:
shape = shape.union([shape1, shape2, shape3])

color

Sets the color of the current element : red, green, blue, alpha (rgba) values range from 0 to 1. The alpha (transparency) defaults to 1 (fully opaque)

shape.color([1,0,0,1]) # now "shape" is a nice red

Clone this wiki locally