Ray tracing through a prism is nothing conceptually new -- it is just an application
of the rules of reflection and refraction. There can be surprises, though. We will look
at the ray transmitted through a triangular prism, ignoring internal reflections. The
surprise is that "most" transmitted rays are deviated through roughly the same
angle, a bit less than
40 degrees in our example, irrespective of the angle of incidence of the
ray on the prism! This is not a violation of Snell's Law, as it might at first seem,
but rather a subtle consequence of it.

Here is a simulation of a ray striking a triangular prism. We will not follow
the internal reflections, but rather just look at the transmitted ray, if there
is one. Of course if the ray is totally internally reflected, there is no transmitted
ray. You can use the mouse to drag any corner of the prism and thus change the angle
of incidence. You will see that there is a minimum angle of deviation, about
37.2 degrees. If you drag the prism either direction from orientation that
gives this minimum deviation, you find that the deviation is quite insensitive to
the change. That is just a familiar fact of calculus: at a minimum, the derivative
is zero. And that is just the property mentioned above: "most" rays are deviated
at about that angle. Note the symmetrical position of the minimum deviation ray.

The angle of minimum deviation is responsible for some meteorological
phemomena, like
halos and sundogs
,
produced by deviation of sunlight
in the hexagonal prisms of ice crystals in the air.
Reflection from raindrops -- another
exercise in ray-tracing -- shows a minimum deviation angle: that's the
rainbow!
In all cases you can imagine as a first approximation that the light is deviated
through just one special angle, the angle of minimum deviation.

The minimum deviation D in a prism occurs when the entering
angle and the exiting angle are the same, a particularly symmetrical
configuration. Applying Snell's Law at the interfaces you can derive
the following relationship:

n=sin[(D+a)/2]/sin(a/2)

where n is the relative index of refraction of the prism, and
a is the angle between the two relevant prism faces (60 degrees
in our example).
Using this relationship, you could
figure out what index of refraction was assumed for this simulation.
You could also use this method to measure the index of refraction
of real materials.