-
Notifications
You must be signed in to change notification settings - Fork 25
box
is intended to be a complete replacement for the cube
module.
module box(size, anchor=$inward)
box
offers all the existing functionality of cube
, but unlike cube, box
will render any child module passed to it:
box(50)
sphere(d=55);
By default, child modules will render with their origins at the center of their parent module. This can be changed using standard built-in modules like transform
. box
exposes a special variable, $parent_size
, that allows translation relative to the size of the parent:
box(50)
translate([0,0,$parent_size.x/2])
sphere(d=55);
relativity.scad offers a wrapper for the translate
module, called align
. Statements such as the one above can be streamlined using align
:
box(50)
align([0,0,1])
sphere(d=55);
Here, a value of "1" indicates that sphere
is translated along the z axis by a value equivalent to $parent_size.x/2
. This aligns the origin of the sphere
with the top of the box
. This can be made more intuitive using a set of variables offered by relativity.scad:
box(50)
align(top)
sphere(d=55);
box
also streamlines its own translation. You might have found yourself writing code like this at some point:
cube_size = 10;
translate([0,0,cube_size/2])
cube(cube_size, center=true);
box
offers a parameter, anchor
, that defines where you want the origin to be relative to box
. The statement above is equivalent to the following:
box(10, anchor=[0,0,-1]);
anchor
acts as a complete replacement for the center
parameter exposed by cube
. The following statements are equivalent:
box(10, anchor=[0,0,0]);
cube(10, center=true);
box(10, anchor=[-1,-1,-1]);
cube(10, center=false);