Lecture 14:Ray Sphere Intersection
September 21, 2017
Sphere Intersection• Sphere centered at Pc with radius r.
9/21/17 CSU CS 410 Fall 2017 ©Ross Beveridge & Bruce Draper
P −Pc2=r2
L + sU −Pc2− r2 =0
substituteT =Pc − LYielding a quadratic equationsU −T( ) ⋅ sU −T( )− r2 =0
L
2
Brute Force (II)• Expand to see what is happening.
9/21/17 CSU CS 410 Fall 2017 ©Ross Beveridge & Bruce Draper
W ⋅W − r2 =0 W =
sux − txsuy − tysuz − tz
T =xc − x0yc − y0zc − z0
suxuyuz
−
txtytz
"
#
$$$$
%
&
''''
• suxuyuz
−
txtytz
"
#
$$$$
%
&
''''
"
#
$$$$
%
&
''''
− r2 = 0
sux − tx( )2 + suy − ty( )2+ suz − tz( )2 − r2 = 0
3
SphereIntersection(III)
9/21/17 CSU CS 410 Fall 2017 ©Ross Beveridge & Bruce Draper
• Multiply then expand and collect terms.
€
s2 − 2 U ⋅T( ) s+T ⋅T − r2 =0
• U is length 1, so (ux2 + uy
2 + uz2) = 1
• So the equation may be written as:
ux2 +uy
2 +uz2( )s2 +
−2txux − 2tyuy − 2tzuz( )s+tx2 + ty
2 + tz2( )− r2 = 0
4
ReducestoQuadratic
9/21/17 CSU CS 410 Fall 2017 ©Ross Beveridge & Bruce Draper
Note vector dot products.
as2 + bs+ c = 0wherea =1b = −2 U ⋅T( )c = T 2 − r2
Therefore:
s = −b± b2 − 4ac2a
s =2 U ⋅T( )± 4 U ⋅T( )2 − 4 T 2 − r2( )
2
s = U ⋅T( )± U ⋅T( )2 −T 2 + r2
5
Actual Intersection Points• Compute the two s values for the two
intersections:
• Compute the actual positions along the ray for the smallest positive s:
9/21/17 CSU CS 410 Fall 2017 ©Ross Beveridge & Bruce Draper
s1 = U ⋅T( )+ U ⋅T( )2 −T 2 + r2
s2 = U ⋅T( )− U ⋅T( )2 −T 2 + r2
8 multiplies/squares (caching results; r2
previously stored) 9 additions/subtractions1 square root
s* =min(s1, s2 )P* = L + s*U
3 multiplies 3 additions1 min
6
FirstExample
9/21/17 CSU CS 410 Fall 2017 ©Ross Beveridge & Bruce Draper 7
SecondExample
9/21/17 CSU CS 410 Fall 2017 ©Ross Beveridge & Bruce Draper 8
But Wait• The proceeding follows naturally from
parametric approach to intersection.• But is it smart? Is there a better way?• Yes.– Glassner, A. (ed) An Introduction to Ray Tracing.
Academic Press, 1989– http://www.cs.unc.edu/~rademach/xroads-
RT/RTarticle.html• Let’s see it,
9/21/17 CSU CS 410 Fall 2017 ©Ross Beveridge & Bruce Draper 9
FasterMethod
9/21/17 CSU CS 410 Fall 2017 ©Ross Beveridge & Bruce Draper
€
v 2 + b2 = c 2
d2 + b2 = r2
€
d2 = r2 − c 2 − v 2( )( )d = r2 − c 2 − v 2( )
E
O
R
If d2 less than zero, no intersection.Otherwise, Q = E + (v-d)R
Q
10
Faster Method - How Fast?• Recall how R is defined …
• Need to compute v …– 3 multiplies, 2 additions.
• Both r2 and c2 are already computed.– c2 computed for case of ray coming from focal point
• Test if r2 is greater than (c2 - v2) – 1 multiply, one conditional.
• Only if intersection, Q = E+(v-d)R.– 1 subtract, 3 multiplies, 3 additions.
• Another reference on this approach:– http://www.groovyvis.com/other/raytracing/basic.html
9/21/17 CSU CS 410 Fall 2017 ©Ross Beveridge & Bruce Draper
𝑅 𝑠 = 𝐿 + 𝑠𝑈𝑣 = 𝐶 − 𝐿 * 𝑈
11
Example1
9/21/17 CSU CS 410 Fall 2017 ©Ross Beveridge & Bruce Draper
𝑟, − 𝑏, = −5813
12
Example2
9/21/17 CSU CS 410 Fall 2017 ©Ross Beveridge & Bruce Draper 13
Option: Rays from Focal Point• Earlier, we had the ray
originate from pixel L.• With the unit vector pointing
from focal point E to pixel L.• Now, instead, let ray
originate from focal point E.
9/21/17 CSU CS 410 Fall 2017 ©Ross Beveridge & Bruce Draper
R s( )=L + sU
U= L −EL −E
R s( )=E + sU
Howmightthishelp?IntermediatevaluesremainconstantacrossallpixelswhenalwaysusingthefocalpointEasthebaseoftheray.
14
Why Spheres in a Triangle World?• How do spheres help with big polygonal
models??• Define a sphere around your model.– Intersecting the sphere is necessary but not
sufficient for intersecting polygons in the model.–May help greatly to reduce work.
• What factors contribute to savings?
9/21/17 CSU CS 410 Fall 2017 ©Ross Beveridge & Bruce Draper 15