This page is a short example of POV-Ray's Constructive Solid Geometry feature.
If you don't understand it, please see
Intro to POV-Ray.

Intersection

POV-Ray has a feature that allows you to construct objects by
specifying the intersection of other objects. For example, suppose
you want to construct the object that is the intersection of two
cylinders. Here's a example.

The key to create a intersection, is the instersection {} construct. For example, the intersection of two cylinders is specified like this:

intersection {
cylinder { <3,0,0>,<-3,0,0>, // center of two ends
0.5// Radius
texture { pigment { color Red } }
}
cylinder { <0,0,3>,<0,0,-3>, // center of two ends
0.5// Radius
texture { pigment { color Blue } }
}
}

Now, let's make a intersection of 3 orthogonal cylinders.

Difference

Objects can be build by taking the difference between two objects.

The key in the above image is this:

difference {
sphere { <0,0,0>, 1} // smaller sphere
sphere { <6,0,0>, 5.1} // larger sphere
rotate <0,0,40> // rotate the final object for better view
pigment { White} // color it white
}

Union and Merge

A object can be created as the union of two or more objects. Such union is useful because it can be assigned to a variable and POV-Ray can then treat it as a single object.

Note the construction merge {}. The keyword “merge” can be replaced with “union”. Their difference is that “merge” will delete the internally shared parts. That is why, in the above image we can see thru one of the tube into another tube.

CSG Substraction Glitch

Sometimes when doing a substraction and the two object's face coincide, output image may have a glitch, because coincident surfaces confuses it. Here's a example where large square of side length 2 is to substract a smaller square of side length 1.

difference {
box { -1, 1pigment { Red } } // -1 means <-1,-1,-1> and 1 means <1,1,1>
box { 0, 1pigment { Blue } }
}

A proper solution, is to make the subtracted object slightly larger. For example:

difference {
box { -1, 1pigment { Red } }
box { 0, 1pigment { Blue } scale 1.0001}
}