Programmable CAD
Every few years I decide to have a go at using a CAD package for the creation of 3D diagrams and shapes, and every time I give it up. There's simply too much to learn in terms of creating shapes, moving them about, and so on, and every system seems to have its own ways of doing things. My son (who is an expert in Blender) recommended that I experiment with Tinkercad, and indeed this is probably a pretty easy way of getting started with 3D CAD. But it didn't suit me: I wanted to place things precisely in relation to each other, and fiddling with dragging and dropping with the mouse was harder and more inconvenient than it should have been. No doubt there are ways of getting exact line ups, but it isn't obvious to the raw beginner.
I then discovered that there are lots of different CAD "programming languages"; or more properly scripting languages, where the user describes how the figure is to be built in the system's language. Then the system builds it from the script. In this sense these systems are descendants of the venerable VRML, of which you can see some examples here, and its modern version X3D.
Some of the systems that I looked at were:
- OpenSCAD, which uses its own scripting language
- OpenJSCAD, based on JavaScript
- implicitCAD, based on Haskell,
No doubt there are others. All of these systems have primitive shapes (spheres, cubes, cylinders etc), operations on shapes (shifting, stretching, rotating, extruding etc) so a vast array of different forms can be generated. Some systems allow for a great deal of flexibility, so that a cylinder with a radius of zero at one end will be a cone, or of different radii at each end a frustum.
I ended up choosing OpenJSCAD, which is being actively developed, is based on a well known and robust language, and is also great fun to use. Here is a simple example, to construct a tetrahedron whose vertices are chosen from the vertices of a cube with vertices . The vertices whose product is 1 will be the vertices of a tetrahedron. We can make a nice tetrahedral shape by putting a small sphere at each vertex, and joining each sphere by a cylinder of the same radius:
The code should be fairly self-explanatory. And here is the tetrahedron:
I won't put these models in this post, as one of them is slow to render: but look at a coloured tetrahedron, and an icosahedron.
Note that CAD design of this sort is not so much for animated media so much as precise designs for 3D printing. But I like it for exploring 3D geometry.