Math Tips for Ray Tracing

Here are some helpful formulas for writing a ray tracer.

You normalize a vector by scaling it to be length one.

A normalized vector of length one is called a unit vector. If you have two unit vectors, the cosine of the angle between them is their dot product! That's why we keep using cosines in the lighting approximation rather than the angle itself - it's a lot easier to compute. If we call the angle theta,

The equation for a plane can be conviniently normalized so that it includes the normal n of the plane. The points on the plane are the points (x,y,z) which satisfy

You can find the scalar d by substituting a point (x,y,z) that you know is on the plane. By the way, it turns out that d is the distance from the plane to origin, at the closest point.

To test how strong the specular reflection at a surface point should be, find the cos of the angle between the normal and the vector s half-way between the vector l to the light source and the vector v to the viewpoint. Assuming v and l are normalized, s is easy to compute:

One nice way to find the reflection r of a vector v (not necessarily normalized) in a unit vector n is

When finding the intersection of a line with a quadric surface, the quadratic formula is handy:

The formula below for finding a refraction ray rt from an incoming ray ri and the surface normal is derived from Snell's law, the first equation. See pages 72-3 in Prof. Mount's notes for the derivation and explaination.

Are there any other formulas that ought to go on this page? Let me know!