Revolutionary Surfaces with OpenScad

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.

Starting from the work I started with Bezier surfaces, I had first constructed basic surfaces of revolution based on simple functions, and thus began the revoloids campaign.

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 isn’t really a limitation though, it just shows the boundary of what you can do from within the context of the OpenScad editor.  Since my math routines are fairly generic, and don’t really rely on anything within OpenScad, it will be a fairly straightforward exercise to rewrite them in ‘C’, or even javascript.  By doing such, I could simply generate the correct polyhedron, and then export it as OpenScad.

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.

But, these are just random thoughts.  What I’m really contemplating, and currently pursuing, is implementing my routines in JavaScript, and operating in the browser, or another host.  If in the browser, then it would be WebGL.  This seems to be a quite reasonable way to go.  WebGL and HTML 5 seem to be all the rage these days.  That would give any application the ultimate reach, without having to worry about libraries such as Qt.  The biggest challenge is dealing with the CSG routines that are implemented in CGAL.  If that can be cracked, then it becomes a relative no-brainer to create an OpenScad like experience in HTML.

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.

11 Comments on “Revolutionary Surfaces with OpenScad”

  1. Adam K says:

    You might also consider checking out pythonOCC and cadmium, if you’re not averse to using python.


    • I had considered pythonOCC, and cadmium. that looks like a promising route as well. The primary choice I made was a language choice, choosing Lua over Python. I had looked at the comparisons of eLua to pyMite, and Lua seems to be a better fit for small microcontrollers, which is one of my primary environments.

      My code is fairly simple though, and really it only uses the most basic features of the languages (I am porting from OpenScad after all).

  2. Yura V says:

    Sorry but how to curve a cone with this method? Rotate along arbitrary curve? I need to construct 3d model of saxophone neck and bell for 3d printing but still looking for good method of curving cones(saxophone is exactly the cone) Currently I use many rings with step rotating…

    • If you are going to construct a saxophone, you will probably do it in multiple sections. For example, the bell for the opening itself can be one construct. The main body might be another, and the neck might take another one or two sections.

      If the surface is not symmytrical, then you won’t want to rotate all the way around, you’ll want to do partials, possibly with differing radii or axis of rotation, and then stitch them together.

      An even better way of modeling it would probably be to sweep a circle along a path, and allow the radius to vary over the length of the sweep. That sounds like what you’re doing essentially. There’s not an easy function within this library to do it that way, but you could probably put together such a thing fairly easily.

      • Yura V says:

        Yes I made neck (very many short cones) and horn and have made bow.
        But the problem occures when I start to make holes with rim in bow. I pass cylinder through the wall of bow but the problem is I cannot remove internal rims in bow. To do it I need to diff bow with only bow internal surface. Openscad stops working correctly this way. So it is critical what primitive to use in “for” cycle…

  3. Yubal says:

    You’re all awesome… I’m loving OpenScad more and more by the second!!

  4. Frazatto says:

    Mr. Adams, is there a way to make them solid?

    The following code does nothing:

    difference ()
    cylinder (h = 10, d = ring_d + 2, center = true);
    translate ([ring_inner_d/2, 0, 0]) { rotate ([90, 0, 0]) { sor_torus (ring_inner_d/2, [ring_d/2, ring_d/2]); }}
    • Super late reply to a comment, but…
      I haven’t checked out this interaction in a number of years. I don’t know how OpenScad has progressed with regard to being able to deal with my creations here. Perhaps mine are not ‘solid’ enough for OpenScad to deal with.

      I might revisit in the near future just to check it out. You might export one of my revoloids, and use some tool to ensure it’s solid, then reimport as a .stl and see if that makes a difference.

      • Frazatto says:

        Yes, my first thought was to make a stl torus and use it, but the result was the same.
        Yours is a very complete and general library, but after some more research, I found that the way suggested in the OpenSCAD Wiki is much simpler, if you just want a simple torus.

        rotate_extrude(convexity = 10, $fn = 100)
        translate([2, 0, 0])
        circle(r = 1, $fn = 100);

      • Yes, that will work to make a simple torus from a circle. I believe when I made this original code, you could vary the major and minor axes, to make a toroid with different shape.

        Ultimately, the revoloids allow you to use any closed curve and then sweep that around in a circle, and come up with more interesting shapes. You can also do bump mapping, texture mapping, and the like. At the time, that seemed interesting.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 57 other followers