Reference:Constructive Solid Geometry
In addition to all of the primitive shapes POV-Ray supports, you can also combine multiple simple shapes into complex shapes using Constructive Solid Geometry (CSG). There are four basic types of CSG operations: union, intersection, difference, and merge. CSG objects can be composed of primitives or other CSG objects to create more, and more complex shapes. See also: Object Modifiers.
Inside and Outside
Most shape primitives, like spheres, boxes and blobs divide the world into two regions. One region is inside the object and one is outside. Given any point in space you can say it is either inside or outside any particular primitive object. Well, it could be exactly on the surface but this case is rather hard to determine due to numerical problems.
Even planes have an inside and an outside. By definition, the surface normal
of the plane points towards the outside of the plane. You should note that
triangles cannot be used as solid objects in CSG since they have no well defined inside and outside. Triangle-based shapes (mesh
and mesh2
) can only be used in CSG when they are closed objects and have an inside vector specified.
Note: Although the triangle
, the bicubic_patch
and some other shapes have no well defined inside and outside, they have a front and backside which makes it possible to use a texture on the front side and an interior_texture
on the back side.
CSG uses the concepts of inside and outside to combine shapes together as explained in the following sections.
Imagine you have two objects that partially overlap like shown in the figure
below. Four different areas of points can be distinguished: points that are
neither in object A
nor in object B
, points that
are in object A
but not in object B
, points that
are not in object A
but in object B
and last not
least points that are in object A
and object B
.
Keeping this in mind it will be quite easy to understand how the CSG operations work.
When using CSG it is often useful to invert an object so that it will be
inside-out. The appearance of the object is not changed, just the way that
POV-Ray perceives it. When the inverse
keyword is used the
inside of the shape is flipped to become the outside and vice
versa.
The inside / outside distinction is not important for a union
, but is important for intersection
, difference
, and merge
. Therefore any objects may be combined using union
but only solid objects, i.e. objects that have a well-defined interior can be used in the other kinds of CSG. The objects described in
Finite Patch Primitives have no well defined inside / outside, while the objects described in the sections Finite Solid Primitives and Infinite Solid Primitives do.