POV-Ray: A Tool for Creating Engaging Visualisation of Geometry

Written by Paul Bourke
January 2004


Abstract

Computers are now a standard tool for creating, exploring, and presenting geometric form and mathematics. Finding the right software tools can be difficult, especially so when high quality and visually appealing images are required. This paper will discuss one particular package (POV-Ray) used with great success by the author. A general discussion of the desirable features will be presented along with examples based around the familiar tetrahedral form.

Introduction

The mathematician and geometer often needs to represent equations or geometry visually, both for their own insight (visualisation) and as a way of conveying information to a wider audience. There are a number of software packages that have been designed to meet this need but most concentrate on the former goal and as such may be able to create informative images for the expert but tend to be limited in their ability to create higher quality images that may be more informative and attractive to a general audience.

There are a number of consideration when choosing software for any task and there are some others that are relevant to the presentation of geometry.

  • There needs to be a very wide range of ways in which geometry can be described, it goes beyond the standard geometric building blocks such as planes, spheres, and cylinders. It includes higher level descriptions such as isosurfaces, parametric equations, and solid constructive geometry. The software should have a versatile programming, scripting, or macro language that can be employed to construct more complicated forms from the simpler building blocks. The ability to supplement this further with algorithms implemented externally in programming languages such as C/C++ can also greatly extend the possibilities.

  • For presenting engaging images of geometric forms it is necessary to be able to do more than just render as wireframe and flat shading. There needs to be a realistic model of the surface properties and simulation of how light interacts with the geometry. Subtle shading, transparency, and shadows all assist in the visualisation and appreciation of complex geometry.

  • The cost of any application can be a serious consideration to many users especially those not associated with a company or educational institution. There are clear advantages if the software is free, perhaps developed under the GNU license arrangement.

  • In order to facilitate collaboration and the sharing of models and expertise, a particular software package needs to be available for the three most widely used operating systems, namely Linux, Macintosh, and MicroSoft Windows. It is important for the software (given a particular version number) to be functionally identical across all platforms and for no platform to lag behind in version releases.

The software package to be discussed here, POV-Ray, goes some way to meeting all the above. It is free and runs identically on all major operating systems and computer platforms. It has a very powerful language for describing geometry which includes a programming language and it is straightforward to create geometric descriptions with external software. The method by which it renders the geometry is based upon a technique called ray tracing, as such it is capable of very high quality imagery with a high degree of realism.

Ray Tracing

Rendering software such a POV-Ray creates an image using a technique known as a ray tracing which broadly means it takes a description of geometry (which includes surface materials and light sources), a model of a virtual camera, and a projection plane made up of the pixels in the final image. It then creates what the camera would "see" by shooting rays from the camera through each pixel and analyzing how they are affected by the geometry, materials, and lights.

An interesting consequence of the ray tracing technique is that traditional computer graphic primitives such as ideal points and lines cannot be represented, indeed in most cases a ray tracer does not even have those as geometric building blocks. The reason is that a ray will never strike a point or a line (they have no thickness) and could therefore never be made visible, in a similar way that a true line could not be seen by ourselves because it would not reflect any light. A ray tracer generally has a polygon primitive (bounded region of a plane that is infinitely thin) however it would suffer the same fate if viewed exactly edge on.

Examples

