Signture: Fire Alrm Code: CPSC 44 2-2 (T) 2nd Midterm Exm Deprtment of Computer Science University of British Columbi K. Booth & R. Schrein Exm Instructions (Red Crefully). Sign the first pge of the exm with your Signture in the spce provided on the upper left immeditely. 2. Continue reding the instructions, but do not open the exm booklet until you re told to do so by proctor. 3. Print your Nme nd Student Identifiction Number on every pge in the spce provided t the top of ech pge before you strt the exm. 4. Cheting is n cdemic offense. Your signture on the exm indictes tht you understnd nd gree to the University s policies regrding cheting on exms. 5. Plese red the entire exm before nswering ny ofthe questions. 6. There re four questions on this exm, ech worth the indicted number of mrks. Answer s mny questions s you cn. 7. Write ll of your nswers on these pges. If you need more spce, there is blnk spce t the end of the exm. Be sure to indicte when question is continued, both on the pge for tht question nd on the continution pge. 8. Interpret the exm questions s written. No questions will be nswered by the proctor(s) during the exm period. 9. The exm is closed book. There re no ids permitted, except for clcultor.. You hve 7 minutes in which to work. Budget your time wisely.. In the event of fire lrm during the exm, enter the four-chrcter code provided by the proctor(s) in the spce on the upper right, then gther your belongings nd exit the room, hnding your exm to proctor s you exit. 2. No one will be permitted to leve the exm room during the lst ten minutes of the exm. Question Men SD Mx (-b) 6.7.9 8 (c-d) 2.6 3.6 6 2(-d) 7..2 8 2(e-h) 6. 2. 8 3 5.6 4.2 2 4(-l) 2. 3.6 24 4(m-t) 5..5 6 Totl 82.9. CPSC 44 2-2 (T) of3 2nd Midterm Exm (7 minutes)
Question # [24 mrks totl] This question tests your knowledge of how 2D polygon clipping is performed. The questions will refer to window-edge coordintes, Sutherlnd-Cohen outcodes, nd the Sutherlnd-Hodgmn polygon clipper discussed in lecture. Below is the min body of the clipping function given in the lecture nd on the course Web pges. It clips ginst single clipping boundry, then psses its output to the next boundry. Assume tht the clipping boundries re the stndrd ones for 2 2squre window centred on the origin,. x, y +., nd tht clipping is performed ginst the four clipping boundries in four stges using the order Left, Right, Bottom, nd then Top. You my ssume tht ll necessry initiliztion hs been performed, nd tht the function WEC(i,x,y) returns the i-th window edge coordinte for the point (x,y). int flg[maxout]; /* flg[i] = FALSE if first vertex */ flot Fx[MAXOUT], Fy[MAXOUT]; /* first vertex t i-th level*/ flot Sx[MAXOUT], Sy[MAXOUT]; /* sved vertex t i-th level*/ flot wecs[maxout]; /* outcode for sved vertex t i-th level */ void Clip ( int i, flot Px, flot Py ) { flot lph, wecp, Ix, Iy; if (i==maxout) { Output(Px,Py); return; } wecp = WEC( i, Px, Py ); /* Get ith Window Edge Coordinte */ if (!flg[i]) { Fx[i]=Px; Fy[i]=Py; flg[i]=true; } else { if (wecs[i]>=) { if (wecp>=) /* Cse ++, S nd P re both OK */ Clip(i+, Px, Py ); /* Pss long P to next level */ else { /* Cse +-, S is OK but P is not */ lph = wecs[i] / (wecs[i] - wecp); Ix = Sx[i] + lph*(px-sx[i]); Iy = Sy[i] + lph*(py-sy[i]); Clip(i+, Ix, Iy ); /* Pss long I to next level */ } } else { if (wecp>=) { /* Cse -+, S is not OK but P is OK */ lph = wecs[i] / (wecs[i] - wecp); Ix = Sx[i] + lph*(px-sx[i]); Iy = Sy[i] + lph*(py-sy[i]); Clip(i+, Ix, Iy ); /* Pss long I to next level */ Clip(i+, Px, Py ); /* Pss long P to next level */ } } } Sx[i]=Px; Sy[i]=Py; wecs[i]=wecp; } void End ( int i ) { if (i<maxout) { /* If never clled, then nothing to do t or fter this level */ if (flg[i]) { Clip( i, Fx[i], Fy[i] ); End(i+); flg[i] = FALSE; } } } void Strt ( int i ) { if (i<maxout) { flg[i] = FALSE; Strt(i+); } } CPSC 44 2-2 (T) 2of3 2nd Midterm Exm (7 minutes)
In this question, the input polygon to be clipped ginst the 2 2window isgiven bythe following 2D coordintes. Vertex x y P.. P. 5 +. 5 P 2. 5 +. 5 P 3 2.. () [4 mrks] Determine the vlues of the four one-bit outcodes for ech of the vertices with respect to the four boundries of the clipping region. Use the stndrd convention for outcodes. Vertex L R B T P P P 2 P 3 NOTE: The nswers T or TRUE (insted of ), nd F or FALSE (insted of ) re lso cceptble (this is the convention in the textbook). (b) [4 mrks] Determine the numeric vlues of the four window edge coordintes with respect to the four boundries of the clipping region for just the third vertex P 2 = (. 5, +. 5) in the input polygon. WEC[Left]: + x =+. 5 WEC[Right]: x =+. 5 WEC[Bottom]: + y =+2. 5 WEC[Top]: y =. 5 CPSC 44 2-2 (T) 3of3 2nd Midterm Exm (7 minutes)
(c) [8 mrks] Indicte the coordintes fter the clipper is clled with ll points for the Left clipping boundry (i.e., provide the output from the first stge of clipping). Unused entries should be left blnk. Vertices should be listed in order so they form proper polygon (you cn strt with ny vertex, but the rest must come in the correct cyclic order). Vertex x y P. 5 +. 5 P 2. 5 +. 5 L. +. L.. P.. The order bove is wht the C code ctully produces if it is run with just the Left clipping boundry. Your nswer cn be ny cyclic shift of this. (d) [8 mrks] Indicte the coordintes t the very end fter the clipper is clled with ll points for the Top clipping boundry (i.e., provide the output from the lst stge of clipping). Unused entries should be left blnk. Vertices should be listed in order so they form proper polygon (you cn strt with ny vertex, but the rest must come in the correct cyclic order). Vertex x y L.. P.. P. 5 +. 5 T. 5 +. T. +. L. +. NOTICE tht T nd L hve the sme coordintes! CPSC 44 2-2 (T) 4of3 2nd Midterm Exm (7 minutes)
Question #2 [6 mrks totl] This question tests your knowledge of properties nd conventions for 3D polygons. Below re the 3-D coordintes for polygon (similr to the polygon used in Question #, but this one hs 3D coordintes rther thn just 2D coordintes). Vertex x y z P... P. 5 +. 5. P 2. 5 +. 5. P 3 2... Use these coordintes for the first four prts of this question. () [2 mrks] Assume tht the eyepoint is locted t (.,., 3. ). Using our stndrd convention for polygons, is the polygon (P, P, P 2, P 3 )front-fcing or bck-fcing polygon? Why? IT is FRONT-FACING becuse the vertices re seen in COUNTER- CLOCKWISE order from the eyepoint. Newell s formul provides norml of (,,), which points towrd the eyepoint. (b) [2 mrks] Is the polygon (P, P, P 2, P 3 )plnr or non-plnr polygon? Why? It is PLANAR becuse ll of the vertices lie in the z = plne. (c) [2 mrks] Is the polygon (P, P, P 2, P 3 )convex or non-convex polygon? Why? It is NON-CONVEX becuse the line P P 2 is not completely contined within the polygon interior or boundry. (d) [2 mrks] Is the 2D projection onto the screen of the polygon (P, P, P 2, P 3 )simple or nonsimple polygon? Why? It is SIMPLE becuse no edges cross in the projected polygon. CPSC 44 2-2 (T) 5of3 2nd Midterm Exm (7 minutes)
For the next four prts of this question, consider the following polygon for ll of your nswers. Its vertices re different both in order nd in coordintes from the previous polygon. Vertex x y z P 4 2... P 5. 5 +. 5. P 6... P 7. +. 5. (e) [2 mrks] Assume tht the eyepoint is locted t (.,., 3. ). Using our stndrd convention for polygons, is the polygon (P 4, P 5, P 6, P 7 )front-fcing or bck-fcing polygon? Why? IT is BACK-FACING becuse the vertices re seen in CLOCKWISE order from the eyepoint. Newell s formul provides norml of (.499,.66,-.9986), which points wy from the eyepoint. The polygon is non-plnr (see (f) below) nd non-simple (see (h) below). This mkes it more difficult to nswer this question, but the lrger portion is clockwise nd the smller is counterclockwise, nd Newell s formul weights this ccordingly to produce net result tht corresponds to clockwise ordering. (f) [2 mrks] Is the polygon (P 4, P 5, P 6, P 7 )plnr or non-plnr polygon? Why? It is NON-PLANAR becuse three of the vertices lie in the z = plne but one does not, so there cnnot be ny plne in which they ll four lie. (g) [2 mrks] Is the polygon (P 4, P 5, P 6, P 7 )convex or non-convex polygon? Why? It is NON-CONVEX becuse the line P 5 P 7 is not completely contined within the polygon interior or boundry. The fct tht it is nonplnr mens it cnnot be convex. (h) [2 mrks] Is the 2D projection onto the screen of the polygon simple or non-simple polygon? Why? It is NON-SIMPLE becuse the two edges P 5 P 6 nd P 7 P 4 cross in the projected polygon. CPSC 44 2-2 (T) 6of3 2nd Midterm Exm (7 minutes)
Question #3 [2 mrks totl] This questions tests you knowledge of hierrchicl disply list structures s discussed in lecture. Below is DAG tht will disply multiple instnces of the unit cube, centred t the origin, whose geometry is stored in the node C when the Wlk() function is clled to process the root node of the DAG. Refer to this digrm for both prts of this question. The nodes with T lbel re trnsltions. T T T2 T3 T4 T5 R S istrnsltion tht tkes (x, y, z) to(x,y 5, z). istrnsltion tht tkes (x, y, z) to(x,y,z). istrnsltion tht tkes (x, y, z) to(x,y+5, z). istrnsltion tht tkes (x, y, z) to(x 5, y, z). istrnsltion tht tkes (x, y, z) to(x,y,z). istrnsltion tht tkes (x, y, z) to(x+5, y, z). iscounterclockwise rottion of 6 degrees bout z-xis. is scling tht contrcts everything by fctor of three long the x xis, expnds everything by fctor of seven long the y xis, nd leves things unchnged long the z xis. T T T2 T3 T4 T5 S R C CPSC 44 2-2 (T) 7of3 2nd Midterm Exm (7 minutes)
When cube is drwn fter non-uniform scling hs been pplied, it will in generl be prllellipiped, not cube. If we ssume tht the function Wlk() is invoked with T s its rgument (the root of the DAG), there will be six prllellipipeds (possibly scled nd rotted cubes) drw t vrious plces on the screen. () [2 mrks] For ech of the six prllellipipeds, describe its position (x, y) on the screen, its orienttion (rotted or not), nd its shpe (scled or not). Vertex Position Orienttion Shpe () ( 5, 5) rotted scled (2) (, 5) rotted not scled (3) (+5, 5) rotted scled (4) (+5, ) rotted scled (5) (, +5) rotted not scled (6) (+5, +5) rotted scled (b) [8 mrks] Assume tht the viewing trnsformtion is just the identity mtrix with no perspective. Show the contents of the mtrix stck when the lst prllellipiped is being drwn using the Wlk() function described in lecture. The stck will contin five 4 4 mtrices with the current trnsformtion on the top of the stck nd four sved mtrices in the stck. Show ech of the symbolic expressions (vrious products of the mtrices stored in the DAG) for the five mtrices in the stck. () top: I T 2 T 5 S R (2) I T 2 T 5 S (3) I T 2 T 5 (4) I T 2 (5) bottom: I (the identity mtrix) CPSC 44 2-2 (T) 8of3 2nd Midterm Exm (7 minutes)
Question #4 [4 mrks 2 mrks ech] This question tests your generl knowledge of the concepts nd terminology introduced in the course. The following terms or people s nmes re possible nswers for the questions on subsequent pges. Use the number corresponding to term or nme below sninthe spce provided nswer if you think it is the best mtch for one of the concepts or terms on subsequent pges. Ech term my be used once, more thn once, or not t ll. () DAG (2) ffine (3) child (4) commuttive (5) convex (6) determinnt (7) heterogeneous (8) homogeneous (9) homotopy () indeterminnt () inverse (2) liner (3) non-uniform scling (4) orthogonl (5) orthogrphic (6) prent (7) permnent (8) point (9) point t infinity (2) qudrnt (2) qudruple (22) quternion (23) rottion bout x (24) rottion bout y (25) rottion bout z (26) sher (27) sibling (28) threded (29) trce (3) trnsltion (3) uniform scling (32) vector (33) virtul cmer (34) Weiler-Atherton CPSC 44 2-2 (T) 9of3 2nd Midterm Exm (7 minutes)
For ech sttement below, write the number of the term listed on the previous pge tht best fits into the missing spce mrked by ******** in the sentence. [2 mrks ech] _ 8 _() We often dd this fourth homogeneous coordinte in 3-D grphics to provide uniform mtrix representtion for the vrious trnsformtions tht re used. _8_(b) For point we dd fourth coordinte tht is one (). _32_(c) For vector we dd fourth coordinte tht is zero (). _9_(d) A second interprettion, insted of the one in prt (c), is tht when we dd fourth coordinte tht is zero () we obtin point t infinity. NOTE: The nswers to (c) nd (d) re interchngeble, but credit will not be given twice for the sme nswer. _2_(e) A weighted sum of vectors is liner combintion nd is itself lwys vector. _2_(f) A weighted sum of vectors whose weights sum to unity () is clled ffine. _ 5 _(g) A weighted sum of vectors whose weights re ll non-negtive nd sum to unity () is clled convex. _2_(h) A weighted sum of points must be ffine if the result is point. _28_(i) A threded n-ry tree is one in which the usul pointers from prents to children hve been replced by only two pointers, one to the first child nd one to the next sibling. _6_(j) The difference between tree nd DAG is tht some nodes my hve more thn one prent in DAG. _34_(k) The Weiler-Atherton clipping lgorithm is the most generl polygon clipping lgorithm of those discussed in the textbook. _33_(l) The virtul cmer is useful nlogy or metphor tht ssists in understnding vrious viewing nd perspective prmeters. CPSC 44 2-2 (T) of3 2nd Midterm Exm (7 minutes)
[2 mrks ech] _24_(m) A 4 4mtrix b b where 2 + b 2 = corresponds to rottion bout y trnsformtion. NOTE: An lternte nswer (worth only mrk) is #4, orthogonl. _3_(n) A 4 4mtrix b c corresponds to trnsltion trnsformtion. _3_(o) A 4 4mtrix b c corresponds to non-uniform scling trnsformtion. _3_(p) A 4 4mtrix corresponds to uniform scling trnsformtion. _26_(q) A 4 4mtrix corresponds to sher trnsformtion. _ 6 _(r) The re of polygon fter trnsformtion by mtrix M is relted to the originl re by the determinnt of the mtrix M. _22_(s) The quternion is mthemticl object hs four components nd cn be used to represent rottions in three-dimensionl spce. It ws discovered by Sir Willim Rowen Hmilton in 843 while wlking with his wife one evening long the Royl Cnl in Dublin. _4_(t) Two mtrices A nd B re commuttive if AB = BA. CPSC 44 2-2 (T) of3 2nd Midterm Exm (7 minutes)