Introducing Solids of Revolution

If you're a beginner and want to create complex 3D objects in Processing then you may be wondering if there's an easy way to do it. After all, constructing 3D objects requires you to specify maybe hundreds of vertices and triangles. Alternatively, you might prefer to create them in a 3D editor such as Blender, and import the files into your processing project. The first option is very time consuming and prone to error, and using an editor means you will have less control of the object in your 3D scene. However, there is a relatively easy way to add some quite complex objects to your Processing 3D scenes, which relies on the fact that many things in real life are solids of revolution (SolRev's).

If you're wondering what a SolRev is, think of a craftsperson turning wood on a lathe: when the turned item is finished it will have a circular cross section everywhere along it's length. By defining the distance along an object, and the radius of the cross section, we can do something similar in Processing. As ours are virtual objects we can also go one better by defining the number of increments we will use around the radius for our triangles. That means we can create SolRev's with all sorts of symmetrical cross sections, from a triangle, through square and hexagonal, and with enough points even close to a circle. Try doing that on a lathe!

To demonstrate SolRev's in Processing, below is a simple applet that draws a wine bottle and glass, complete with some contents. They can be rotated using the left and right arrow keys on your keyboard, and the up and down arrows let you zoom in and out. To toggle between a rendered and wireframe viewing mode, simply press the 'w' button.

This browser does not have a Java Plug-in.
Get the latest Java Plug-in here.

So, how does the applet create the 3D objects, you may ask? Well, because the cross section is uniform along its length, all we have to do is specify the cross section in Processing, as an array, and use a SolRev function to rotate it to create triangles all around the outside. In Figure 1 below you can see the cross sections for the wine bottle and glass. As you can see, the cross section can be quite complex as we are defining the inside and outside in one section. Here the sections are drawn with a height of one, to make scaling easier, but the coordinates can really be any size required.

Cross sections for the bottle and glass SolRevs.

Figure 1. A bottle and glass cross section for use in creating a SolRev.

Calculating the vertices is quite easy using the equation of a circle, and having done that the SolRev function just has to draw a mesh of triangles using those vertices. Don't forget that you can see the triangles by pressing 'w' to toggle wireframe mode. So, with such a function, creating a complex 3D object is as simple as drawing a 2D cross section. In future pages the SolRev function will be introduced together with some simple examples of how to use it to easily create some fun 3D scenes.