Part 2: Geometric primitives
A: Ray tracing primitives
B: Conics, quadrics and superquadrics
...back to part 1  on to part 3...
A primitive is a shape for which a rayshape intersection routine has been written. More complex objects can be built out of the primitives. Most ray tracers will have a variety of primitives. They are limited only by the ability of the programmer to write a function to analytically intersect a ray with the surface of the shape.
Polygon
Having the polygon as a ray tracing primitive allows a ray tracer to
render anything that a PSC algorithm could. To find the
intersection of a ray with a polygon, first find the intersection of
the ray with the infinite plane in which the polygon lies. Then
ascertain whether the intersection lies inside or outside the polygon:
this is a reasonably straightforward two dimensional graphics operation.
Box
A box is essentially six polygons and could be ray traced as
such. However, intersection with an axisaligned box can be
optimised. Any box can be axisaligned by appropriate
transformations. We can thus write a routine to intersect an arbitrary
ray with an axisaligned box and then transform the ray under
consideration in exactly the same way as we transform the box which we are
trying to intersect with it. This sort of idea generalises neatly to
the concept of specifying any object in a convenient object coordinate
system and then applying transforms to the whole object to place
it at the appropriate point in the world coordinate system.
Sphere
The sphere is the simplest finite object with which to intersect a
ray. Practically any ray tracing program will include the sphere as a
primitive. Scaling a sphere by different amounts along the different
axes will produce an ellipsoid: a squashed or stretched sphere. There
is thus no need to include the ellipsoid as a primitive provided that
your ray tracer contains the usual complement of transformations. (It
would be a poor ray tracer if it did not!)
Cylinder
Intersecting a ray with an infinitely long cylinder is practically as
easy as intersecting one with a sphere. The tricky bit, if it can be
called that, is to intersect a ray with a more useful finite length
cylinder. This is achieved by intersecting the ray with the
appropriate infinitely long cylinder and then ascertaining where along
the cylinder the intersection lies. If it lies in the finite length in
which you are interested then keep the intersection. If it does not
then ignore the intersection. Note that the ray tracer used to render
the accompanying image has cylinders without end caps. This is the
correct result if you follow the procedure outlined in this
paragraph. Adding end caps to your cylinders requires extra
calculations.
Cone
Cones are very like cylinders. Like the infinite cylinder, there is a
simple mathematical definition of an infinite cone which makes it easy
to write a raycone intersection algorithm. Note that a cone does not
need to have a point  it can be truncated short of its `top', as
illustrated in the accompanying image. The particular ray
tracer used does not add end caps to cones.
Disc
The disc is not a common ray tracing primitive, but is necessary in
ray tracers which implement cones and cylinders without end caps. It
is handled in much the same way as the polygon. The
routine to check if the intersection with the plane lies inside or
outside of the disc is simpler than the equivalent routine for the
polygon. In the accompanying ray traced image, the disc has been
positioned so that it just catches the light  this illustrates how
specular reflection varies across a completely flat surface. The
sphere, cone and torus images illustrate how specular reflection varies
across three curved surfaces.
Torus
Toroids are reasonably rare in real life (doughnuts and tyre inner
tubes notwithstanding). They are somehow alluring to the kinds of
people who implement ray tracers and, having a reasonably
straightforward mathematical definition, are reasonably simple to
implement. They thus appear as primitives in many ray tracers. They
become more useful when combined with Constructive Solid Geometry (see
Part 4C).
Exercises

Part 2: Geometric primitives
A: Ray tracing primitives
B: Conics, quadrics and superquadrics
...back to part 1  on to part 3...