A friend's Christmas present to himself (and indirectly his family and friends) was a MakerBot Replicator 3-D printer. Down at Bristol Hackspace we have several repraps in various stages of completion, but none yet ready for novice use. Marc's printer seems to have worked out of the box, so I was able to get my first test piece send via Dropbox to London, printed appropriately enough, since it involved hearts, in a pretty pink plastic and posted to Bristol in a couple of days.
The key to my personal progress was the discovery of OpenSCAD. I've looked at using GUI-based 3-D tools like Blender but OpenSCAD is a programming environment, just my kind of 3-D tool. I soon found a weath of freely avaliable tutorials, reference material and scripts:
OpenSCAD uses two modes of construction: Constructive Solid Geometry (CSG) using the Computational Geometry Algorithms Library (CGAL); and extrusion(two modes) of a 2-D shape.
Some lessons learnt:
The challenge for the budding designer is to learn how to compose a desired shape by the application of the operators to the primitives. In the physical world, we typically construct objects in a 'carpentry' mode, glueing non-intersectiing objects (union) and removing waste (difference). Also our range of primitives is vast and I generally have no idea how, say, a nut is formed. CSG allows us to union() overlapping objects, get the intersection of objects and use the less-known operators minkowski sum and hull. To see what experienced openSCAD programmers use, I analysed the collection of 22 library files for basic shapes, gears and threads etc. There were a total of 10000 lines including comments. I used grep to do the counting of patterns such as 'rotate\s*(' to get counts of each construct in the language.
translate | 1088 |
rotate | 625 |
scale | 576 |
mirror | 3 |
multmatrix | 0 |
union | 576 | Severe underestimate since union() is the default for a sequence of objects |
difference | 36 | |
linear_extrude | 18 | |
intersection | 9 | |
intersection_for | 2 | replacement for loop within intersection which doesnt work |
rotate_extrude | 2 | |
projection | 1 | |
minkowski | 0 | |
hull | 0 |
polygon | 19 |
circle | 10 |
square | 5 |
cylinder | 1029 |
cube | 52 |
polyhedra | 45 |
sphere | 15 |
surface | 0 |
function | 144 | |
module | 111 | |
assign | 43 | |
if | 41 | |
for | 38 | |
echo | 20 | |
include | 4 | |
use | 2 | |
search | 0 | |
str | 0 |
concatenate |
Exploring Intersection
This data seems to indicate that designers are mainly using operators which correspond to the physical operations (carpentry mode) and are generally not using the advanced operators. This is not surprising because even intersection can yield surprising results. An example in the wikibook shows the construction of a dodecahedron from the intersection of 6 boxes:
but I havent been able to trace the source of this construction. It's tempting to look for ways of constructing the other regular solids using intersection and indeed playing with this code, I found I could make an octahedron:
Animation
What other solids could I make this way? One feature of OpenSCAD is very useful here - the ability to display a parameterized sequence of objects as an animation. The system variable $t changes from 0 to 1 in increments determined by the total number frames entered in the animation panel, so to see what solids are generated as the dihedral angle is changed :
and its fun to watch the shapes morph, becoming dodecahedrons at several angles and curious asymmetric faceted shapes in between. Moreover you can edit the script as it runs to change other parameters such as the number of intersecting boxes. You can also create a video. Each frame is saved as a .png file. I used ffmpeg installed on Ubuntu:
> ffmpeg -f image2 -i frame%05d.png -r 12 dodec.avi
to create this little video