Lecture16-RayTracingIntersections

# Let a xd 2 yd 2 zd 2 1 b 2 xdxo xdxc ydyo ydyc zdzo

• Notes
• 53

This preview shows page 13 - 28 out of 53 pages.

Let A = xd 2 + yd 2 + zd 2 = 1 B = 2( xdxo - xdxc+ ydyo - ydyc+ zdzo - zdzc ) C = xo 2 - 2 xoxc+ xc 2 + yo 2 - 2 yoyc+ yc 2 + zo 2 - 2 zozc+ zc 2 - r2 Then solve using the quadratic equation: Ray-Sphere Intersections 2 4 2 C B B t - ± - =

Subscribe to view the full document.

Ray-Sphere Intersections If the discriminant is negative, the ray misses the sphere The smaller positive root (if one exists) is the closer intersection point We can save some computation time by computing the smaller root first, then only computing the second root if necessary 2 4 2 0 C B B t - - - = 2 4 2 1 C B B t - + - =
Algorithm for ray-sphere intersection: 1. Calculate B and C of the quadratic 2. Calculate the discriminant: D = B 2 – 4 C 3. If D < 0 return false (no intersection point) 4. Calculate smaller intersection parameter t 0 : 5. If t 0  0 then calculate larger t -value t 1 : 6. If t 1  0 return false (intersection point behind ray) 7. else set t = t 1 8. else set t = t 0 9. Return intersection point: p = r ( t ) = r o + r dt Ray-Sphere Intersections: Algorithm 2 0 D B t - - = 2 1 D B t + - =

Subscribe to view the full document.

The normal n at an intersection point p on a sphere is: Ray-Sphere Intersections: Normal n p c r - - - = - = r z z r y y r x x r S c i c i c i c p n
Ray-Sphere Intersections Computation time: § 17 adds/subtracts § 17 multiplies § 1 square root for each ray/sphere test Can we reduce the number of intersection calculations? § use a geometric approach

Subscribe to view the full document.

Ray-Sphere Intersections - Geometric d Sc r o tca th c OC r d
Ray-Sphere Intersections - Geometric d Sc r o tca th c OC r d

Subscribe to view the full document.

Ray-Sphere Intersections - Geometric d Sc ro thc tc a OC r d
Ray-Sphere Intersections - Geometric 3. If tca < 0 and ro lies outside the sphere, the ray does not intersect the sphere 4. Otherwise, compute thc, the distance from the closest approach to the sphere’s surface § thc2 = r2 - d2 § d2 = |OC|2 - tca2, so § thc2 = r2 - |OC|2 + tca2 d Sc ro thc tc a OC

Subscribe to view the full document.

Ray-Sphere Intersections - Geometric 5. If thc2 < 0 the ray does not intersect the sphere 6. Otherwise, calculate the intersection distance § If r0 is outside the sphere: t = tca - thc § If r0 is inside the sphere: t = tca + thc d Sc ro thc tc a OC
Ray-Sphere Intersections - Geometric 7. Calculate the intersection point: (xi, yi, zi) = (xo + xdt, yo + ydt, zo + zdt) 8. Calculate the normal at the intersection point: •. This reduces the computation (worst case) by 4 multiplies and 1 add •. Even fewer computations if the ray misses the sphere d Sc r0 thc tc a OC - - - = r z z r y y r x x c i c i c i n

Subscribe to view the full document.

Ray-Sphere Example r(t) = (0,0,2) + t(0,0,-1) Sphere: (x-2)2 + (y-1)2 + (z-0)2 = 9
Ray-Sphere Example r(t) = (0,0,2) + t(0,0,-1) Sphere: (x-2)2 + (y-1)2 + (z-0)2 = 9 1. Find ||Sc – ro|| = ||(2,1,0) – (0,0,2)|| = ||(2,1,-2)|| = 3. ro is in S. 2. tca = OC ∙ rd = (2,1,-2) ∙ (0,0,-1) = 2*0 + 1*0 + -2*-1 = 2. 3. thc 2= r2 – d2 = r2 - ||OC||2 + tca2 = 9+(32-22 = 4 4. t=tca+thc=2+2=4 5. r(4)=(0,0,2)+(0,0,-4)=(0,0,-2)

Subscribe to view the full document.

To find the intersection points of a ray with an infinite plane: § Ray equation: - Origin: ro = (xo, yo, zo) - Direction: rd = (xd, yd, zd) § Plane equation: ax +by +cz +d = 0 with a2 + b2 +c2 = 1 normal vector pn = (a, b, c) distance from (0, 0, 0) to plane is d Substitute the ray equation into the plane equation: a(x0 + xdt) + b(y0 + ydt) + c(z0 + zdt) + d = 0 ax0 + axdt + by0 + bydt + cz0 + czdt + d = 0 § Solving for t we get: t = -(ax0 + by0 + cz0 + d) / (axd + byd + czd) Ray-Plane Intersections
In vector form we have: If the ray is parallel to the plane and does not intersect If the normal of the plane is pointing away from

Subscribe to view the full document.

You've reached the end of this preview.
• Spring '08
• Jones,M
• Angle of Incidence, Euclidean geometry, Total internal reflection

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern