


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Solutions to homework problems in cs 418, including deriving the equation for the intersection of a ray with a gaussian blob surface and generating shadows through parallel projection. It also discusses the inefficiencies in a ray-sphere intersection procedure and proposes improvements.
Typology: Assignments
1 / 4
This page cannot be seen from the preview
Don't miss anything!



F (x) = eσ‖x‖
2 − τ = 0 (a) Given a ray x(t) = p + td, derive an equation for the value(s) of t at which the ray intersects this surface.
Solution: Plug x(t) = p + td into F (x) = 0, we get
eσ‖p+td‖
2 − τ = 0
⇒ σ‖p + td‖^2 = ln τ
⇒ (p + td)·(p + td) =
ln τ σ ⇒ d·dt^2 + 2d·pt + p·p − ln τ σ
Let a = d·d = 1, b = 2d·p, c = p·p − lnσ^ τ , then
t =
−b ±
b^2 − 4 ac 2 a
= −d·p ±
(d·p)^2 − p·p +
ln τ σ
(b) Give the conditions that we must check to determine whether the ray actually hits the surface or not?
Solution: Ray hits surface if and only if at least one of the solutions of t in part (a) satisfies t > 0.
d
n
Solution:
For a point p and its projection on the plane p′, we are trying to find a projection matrix M that satisfies p′^ = Mp.
The relation between p and p′^ can be written as p′^ = p + td, with t unknown. Substitute it into the plane equation n·p′^ + k = 0 (since p′^ lies on the plane), we get
n·(p + td) + k = 0
⇒ n·p + n·dt + k = 0
⇒ t =
−(n·p + k) n·d
So
p′^ = p + td = p − n·p + k n·d
d
Now we transform this relation between p and p′^ into the desired matrix form. Let’s look at the above equation component by component:
p′ x = px −
n·p + k n·d
dx
= px −
nxpx + ny py + nz pz + k n·d dx
=
n·d [(n·d − nxdx)px − (ny dx)py − (nz dx)pz − kdx]
n·d
[ n·d − nxdx − ny dx − nz dx − kdx ]
px py pz 1
The same equation can be derived for p′ y and p′ z. Combining these components, we get
p′^ =
p′ x p′ y p′ z 1
n·d − nxdx −ny dx −nz dx −kdx −nxdy n·d − ny dy −nz dy −kdy −nxdz −ny dz n·d − nz dz −kdz 0 0 0 n·d
px py pz 1
So the 4×4 matrix M that relates p and p′^ is:
n·d − nxdx −ny dx −nz dx −kdx −nxdy n·d − ny dy −nz dy −kdy −nxdz −ny dz n·d − nz dz −kdz 0 0 0 n·d
double intersect_sphere(const Vec3& p, const Vec3& d) { double PO = p-center; double B = 2 * (PO * d); double C = POPO - radiusradius;
double dis = BB - 4C; if( dis < 0.0 ) return -1; /* No intersection exists */
double sqrt_dis = sqrt(dis); double t0 = 0.5*(-B - sqrt_dis);
if(t_0>0) return t_0; else { double t1 = 0.5(-B + sqrt_dis)); if(t_1>0) return t_1; else return -1; / No intersection exists */ } }