FinalExam Solution
FinalExam Solution
Q1: Can we construct a mesh of a sphere with only quads such that the degree of each
vertex of the mesh is 4? Prove your claim. [10]
Let’s assume that we can make such a mesh. In that case, since the mesh is
homeomorphic to a sphere, by Euler’s formula we have
V-E+F = 2
Where V, E, and F are the total number of vertices, edges, and facets of it.
Since, each vertex has degree 4 and each face is a quad, we have
4F = 2E => F = E/2.
Q2: Use the de Casteljau algorithm to design a curve in 2D of degree four that has its
middle control point on the curve for parameter value t = 0.5. Five collinear points are a
solution but you have to present a better example. In your answer provide the coordinates
of the 5 control points and then show that the middle control point lies on the curve. [10]
q0 = (p0 + p1)/2 = (1,3/2), q1 = (p1 + p2)/2 = (3/2, 1), q2 = (p2+p3)/2 = (5/2, 1), and q3
= (p3+p4)/2 = (3,1/2)
r0 = (q0+q1)/2 = (5/4, 5/4), r1 = (q1 + q2)/2 = (2,1), and r2 = (q2 + q3)/2 = (11/4, ¾)
PTO Page 1
Hence after the final iteration we have
Q3: Given a triangle mesh, briefly explain the key differences in how triangle normal are
used to evaluate (i) flat shading, (ii) Gouraud shading, and (iii) Phong shading. [10]
Solution 3: Given a triangle mesh we can compute each triangle normal using a
cross product. The question asks you how these normal are used to compute shading,
i.e., the color of reflected light. Note that the shading methods all use some
reflectance function that uses position/normal at a point. These shading functions all
use normal differently: (i) Flat shading is evaluated using the normal of the triangle
associated with the sample point.
(ii) Gouraud shading uses normal associated with the triangle’s vertices (which may
be computed by averaging triangle normal around the vertex), then evaluates the
color of each vertex using the reflectance model and linearly interpolates those
colors across the triangle.
In contrast, (iii) Phong shading interpolates vertex normal across the triangle (e.g.,
via linear interpolation followed by normalization), then evaluates the shaded color
by applying the reflectance model at a point on a triangle with the interpolated
normal.
Consequently, flat shading produces constant colors over triangle facets, Gouraud
shading shows piecewise linear color variations but is incapable of producing
specular highlights within a triangle—something Phong shading can do quite well.
Q4: Explain window to viewport mapping. Find the normalization transformation that
maps a window whose lower left corner is at (1,1) and upper right corner is at (3,5) onto a
viewport that is entire normalized device screen. [10]
xw − wx min xv − xvmin
=
xwmax − xwmin xv max − xvmin
yv − yvmin yw − ywmin
=
yvmax − yvmin ywmax − ywmin
PTO Page 2
yv = Syyw+ ty, where
s x 0 tx
This can be represented as a single matrix N = 0 sy t y
0 0 1
So in our case, if we plugin the values we get wxmin = 1, wxmax = 3, wymin = 1, and
wymax = 5. The viewport parameters are vxmin = 0, vxmax = 1, vymin = 0, and vymax =
1. Then
1 / 2 0 − 1 / 2
0 1 / 4 − 1 / 4
0 0 1
Q5: Consider the cubic spline segment, P(t) = a t3 + b t2 + c t + d; on the unit interval t ε
[0; 1]. Recall that Hermite splines use P and P0 controls at each end point, i.e., P0 = P(0),
P0’ = P’(0), P1 = P(1), P1’ = P’(1). In this question you will derive a spline which instead
uses the following controls: at t = 0, use position (P0), velocity (P0’) and acceleration
(P0’’); at t = 1, use position (P1).
(a) What is this spline’s 4x4 geometry matrix G such that [10]
P0
P ′
[
P (t ) = t 3 t2 ]
t 1 G 0
P0′′
P1
P(t) = a t3 + b t2 + c t + d
P’(t) = 3at2 + 2bt + c
PTO Page 3
P’’(t) = 6at + 2b
So that P(1) = a + b + c + d
P(0) = d
P’(0) = c
P’’(0) = 2b
Hence
d = P0,
c = P0’
b = ½ P0’’
a = P1-b-c-d = P1-1/2 P0’’- P0’- P0
Thus P(t) = a t3 + b t2 + c t + d
− 1 − 1 − 1 / 2 1 P0
0 0 1/ 2 0 P0′
[
P(t ) = t 3 t 2 t 1
0 1
] 0 0 P0′′
1 0 0 0 P1
Solution 6: Consider two parallel lines whose points can be explicitly represented as
pk + tu; k = 1; 2; where each is parameterized by some 0< t , and both point in the
same u direction (by virtue of being parallel) but have different base points pk.
Applying an affine transformation
However, since both transformed lines point in the same direction u’ = Fu, they are
still parallel.
PTO Page 4
Q7: Calculate a 4x4 matrix that rotates points about the vector A = [1,1,1] by 90 degrees.
Show you work. [10]
Solution 7:
Rotate about y-axis - 45 degrees to bring vector into YZ plane
Rotate about x-axis 45 degrees to bring vector onto z-axis
Rotate about z-axis by 90 degrees
Unwrap x-rotation
Unwrap y-rotation
cos(45) 0 sin(45) 0 1 0 0 0 cos(90) − sin(90) 0 0
0 1 0 0 0 cos(−45) − sin(−45) 0 sin(90) cos(90)
0 0
− sin(45) 0 cos(45) 0 0 sin(−45) cos(−45) 0 0 0 1 0
0 0 0 1 0 0 0 1 0 0 0 1
1 0 0 0 cos(−45) 0 sin(−45) 0
0 cos(45) − sin(45) 0 0 1 0 0
0 sin(45) cos(45) 0 − sin(−45) 0 cos(−45) 0
0 0 0 1 0 0 0 1
Q8: Illustrate the steps of Weiler-Atherton polygon clipping algorithm using the below
given figure where C1, C2, C3, and C4 is the clip polygon and S1, S2, S3, S4, S5, S6,
and S7 is the subject polygon to be clipped. [12]
S2
C2 C3
S1 S4
S3
S7 S6
C1 C4
S5
PTO Page 5
Solution 8:
Step1: Determine the intersection of the subject and clip polygon. Let I1, I2, I3, I4,
I5, I6, I7, and I8 be the intersection points as shown in below figure. Add each
intersection to the subject polygon and clip polygon vertex list. Thus we have
SUBJECT: S1, I2, I3, S2, I4, S3, I5, S4, I6, I7, S5, I8, S6, I1, S7, S1
CLIP: C1, I1, I2, C2, I3, I4, C3, I5, I6, C4, I7, I8, C1
S2
C2 C3
I3 I4
I2 I5
S1 S4
S3
S7 I1 S6 I6
C1 I8 I7 C4
S5
Step 3:
Once the lists are built the basic idea to do the clipping is as follows
• Pick an entry from the ENTERING list - it will be an intersection point (and
delete it)
• Locate that point on the SUBJECT list
• Traverse the current (SUBJ) list until you find the next intersection point - it
should be an exiting or entering point. Output each vertex encountered to
some data structure, say POLY
• Follow the link from the current (SUBJECT) list to the other (CLIP) list and
• Continue the traversal until you find the next intersection (Note: delete each
entering intersection from the ENTERING list).
• Terminate the traversal when you get to an intersection that is the SAME as
the initial one that you removed from the ENTERING list. At this point
POLY will have one of the clip regions and can be output.
PTO Page 6
• REPEAT the construction and output of POLY until the ENTERING list is
empty.
Q9: Suppose we wish to clip a set of lines to a rectangular window with a hole in it:
Call the outer rectangle R with vertices r0, r1, r2, and r3 and call the inner rectangle H
with vertices h0, h1, h2, and h3. You may assume hi as the corner closest to ri. Describe
an algorithm for clipping lines to this object. [8]
In this algorithm, we will use the same outcodes as Cohen-sutherland Line clipping
does. All those lines which are trivially rejected are going to be trivially accepted
and all those lines which are trivially accepted are going to be trivially accepted.
This is done as follows. If AND of the outcodes of two end points of a line is non-zero
then accept it. If outcodes of both end points of a line is 0000 then trivially reject it.
If a line is not trivially accepted or rejected then divide it into subsegments at a clip
edge. Now test for trivial acceptance or rejection for each subsegment. Continue
each subsegment is either trivially accepted or rejected.
PTO Page 7
So in order to do the desired clipping. Here are the steps
Step 1: Use Cohen-Sutherland Line clipping algorithm to obtain all the lines inside
the clip window of rectangle R and store in a list called INSIDE_R. Reject rest of the
lines.
Q10: Consider a polygonal mesh in 3D with 10000 triangles. You are given 100 line
segment and you want to detect which all triangles of the mesh are getting intersected by
these line segments. Write an efficient algorithm to obtain the list of triangles intersected
by this line segment. Also provide routine to check whether a line intersects a triangle or
not.
[10]
Solution 10: One of the efficient way to do it is using Octree data structure.
Consider a 3D axis aligned cube containing the entire model. Divide this cube into 8
octants. Classify each vertex into one of the octants in which it is contained. If an
octant has more than say M ( a small number say 10) vertices then split it further
into 8 more octants. In this way, we will get a hierarchical Octree structure, T.
In order to detect intersection, take a line segment and start with the root of the tree
T.
For a given octant node O:
If the line segment is intersecting this octant node O
If it is a leaf node
Do explicit intersection check with all the incident triangles of the
vertices belonging to that node.
Else
Traverse recursively to its 8 children and check for intersection with
those 8 children.
Else
Ignore this node and move to its sibling node and checkrecursively for
intersection with its sibling node.
PTO Page 8
C = x1 (y2 - y3) + x2 (y3 - y1) + x3 (y1 - y2)
- D = x1 (y2 z3 - y3 z2) + x2 (y3 z1 - y1 z3) + x3 (y1 z2 - y2 z1)
Substituting in the equation of the line segment through points P1 (x’1,y’1,z’1) and
P2 (x’2,y’2,z’2)
P = P1 + u (P2 - P1)
gives
A (x’1 + u (x’2 – x’1)) + B (y’1 + u (y’2 – y’1)) + C (z’1 + u (z’2 – z’1)) + D = 0
Solving for u
Once the intersection point I is determined then we can check whether the
intersection point lies inside the triangle or not using clockness test. If the point is
inside then the signed area of triangle (I, T1, T2), (I,T2,T3), and (I,T3,T1) will be
same. The signed area of a triangle can be computed by taking the cross product of
its two consecutive edges in the same order.
Q11:
(a) Given is a world coordinate system with the origin O=(0,0,0) and a second
coordinate system with the origin P=(px, py, pz) in world coordinates. The basis
vectors u, v and n of the second coordinate system are normalized and orthogonal
to each other.
Find the homogenous matrix M which converts the uvn-coordinate system into the world
coordinate system. Write down all components of the matrix M. [5]
Solution 11:
1. Translate the origin P of uvn system into origin of the world coordinate
system
2. Rotate uvn-axis into xyz-axes
PTO Page 9
u x uy uz 0 1 0 0 − p x u x uy uz − p.u
v
vy vz 0 0 1 0 − p y v x vy vz − p.v
M = Ruvn T = x
−1
=
n x ny nz 0 0 0 1 − p z n x ny nz − p.n
0 0 0 1 0 0 0 1 0 0 0 1
(b) Consider that eye is at (4,4,4), looking at (0,1,0) and the up vector is (0,1,0).
Compute the view matrix created by gluLookAt(). [5]
Solution:
n = eye – look
u = up x n
v=nxu
(dx, dy, dz) = (-eye.u, -eye.v, -eye.n)
Graphics pipeline: Select the correct spaces from above and list them in the order that we
expect each vertex to go through in the traditional transformation process:
PTO Page 10
(II) Match the descriptions to the appropriate concepts.
(a) A simpler object to make culling tests quicker
(b) Draw or don’t draw triangles based on the order of their vertices
(c) Making things farther away appear smaller
(d) Only draw objects that are in view
(e) Preserve parallel lines
Solution:
__b_ Backface culling
__a_ Bounding volume
__d_ Frustum culling
__e_ Orthographic transform
__c_ Perspective transform
PTO Page 11