Posted on by & filed under hardware, programming.

In the United States, we are just entering the holiday season, so I’m going to tell you a story about me being unbearably geeky. I’m doing this as a service so that you can interact with the geeks in your life and to share what I’ve learned about some technologies that let you design and print gifts and ornaments. Unless the geekiness in this post makes perfect sense to you, in which case I’m doing this in order to let you know you can use code to create physical objects, which is interesting in its own right.

Recently I got it into my head to completely redesign the standard set of polyhedral dice by making them out of planes. For example, the familiar 20-sided icosahedron has all of its corners fully defined by three golden rectangles at right angles to each other. (If you are furrowing your brow right now, a search on golden rectangle icosahedron will make things clearer.) So I spent some time doodling images until I had some designs I liked (although I’m not a designer). The next problem was figuring out how I could turn my graph-paper isometric doodles into a physical object. I’m not at all comfortable in the various modeling programs that seem to be popular for creating 3d-printed objects but I really wanted something that I could hold in my hands and throw in the air (hoping for a 20 on landing every time).

Various pencil-on-graph-paper doodles of  polyhedral dice.

Some isometric doodles.

I wanted a 3d version of PostScript or SVG that could produce printable files, and OpenSCAD is pretty close. It’s a program and a programming language and it can export to a variety of formats used by 3d printers. There are a lot of tutorials out there if you want an in-depth introduction, so I’m just going to provide some bare basics.

OpenSCAD works, like most programming languages, by using operations on low-level data structures and organizing those operations into more complex logical systems. In OpenSCAD, the low-level structures include 2d shapes (circle, square, and polygon) and 3d shapes (sphere, cube, cylinder, and polyhedron). These are defined pretty loosely so that, for example, the parameters of square() can produce rectangles and the parameters of cylinder() can produce cones. The operations include transformations like translate, rotate, and scale and boolean operations like union and difference. Just as you’d expect, there are variables, functions, and flow control (for loops and if statements).

So, for example, I can define a set of points to draw a number:

four = [

and pass that set of points to a polygon constructor, which I then convert into a 3d object by extruding it.

linear_extrude(height=5, center=false){

Combine enough simple objects like this together, keeping your code structure sane so you’re encapsulating repeated operations in a useful way, and you can end up with something like this:

A screenshot of OpenSCAD displaying a 20-sided die composed of three planes.

Be aware that you are probably not going to be printing in color unless you want to produce multiple pieces and assemble them.

Now that you have something you like, how do you 3d print it? I used the printing service at Shapeways, although there are other services available. The first thing to think about is scale. OpenSCAD exports to STL, which does not define a unit size. Shapeways allows you to specify that your units are millimeters, inches, or meters. You may need to wrap your entire model in a scale transformation to get it to be the right size. Once you have that, export your model as an STL file. You may get error messages about the validity of your file, in which case the relevant section of the OpenSCAD documentation may be helpful. Then you can upload your file and have it printed and shipped. The model that appears above looks like this in plastic:

20-sided die composed of three planes

This is what I specified, though more design iteration is needed.

If I have gotten nothing else across, I hope I’ve let you know that it’s possible to model 3d objects and get them printed even if you don’t have any sort of design background. You can review the OpenSCAD code I used to print my die here:


Comments are closed.