## Homework 1, due Wednesday, Feb 3

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:
• An array ray[6] which specifies vx, vy, vz, wx, wy, wz
• An array sphere[4] which specifies cx, cy, cz, R
• An array t[2] in which to place the values for t of any intersections. If there are two intersections, make sure that t[0] < t[1].
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.