Revolutionary Surfaces with OpenScadPosted: July 1, 2011
I have spent quite a lot of time with OpenScad, adding functions and whatnot. One of the lines of improvements that I’ve been pursuing has been surfaces in general, and more recently surfaces of revolution.
Having remembered some basic high school math, I was looking to generalize the idea of surfaces of revolution, so I started down the path of using cubic curves to describe surfaces of revolution. This was an interesting path to pursue because along the way I wanted to also simplify the Bezier calculations that I was using. As it turns out, you can specify cubic curves (which represents a broad set of curves) utilizing a simple matrix representation. Through consultation with my various old graphics books, I was able to come up with the generalized routines to represent cubic curves. As a result, the surface of revolution based on cubic curves can represent any cubic curve.
I encapsulated the latest of this work into the revoloids library.
In the latest incarnation of the library, I added the ability to specify a starting and ending angle for the surface. This is nice because although you could generate the whole surface, and then slice off a bit using CSG, sometimes you actually know exactly what you want, and using CSG operations is just a waste of time.
The general mechanism I am using to render these ‘solids’ is to construct a giant piecewise polyhedron one quad at a time. The benefit of this method is that it can be used to represent any type of 3D object, on the fly. The downside, with respect to OpenScad, is that these objects do not play well with other objects from a CSG perspective. Rather than seeing a piecewise polyhedron, what OpenScad really wants is a single object, with all the vertices specified, and then the faces specified from that single vertex set. The real challenge here is that OpenScad does not have any mechanism whereby you can specify a whole bunch of vertices on the fly. You have to construct them up front, or generate a file.
This is a generic technique I want to pursue. Basically, construct a series of simple executables which can be chained together, with OpenScript as the final outcome. This is what happens with the font importer utility, as well as the polygon generation flash tool.
Through this experience I have contemplated a couple of things:
OpenScad is a few things. A domain specific language, a wrapper of other libraries.
The actual CSG work is done in CGAL.
As much as I like the OpenScad language for ease, I prefer to have a stronger language
OpenScad can have an ‘extensions’ model whereby modules that are quite useful are created and disseminated. Right now this happens with the ‘library’ directory, but there’s not much there.
Besides that, the other thought is, implementing these routines directly in the 3D printer. There’s really no reason in the world why the printer (given sufficient processing power) could not take a .scad file description, and render directly from there. That’s another line to pursue.
At any rate, for now, these surfaces of revolution are ‘feature complete’. I will fold these routines into the Renderer and move on to the next set of routines, which have to do with surface intersections.