CS 418: Homework Solution - Gaussian Blobs and Surface Intersection, Assignments of Computer Graphics

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

Pre 2010

Uploaded on 03/16/2009

koofers-user-t4i
koofers-user-t4i 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 418: Homework #3
Solution
1. Recall that a Gaussian blob is represented as an implicit surface by the zero set of the function:
F(x) = eσkxk2τ= 0
(a) Given a ray x(t) = p+td, derive an equation for the value(s) of tat which the ray intersects this
surface.
Solution:
Plug x(t) = p+tdinto F(x) = 0, we get
eσkp+tdk2τ= 0
σkp+tdk2= ln τ
(p+td)·(p+td) = ln τ
σ
d·dt2+ 2d·pt+p·pln τ
σ= 0
Let a=d·d= 1, b = 2d·p, c =p·pln τ
σ, then
t=b±b24ac
2a=d·p±r(d·p)2p·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.
2. In class we discussed a method for generating shadows by projecting an object through a point onto a
plane. If the light source (which is the focal point of the projection) moves to infinity, then all light
rays become parallel. To generate such shadows, we must perform parallel projection onto a plane. This
provides us with a reasonable way to model shadows cast by the sun, which for all practical purposes is
infinitely far away.
Suppose you are given some triangulated surface model. We want to project every vertex valong the
direction donto the plane n·x+k= 0. Derive the 4 ×4 matrix which accomplishes this projection.
d
n
pf3
pf4

Partial preview of the text

Download CS 418: Homework Solution - Gaussian Blobs and Surface Intersection and more Assignments Computer Graphics in PDF only on Docsity!

CS 418: Homework

Solution

  1. Recall that a Gaussian blob is represented as an implicit surface by the zero set of the function:

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.

  1. In class we discussed a method for generating shadows by projecting an object through a point onto a plane. If the light source (which is the focal point of the projection) moves to infinity, then all light rays become parallel. To generate such shadows, we must perform parallel projection onto a plane. This provides us with a reasonable way to model shadows cast by the sun, which for all practical purposes is infinitely far away. Suppose you are given some triangulated surface model. We want to project every vertex v along the direction d onto the plane n·x + k = 0. Derive the 4×4 matrix which accomplishes this projection.

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:

M =

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 */ } }