0% found this document useful (0 votes)
214 views

FinalExam Solution

The document appears to be part of a comprehensive exam for a computer graphics course. It contains 8 questions related to topics in computer graphics. Question 1 asks the student to prove whether a mesh of a sphere can be constructed using only quadrilateral faces where each vertex has a degree of 4. The student proves this is not possible using Euler's formula. Question 2 asks the student to use the de Casteljau algorithm to design a degree 4 curve where the middle control point lies on the curve for t=0.5. The student provides the coordinates of 5 control points that satisfy this and shows the middle point does lie on the curve. Question 3 asks the student to briefly explain the key differences in

Uploaded by

pranavjibhakate
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
214 views

FinalExam Solution

The document appears to be part of a comprehensive exam for a computer graphics course. It contains 8 questions related to topics in computer graphics. Question 1 asks the student to prove whether a mesh of a sphere can be constructed using only quadrilateral faces where each vertex has a degree of 4. The student proves this is not possible using Euler's formula. Question 2 asks the student to use the de Casteljau algorithm to design a degree 4 curve where the middle control point lies on the curve for t=0.5. The student provides the coordinates of 5 control points that satisfy this and shows the middle point does lie on the curve. Question 3 asks the student to briefly explain the key differences in

Uploaded by

pranavjibhakate
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Birla Institute of Technology and Science-Pilani, Hyderabad Campus

Second Semester 2011-2012


COMPREHENSIVE EXAMINATION
Course No: CS C471/IS C471 Course Title: Computer Graphics
Type: Closed Time: 3 hrs Total Marks: 120 Wt.age: 40% Date:12/5/12
Total Number of Pages =

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]

Solution: No we cannot construct such a mesh. Here is the proof of it.

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.

And 4V = 2E => E = 2V => F = V

Thus V-E+F = V – 2V + V = 0, which is not equal to 2. Hence a contradiction.

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]

Solution 2: Let p0 = (1,2), p1 = (1,1), p2 = (2,1), p3 = (3,1), and p4 = (3,0)

So, after the first iteration of de Casteljau algorithm

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)

After the second iteration of de Casteljau algorithm

r0 = (q0+q1)/2 = (5/4, 5/4), r1 = (q1 + q2)/2 = (2,1), and r2 = (q2 + q3)/2 = (11/4, ¾)

After the third iteration

s0 = (r0 + r1)/2 = (13/8, 9/8) and s1 = (r1 + r2)/2 = (19/8, 7/8)

PTO Page 1
Hence after the final iteration we have

t0 = (s0 + s1)/2 = (2, 1) = p2

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]

Solution 4: A window is specified by four world coordinates: xwmin, xwmax, ywmin,


and ywmax. Similarly a viewport is described by four normalized device
coordiantes: xvmin, xvmax, yvmin, and yvmax. The objective of window to viewport
mapping is to convert the world coordinate (xw, yw) of an arbitrary point to the
corresponding normalized device coordinates (xv, yv). In order to maintain the
same relative placement of the point in the viewport as in the window, we require

xw − wx min xv − xvmin
=
xwmax − xwmin xv max − xvmin
yv − yvmin yw − ywmin
=
yvmax − yvmin ywmax − ywmin

Solving for (xv,yv) gives


xv = Sxxw+ tx

PTO Page 2
yv = Syyw+ ty, where

xvmax − xv min yvmax − yvmin


sx = ; sy =
xwmax − xwmin ywmax − ywmin

xwmax xvmin − xwmin xv max ywmax yvmin − ywmin yv max


And t x = ; ty =
xwmax − xwmin ywmax − ywmin

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 

Solution 5: Taking derivatives of P(t), we have

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

Plugging in the values of a, b, c, and d we get

− 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 

Q6. Show that affine transformations in 2D preserve parallel lines. [10]

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

 m11 m12 m13 


m F v
m22 m23  =  T
 21 1
1  
0
 0 0

to such points produces new line points

F(pk + tu) + v; = (Fpk + v) + tFu; = pk’ + tu’

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 2: Categorize each intersection point as “ENTERING” or “EXITING”.

ENTERING: I2, I4, I6, I8


EXITING: I1, I3, I5, I7

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.

POLY Traversing Polygon ENTERING


I2, I4, I6, I8
I2, I3 SUBJECT I4,I6,I8
I2,I3,I4 CLIP I6,I8
I2,I3,I4,S3,I5 SUBJECT I6,I8
I2,I3,I4,S3,I5,I6 CLIP I8
I2,I3,I4,S3,I5,I6,I7 SUBJECT I8
I2,I3,I4,S3,I5,I6,I7,I8 CLIP EMPTY
I2,I3,I4,S3,I5,I6,I7,I8,S6,I1 SUBJECT EMPTY
I2,I3,I4,S3,I5,I6,I7,I8,S6,I1,I2 CLIP 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]

Solution 9: First we define an algorithm called “Cohen_Sutherland Complement Line


Clipping” algorithm.

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.

Step 2: Use Cohen-Sutherland Complement Line Clipping algorithm on the set of


lines in INSIDE_R to obtain all the ines outside the clip rectangle H. Output the
result.

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.

Algorithm to check whether a line segment intersects a triangle or not:

Let three points of the triangle in space be T1(x1,y1,z1), T2(x2,y2,z2), and T3


(x3,y3,z3). Then the equation of the plane is given as Ax + By + Cz = D, where

A = y1 (z2 - z3) + y2 (z3 - z1) + y3 (z1 - z2)


B = z1 (x2 - x3) + z2 (x3 - x1) + z3 (x1 - x2)

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

Ax'1 + By '1 + Cz '1 + D


u=
A( x '1 − x'2) + B( y '1 − y '2) + C ( z '1 − z '2)

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)

The View Matrix is given by

u x uy uz − eye.u   0.70711 0 − 0.70711 0 


   
− eye.v  − 0.3313 0.88345 − 0.3313 − 0.8345
V = x
v vy vz
=
n ny nz − eye.n   0.6247 0.4685 0.6247 − 6.872 
 x   
 0 0 0 1   0 0 0 1 
Q12:
(I) Consider the following terms [10]
(a) Camera space
(b) Image Space
(c) Inner space
(d) Normalized View space
(e) Object space
(f) Outer space
(g) Projective space
(h) World space

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:

Fill in the letters : 1._____2._____3._____4._____5.______

Solution 12: 1. __e__ 2.__h_3._a__4._d__5.__b___

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

____ Backface culling


____ Bounding volume
____ Frustum culling
____ Orthographic transform
____ Perspective transform

Solution:
__b_ Backface culling
__a_ Bounding volume
__d_ Frustum culling
__e_ Orthographic transform
__c_ Perspective transform

PTO Page 11

You might also like