CS计算机代考程序代写 Ans. to Tut 1

Ans. to Tut 1
Qn 1
a) The tables are as follows:
Vertex Table
Edge Table
Face Table
Attribute Table
a(0,0,0)
E1: a,b
F1: a b j f g
(𝑘𝑘 ,𝑘𝑘 ,𝑘𝑘 )= 𝑎𝑎,𝑟𝑟𝑟𝑟𝑟𝑟 𝑎𝑎,𝑏𝑏𝑏𝑏𝑏𝑏𝑟𝑟 𝑎𝑎,𝑔𝑔𝑟𝑟𝑟𝑟𝑟𝑟𝑔𝑔
F1:
(0.5,0.5,0.5) (𝑘𝑘𝑏𝑏,𝑟𝑟, 𝑘𝑘𝑏𝑏,𝑏𝑏, 𝑘𝑘𝑏𝑏,𝑔𝑔) =. .. …
b(10,0,0)
E2: b,j
F2: b c d j
F2 …
c(10,0,-20)
E3: j,f
F3: a g h i
F3 …
d(10,10,-20)
E4: f,g
F4: i h e d c
F4 …
e(5,15,-20)
E5: g,a
F5: j d e f
F5 …
f(5,15,0)
E6: b,c
F6: g f e h
F6 …
g(0,10,0)
E7: j,d
F7: a i c b
h(0,10,-20)
E8: f,e
i(0,0,-20)
E9: g,h
j(10,10,0)
E10: a,i
E11: i,c
E12: c,d
E13: d,e
E14: e,h
E15: h,i
The face table is expressed using vertices. Alternatively, it may be expressed using edges.
The attributes for each face may include for example,
ambient reflection coefficient 𝑘𝑘𝑎𝑎, diffusion reflection coefficient 𝑘𝑘𝑏𝑏, specular reflection coefficient 𝑘𝑘𝑠𝑠, specular reflection exponent 𝑛𝑛𝑠𝑠, transparency coefficient 𝛼𝛼, etc.
Note that in the Face Table, some faces are “CW” and some “CCW” as seen by us. because it should look “CCW” when seen by an observer outside. So “hidden faces” should be “CW”.
� ����⃑ �����⃑
b) 𝑁𝑁=�𝑓𝑓𝑓𝑓×𝑓𝑓𝑓𝑓�=|(0,0,−20)×(−5,−5,0)|=|(−100,100,0)|=�− 1 , 1 ,0�
c) To find the outward normal, we can for example cross vector jd with vector jf.
This gives
𝑖𝑖𝑗𝑗𝑘𝑘
(A, B, C) = (0, 0, -20) × (-5, 5, 0) = � 0 0 −20� = (100,100,0)
−5 5 0
1
√2 √2

