Homework 1, due Wednesday, Feb 3

Send your answer by email to the grader. Also, please note that I'm asking for something slightly different than what I specified in class.

Write a ray/sphere intersection routine which has the following interface:

int raySphere(double ray[6], double sphere[4], double t[2]);
Your routine should take as arguments: Your routine should return a number between zero and two, indicating the number of times the ray intersects the sphere.

Remember that you need to convert the equation:

(wxt + (vx-cx))2 + (wyt + (vy-cy))2 + (wzt + (vz-cz))2 - R2 = 0
into something of the form At2 + Bt + C = 0, just as we did in class, and then solve using the quadratic equation t = (-B ± sqrt(B2 - 4AC)) / 2A to get the two values of t.

If the value under the square root is negative, that means the ray has missed the sphere, in which case your routine should return a value of zero.