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.

About these ads

6 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.

    See: http://www.pythonocc.org/
    and
    http://jayesh3.github.com/cadmium/

    • 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!!


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Follow

Get every new post delivered to your Inbox.

Join 44 other followers