| Constructive Solid Geometry |
Constructive Solid Geometry (CSG) is just a fancy way of saying that a
more complex object is constructed from the object primitives we saw in the
first section. If you're accustomed to other ray-tracing packages, please
be aware that POV-Ray is not inherently a
mesh based modeler,
though it can import meshes. POV-Ray primitives are mathematical
objects. A sphere is defined as a function and not as triangles. This is
important to remember when building advanced objects.
We'll start this section by showing the various methods of combining
primitives: union, difference, and intersection.
If you were paying attention in algebra class during the lecture on Venn
diagrams, you'll recall that a union is a joining of sets. For example, we
can create a work of modern art by joining a few primitives together (
CSG Union):
The important statement here is the #declare OBJ_NAME=union
which defines the union of primitives:
#declare lego=union {
box {
<6, 0, 0>,
<0, 2, 4>
}
cylinder {
<1, 0, 1>,
<1, 2.5, 1>
.5
}
.
.
.
}
We can then use the object statement to place the newly
defined object on the screen. You can use translate and
rotate statements to move the new object around the scene.
The next CSG function is
difference. With it we can subtract one
object from another (
CSG Difference):
Something's wrong though. Notice that the ends of the boxes are closed.
This is an example of a coincident surface. POV-Ray cannot determine
whether the ends are to be subtracted or not. This defect may depend on the
floating point hardware of your rendering machine and may or may not be
evident. To get around it we can make the removed surface slightly larger
than before so POV-Ray can render with impunity (CSG
Difference - Modified):