[csu540-f05-rpf] Ray trace - simple ortho and perspective t-values
Robert Futrelle
futrelle at ccs.neu.edu
Tue Oct 4 13:21:10 EDT 2005
Note on simple ray tracing for spheres
by Prof. Futrelle, 10/4/05
Here's an example that's so simple that you can work it
through by hand, and also check that your code can do it too.
Assume you have an eyepoint, raye at 0,0,10 along the z-axis.
Assume you have a sphere at the origin, c = 0,0,0 with radius R = 1.0.
Assume that the ray direction is 0,0,-1 pointing toward negative z.
Clearly, you intersections with the sphere should be at
z = 1 and z = -1. If you do the math, you'll get t values
at t = 9 and t = 11, corresponding to the two hits along
the z-axis.
Again, this was generated because a student came to my
office during my office hours, asking for a simple example.
------------------------
As a prelude to my note on perspective, let's assume
that instead, I have a vector d which has coordinates 1,1,-100,
which will hit the sphere slightly off axis, about 15% of its
radius off axis, but still with t values similar to hitting
it on-axis.
The basic quantities in the equation on pg. 206:
d = 1,1,-100
e = 0,0,10
c = 0,0,0
e - c = 0,0,10
d dot d = 10,002
e - c dot e - c = 100
R = 1
R squared = 1
d dot e - c = 1,1,-100 dot 0,0,10 = -1,000
The entire equation becomes
(1,000 plus or minus sqrt( (1,000 squared) - 10,002(100 - 1)))/10,002
The way to approximate this is to write the second terms in the sqrt
as - (10,000 + 2)(100 -1), multiply it out to four terms, cancel the
two 1,000,000 terms, retaining only the 10,000 term. Also, approx. the
denominator by 10,000. When all done, you get, to a good approximation,
t = 1/10 plus/minus 1/100, which is precisely what you'd expect.
Too see why, draw a picture.
My reason for all these approximations is that I was trained both
in the calculus and numerical math to make approximations by
expanding and then neglecting small terms. Gives more insight than
to just blindly run the numbers. It's actually easier - I could
do the entire computation without a calculator. Heck, who wants
that 2 in 10,002?! I did have to go to second order in the radicand,
getting rid of the largest two terms and retaining the next largest
term.
Again, I've ran through all this rather quickly, so it could
still be wrong. I'd advise you to check it yourself.
- RPF
PS: Where did the word "radicand" come from?
From http://mathworld.wolfram.com/Radical.html
UTWS, to put it crudely. More at
http://acronyms.thefreedictionary.com/Read+The+Meticulously+Formulated+Question
More information about the csu540-f05-rpf
mailing list