Constructing objects

POV-Ray gives you several simple objects that you can place in your scene. If you want more complex objects there are several ways of getting them. One of these ways is using constructive solid geometry, or CSG. With CSG you take simple objects and combine them into more complex objects. You can merge objects, unite them, cut them, and intersect them.

Once you’ve created a CSG object, CSG objects are themselves able to be used in merges, unions, differences, and intersections.

Let’s add a ring to our sphere. There is no such thing as a flat ring in POV-Ray (it does have a torus, but that’s a kind of donut shape). But it does have a cylinder. Below the sphere, add a cylinder object.

//ring around the sphere

cylinder {

<0, -.01, 0>, <0, .01, 0>, 3.2

pigment {

color Green

}

}

Cylinders are defined by their starting location, their ending location, and their radius. This cylinder starts at -.01 meters below the origin, ends at .01 meters above the origin, and is 3.2 meters in radius. It’s really more of a disc than a cylinder.

You should end up with a blue sphere with a green puddle around it on the plane.

We want this to be a ring, like a ring around a planet, so we don’t want the ring to go right up to the surface of the sphere. Let’s add another, smaller cylinder where we want the empty space to be.

cylinder {

<0, -.01, 0>, <0, .01, 0>, 2.8

}

This looks strange. There’s green all the way to the center, but little black semicircles on the edge. It might even look different on yours than it does in this picture.

This is happening because we have two coincident surfaces. We have a black plane and a green plane whose surfaces are exactly the same once you get inside the radius of 2.8. Both of those cylinders start at y -.01 and end at y .01. POV-Ray has no idea which surface to use as the “real” surface at those points.

This is similar to the problem of looking at a plane straight-on. Because these numbers are exact numbers, we can tell POV-Ray to put things or look at things at exactly the same locations.

In this case, the solution is to make the inner cylinder start at slightly lower and higher points than the outer cylinder does.

cylinder {

<0, -.02, 0>, <0, .02, 0>, 2.8

}

That’s better. This gives our green cylinder the basic shape we want, but we still have that black cylinder inside. We really want there to be nothing there. We want the cylinder to be, not a cylinder, but a ring.

This is what CSG is for. In CSG, we have a difference object that takes the difference between two other objects. We want the difference between our green cylinder and our inner cylinder. Surround the two cylinders with difference:

difference {

cylinder {

<0, -.01, 0>, <0, .01, 0>, 3.2

pigment {

color Green

}

}

cylinder {

<0, -.02, 0>, <0, .02, 0>, 2.8

}

}

Okay, this is what we want. The ring circles the sphere with space between the sphere and the inner edge of the ring. Let’s add a little more “action” to the scene. We can rotate the ring so that it is on an angle.

First, remove the plane from the scene so that we’ll be able to see the whole ring when we angle it. It was a nice plane, but we won’t be needing it any more.

Then, add a “rotate” line to the difference section, just above the final curly bracket:

rotate <0, 0, 30>

The complete difference section should be:

//ring around the sphere

difference {

cylinder {

<0, -.01, 0>, <0, .01, 0>, 3.2

pigment {

color Green

}

}

cylinder {

<0, -.02, 0>, <0, .02, 0>, 2.8

}

rotate <0, 0, 30>

}

The “rotate” line has a set of three numbers that look a lot like our other sets of three numbers. In this case, we’re rotating a number of degrees around the “pole” that we’ve specified. The numbers are still x, y, and z. We’ve told it to rotate 30 degrees around z. You can imagine z as a pole situated on zero x and zero y. It moves from front to back. Here’s a diagram (you can see how this diagram was made at The Persistence of Text).

Rotating the ring <0, 0, 30> is like resting it on the green pole and rotating it 30 degrees, with the right side moving up. We could also rotate it around x and y. In this case rotating the ring solely around y wouldn’t change anything in the image. No matter how much you rotate it around y, it is still a green ring circling the sphere, flat on the other two poles. Now, having rotated it around z first, we could rotate it around y and that would move the lower end either towards or away from us. Go ahead and add another rotate after the current rotate, and play around with rotating it around x and y.

When you’re done, remove that second rotate.