Thus we have
100 X + 100 Y + D = 0
Put in any vertex, say j = (10, 10, 0) gives D = -2000. Thus the plane equation is
X + Y – 20 = 0
Note
-X – Y + 20 = 0 is incorrect, because you should make sure that the normal (A, B, C) is computed in a way that iff
X + Y – 20 > 0
the point (X, Y, Z) is outside and vice versa.
𝐴𝐴𝑖𝑖𝑥𝑥𝑝𝑝+𝐵𝐵𝑖𝑖𝑦𝑦𝑝𝑝+𝐶𝐶𝑖𝑖𝑧𝑧𝑝𝑝+𝐷𝐷𝑖𝑖 <0 𝑖𝑖=1,...,7 then the point is inside the object (otherwise it is outside the object). e) The above only works for convex objects. For concave objects, subdivide into 𝑚𝑚 convex subparts. Then if and only if (𝑥𝑥𝑝𝑝 , 𝑦𝑦𝑝𝑝 , 𝑧𝑧𝑝𝑝 ) is inside one of the 𝑚𝑚 subparts, the point is inside the object. In general, it may be difficult to subdivide a complex object into convex sub- objects. A general technique for testing whether a point is inside/outside is the inside-outside test. f) Collision detection in a virtual reality walkthrough. Discuss: Can you think of another practical or emerging application? Qn 2 a) d) Compute the plane equation of each face 𝐴𝐴𝑖𝑖𝑥𝑥+𝐵𝐵𝑖𝑖𝑦𝑦+𝐶𝐶𝑖𝑖𝑧𝑧+𝐷𝐷𝑖𝑖 =0 𝑖𝑖=1,...,7 where(𝐴𝐴𝑖𝑖,𝐵𝐵𝑖𝑖,𝐶𝐶𝑖𝑖) istheoutwardsurfacenormal. Given a point (𝑥𝑥𝑝𝑝, 𝑦𝑦𝑝𝑝, 𝑧𝑧𝑝𝑝), if and only if 2 vertex_table [0].X = 10; vertex_table [0].Y = 0; vertex_table [0].Z = 0; // b(10, 0, 0) vertex_table [1].X = 10; vertex_table [1].Y = 4; vertex_table [1].Z = 0; // c (10, 4, 0) vertex_table [2].X = 10; vertex_table [2].Y = 4; vertex_table [2].Z = 5; // g (10, 4, 5) vertex_table [3].X = 10; vertex_table [3].Y = 0; vertex_table [3].Z = 5; // f (10, 0, 5) edge_table [0][0] = 0; edge_table [1][0] = 1; edge_table [2][0] = 2; edge_table [3][0] = 3; face_table [0] [0] = 0; face_table [0][3] = 3; // 𝑏𝑏𝑏𝑏 // 𝑏𝑏𝑓𝑓 b) efghe abcda edge_table [0][1] = 1; edge_table [1][1] = 2; edge_table [2][1] = 3; edge_table [3][1] = 0; face_table [0][1] = 1; face_table [0][2] = 2; face_table [0][4] = 0; To represent the whole object, the preferred way is to use 3 quadrilateral meshes, that is, use a separate quadrilateral mesh for both the top and the bottom face. One example is gluCylinder. To close the ends of the cylinders, we use two gluDisk commands. Thus there are three quadrilateral meshes. 𝑖𝑖𝑗𝑗𝑘𝑘 c) (𝐴𝐴,𝐵𝐵,𝐶𝐶)=𝑏𝑏𝑐𝑐×�𝑏𝑏��𝑓𝑓�⃑=�−10 21 0�=(105,50,0) ����⃑ 005 105𝑋𝑋 + 50𝑌𝑌 + 𝐷𝐷 = 0 Put in (X, Y, Z) = (10, 4, 0) ⇒ D = -1250 The equation is 105𝑋𝑋 + 50𝑌𝑌 − 1250 = 0 ⇒ 21𝑋𝑋 + 10𝑌𝑌 − 250 = 0 d) Using mesh has the advantage over table that there is no need to specify the edge and face tables. Thus it saves memory. Qn 3 a) The parametric form samples uniformly across the parameters. This gives a set of pixels that appear continuous when displayed in screen coordinates. On the contrary, without techniques to keep track of the slope of the curve, the non- parametric form will sample uniformly in X (or Y), which gives a non-uniform sampling across Y (or X). When displayed, this results in some pixels along the curve that are not sampled (gap in the curve). // 𝑓𝑓𝑓𝑓 // 𝑓𝑓𝑏𝑏 3 b) Let �𝑟𝑟𝑍𝑍�2/𝑠𝑠1 = 𝑠𝑠𝑖𝑖𝑛𝑛2 𝜑𝜑 This gives 𝑍𝑍 = 𝑟𝑟𝑧𝑧 𝑠𝑠𝑖𝑖𝑛𝑛𝑠𝑠1 𝜑𝜑 𝑟𝑟𝑋𝑋 2/𝑠𝑠2 𝑟𝑟𝑌𝑌 𝑠𝑠2/𝑠𝑠1 (� �𝑧𝑧 +� �2/𝑠𝑠2) =𝑏𝑏𝑐𝑐𝑠𝑠 𝜑𝜑 ⇒� � +� �2/𝑠𝑠2 =(𝑏𝑏𝑐𝑐𝑠𝑠𝜑𝜑) 2 𝑟𝑟𝑋𝑋 2/𝑠𝑠2 𝑟𝑟𝑌𝑌 2𝑠𝑠1/𝑠𝑠2 𝑥𝑥𝑦𝑦 𝑥𝑥2/𝑠𝑠2𝑦𝑦 Let �𝑟𝑟𝑋𝑋 �2/𝑠𝑠2 = (𝑏𝑏𝑐𝑐𝑠𝑠 𝜑𝜑)2𝑠𝑠1/𝑠𝑠2 𝑏𝑏𝑐𝑐𝑠𝑠2 𝜃𝜃 and �𝑟𝑟𝑌𝑌 � = (𝑏𝑏𝑐𝑐𝑠𝑠 𝜑𝜑)2𝑠𝑠1/𝑠𝑠2 𝑠𝑠𝑖𝑖𝑛𝑛2 𝜃𝜃 𝑥𝑥𝑦𝑦 This gives 𝑋𝑋=𝑟𝑟𝑥𝑥𝑏𝑏𝑐𝑐𝑠𝑠𝑠𝑠1𝜑𝜑𝑏𝑏𝑐𝑐𝑠𝑠𝑠𝑠2𝜃𝜃 and 𝑌𝑌=𝑟𝑟𝑦𝑦𝑏𝑏𝑐𝑐𝑠𝑠𝑠𝑠1𝜑𝜑𝑠𝑠𝑖𝑖𝑛𝑛𝑠𝑠2𝜃𝜃 0 ≤ 𝜃𝜃 < 2 𝜋𝜋 − 𝜋𝜋2 ≤ 𝜑𝜑 < 𝜋𝜋2 Physical meaning: Consider a globe: 𝜑𝜑 latitude 𝜃𝜃 longitude Qn 4 double sgn (double t ) { if (t > 0) return 1.0; else if (t < 0) return -1.0; else return 0.0; } void calculate_mesh (double s1, double s2) // calculate the parameters of the sphere mesh { double ta, tb, tc, td; for (int i=0; i