This section will illustrate the capabilities of POV-Ray to create geometry with some concrete examples. In each case the core geometric description will be given along with the resulting image. Please note that this is not intended to be a tutorial on POV-Ray or the scripting language but more to give a sense of the elegance and power of the description. For tutorials, documentation, and reference material the POV-Ray web site (http://www.povray.org/) should be consulted.

1. Simple geometric building blocks

The lack of line and point primitives with which to build a computer based model may seem rather restrictive. As it turns out the model is created much like it would be in real life, namely with materials of finite thickness such as wire, straws, balsa wood, and balls of putty. The computer versions of these are spheres and cylinders, they both have an associated radius. For the first example, see figure 1, the geometry description that created this tetrahedron is made up of 4 vertices (copper spheres), 6 edges (silver cylinders), and 4 faces (blue, transparent glass). One of each of these appears in the geometry file as follows.

sphere { <1,1,1>, sphereradius texture { copper } }
cylinder { <-1,-1,1>, <-1,1,-1>, cylinderradius texture { silver } }
triangle { <1,1,1>, <-1,1,-1>, <1,-1,-1> texture { blueglass } }

Note that the exact formatting is not important and that names such as "sphereradius", "copper" are not shown but would be defined earlier in the scene file. The full POV-Ray scene files that were used to create the images here are provided at the end of this document.


Figure 1. Tetrahedron constructed using cylinders, spheres, and semi transparent and reflective glass

2. Parametric surfaces

A more interesting geometric primitive is a parametric surface, to illustrate this consider the following code which describes the "Steiner Look-a-Like" surface and generates the image in figure 2.

parametric {
   function { cos(2*pi*u - pi/2)*cos(2*pi*(-u+v)+pi/2) }
   function { cos(2*pi*v - pi/2)*cos(2*pi*(-u+v)+pi/2) }
   function { cos(2*pi*v - pi/2)*cos(2*pi*u-pi/2) }
   <0,0>, <0.5,1>
   contained_by { sphere { <0,0,0>, 2.5 } }
   accuracy 0.001
   max_gradient 10
   texture { brass }
}

Most of the meaning can be guessed at, the first three lines are the equations in (u,v) for each coordinate axis, the fourth line specifies the (u,v) range, the subsequent lines relate to how the internal algorithm functions. The example here is a Steiner Look-A-Like (Roger Bagula) surface defined by three parametric equations of two variables.


Figure 2. Steiner Look-A-Like surface (Roger Bagula)

3. Isosurfaces

When an implicit equation in known then that can be explored by using the isosurface primitive. the example here is a tetrahedran Kusner-Schmitt surface.

isosurface {
   function { 
      (pow(x,2)+3) * (pow(y,2)+3) * (pow(z,2)+3) - 32*(x*y*z+1)
   }
   contained_by { { <0,0,0>, 2.5} }
   threshold 0.5
   accuracy 0.01
   max_gradient 100
   open
   texture { greenchrome  }
}


Figure 3. Kusner-Schmitt surface described an an isosurface of an implicit function

4. Solid Constructive Geometry

Solid constructive geometry (often simple called CSG) is a very powerful method for constructing forms that are the union, intersection, or difference of simpler solids. In the following example it is used to create the intersection of multiple cylinders, in much the same way in which the Steinmetz solid is the intersection of two circular cylinders at right angles to each other, we consider here the intersection volume of 4 cylinders. Each cylinder is along the line that passes through each vertex of a tetrahedron and the center of the opposite face.

intersection {
   cylinder {
      <-1,-1,-1>, <1,1,1>, 0.5
      texture { pigment { color rgb <1,0,0> } finish { plastic } }
   }
   cylinder {
      <1,-1,1>, <-1,1,-1>, 0.5
      texture { pigment { color rgb <1,1,0> } finish { plastic } }
   }
   cylinder {
      <-1,1,1>, <1,-1,-1>, 0.5
      texture { pigment { color rgb <0,0,1> } finish { plastic } }
   }
   cylinder {
      <1,1,-1>, <-1,-1,1>, 0.5
      texture { pigment { color rgb <0,1,0> } finish { plastic } }
   }
}


Figure 4a. Cylinder intersection, tetrahedral arrangement


Figure 4b. Cylinder intersection, result

5. Scripting language

The great advantage of a programming language is that geometry may be algorithmically constructed, this is illustrated in figure 5 for the 3D version of the Sierpinski gasket. A tetrahedral element is constructed and repeatedly scales and translated for as many iterations as required. This is a relatively simple example using CSG and iterative declarations, the POV-Ray language also supports loops, logical decisions, variables, etc.

#declare iteration0 = union {
   triangle { < 1,  1,  1>,  <-1,  1, -1>,  < 1, -1, -1> }
   triangle { <-1,  1, -1>,  <-1, -1,  1>,  < 1, -1, -1> }
   triangle { < 1,  1,  1>,  < 1, -1, -1>,  <-1, -1,  1> }
   triangle { < 1,  1,  1>,  <-1, -1,  1>,  <-1,  1, -1> }
   translate <1,1,1>
}

#declare finaliteration = iteration0;
#declare niterations = 6;
#while (niterations > 0)
   #declare finaliteration = union {
      object { finaliteration }
      object { finaliteration translate <-2, 0, 2> }
      object { finaliteration translate <-2, 2, 0> }
      object { finaliteration translate < 0, 2, 2> }
      translate <2,0,0>
      scale 0.5
   }
   #declare niterations = niterations - 1;
#end

union {
   object { finaliteration }
   translate <-1,-1,-1>
   texture { blueplastic }
   scale 0.95
}


Figure 5. Tetrahedral fractal (6 iterations)

Conclusion

The goal here has been to suggest that POV-Ray, a free and cross platform rendering package, has powerful features making it a useful toolkit for the mathematician and geometer. The short example code pieces should hopefully not look too scary (full code given below) and encourage the reader to download the software (www.povray.org) and experiment for his/her self.

Models

The complete POV-Ray models (Version 3.5) used to create the images in the above are given here.

common.pov
fig1.pov
fig2.pov
fig3.pov
fig4.pov
fig5.pov
tetrahedron.pov