Presentation is loading. Please wait.

Presentation is loading. Please wait.

Exam 3 Review Questions. Q1: Rasterize the line (2, -1) to (4, -6) (hint: Bresenham)

Similar presentations


Presentation on theme: "Exam 3 Review Questions. Q1: Rasterize the line (2, -1) to (4, -6) (hint: Bresenham)"— Presentation transcript:

1 Exam 3 Review Questions

2 Q1: Rasterize the line (2, -1) to (4, -6) (hint: Bresenham)

3 Step 1: Put the line into octant “0” Add (-2, 1) to the endpoints: (0, 0) to (2, -5) Rotate (2, -5) into octant “0” X’=- x’=-y, y’=x x’= 5, y’=2 (5, 2)

4 Q1: Rasterize the line (2, -1) to (4, -6) (hint: Bresenham) Step 2: Apply Bresenham algorithm to each step Plot the endpoints. Then, y = mx+b m = (y1-y0)/(x1-x0) B = y0 – mx0 F(x,y) = mx + b – y If f(M) < 0,  E If f(M) >=0,  NE

5 Q1: Rasterize the line (2, -1) to (4, -6) (hint: Bresenham) Step 2: Apply Bresenham algorithm to each step Plot the endpoints. Then, Start with: P = (0,0) b = 0 m = 2/5 = 0.4 F(P) = mx + b – y = 0 M = P + (1, 0.5) = (1, 0.5) F(M) = mx – y = (0.4) -0.5 = -0.1 < -0 Therefore, select E (1, 0)

6 Q1: Rasterize the line (2, -1) to (4, -6) (hint: Bresenham) Step 2: Apply Bresenham algorithm to each step Plot the endpoints. Then: P = (1,0) b = 0 m = 2/5 = 0.4 F(P) = mx + b – y = 0 M = P + (1, 0.5) = (2, 0.5) F(M) = mx – y = (0.4)(2) – 0.5 = 0.8 – 0.5 = 0.3 Therefore, select NE (2, 1)

7 Q1: Rasterize the line (2, -1) to (4, -6) (hint: Bresenham) Step 2: Apply Bresenham algorithm to each step Plot the endpoints. Then: P = (2,1) b = 0 m = 2/5 = 0.4 F(P) = mx + b – y = 0 M = P + (1, 0.5) = (3, 1.5) F(M) = mx – y = (0.4)(3) – 1.5 = 1.2 – 1.5 = -0.3 Therefore, select E (3, 1)

8 Q1: Rasterize the line (2, -1) to (4, -6) (hint: Bresenham) Step 2: Apply Bresenham algorithm to each step Plot the endpoints. Then: P = (3,1) b = 0 m = 2/5 = 0.4 F(P) = mx + b – y = 0 M = P + (1, 0.5) = (4, 1.5) F(M) = mx – y = (0.4)(4) – 1.5 = 1.6 – 1.5 = 0.1 Therefore, select NE (4, 2)

9 Q1: Rasterize the line (2, -1) to (4, -6) (hint: Bresenham) Step 3: Rotate the points back into the unrotated quadrant Points are: (0,0), (1,0), (2,1), (3,1), (4, 2), (5,2) We want to put (x’,y’)=(5,2) back at (x,y)=(2, -5) where it came from. To do this, we see that x = y’ and y = -x’ (0,0)  (0,0) (1,0)  (0,-1) (2,1)  (1, -2) (3,1)  (1, -3) (4,2)  (2, -4) (5,2)  (2, -5)

10 Q1: Rasterize the line (2, -1) to (4, -6) (hint: Bresenham) Step 3: Rotate the points back into the unrotated quadrant Points are: (0,0), (1,0), (2,1), (3,1), (4, 2), (5,2) We want to put (x’,y’)=(5,2) back at (x,y)=(2, -5) where it came from. To do this, we see that x = y’ and y = -x’ (0,0)  (0,0) (1,0)  (0,-1) (2,1)  (1, -2) (3,1)  (1, -3) (4,2)  (2, -4) (5,2)  (2, -5)

11 Q1: Rasterize the line (2, -1) to (4, -6) (hint: Bresenham) Step 4: Translate the points back to their original location Rotated points are: (0,0), (0,-1), (1,-2), (1,-3), (2, -4), (2,-5) In step 1, we added (-2, 1) to translate the endpoint (2, -1) to the origin. Now move it back so that the endpoints are at their original points: (2, -1) and (4, -6) This means adding (2, -1) to all of the points.

12 Q1: Rasterize the line (2, -1) to (4, -6) (hint: Bresenham) Step 4: Translate the points back to their original location Rotated points are: (0,0), (0,-1), (1,-2), (1,-3), (2, -4), (2,-5) Add (2, -1) to everything: (2,-1), (2,-2), (3,-3), (3,-4), (4,-5), (4,-6)

13 Q1: Rasterize the line (2, -1) to (4, -6) (hint: Bresenham) Step 4: Translate the points back to their original location Rotated points are: (0,0), (0,-1), (1,-2), (1,-3), (2, -4), (2,-5) Add (2, -1) to everything:

14 Q2: Fill in pseudocode for the Bresenham algorithm (assume the line is in the initial octant) To plot something, say plot(x,y) plotLine(x0, y0, x1, y1) { … for (n=1 to x1) { … } … }

15 Q2: Fill in pseudocode for the Bresenham algorithm (assume the line is in the initial octant) To plot something, say plot(x,y) plotLine(x0, y0, x1, y1) { plot(x0,y0); dx=x1-x0; dy=y1-y0; slope=dy/dx; current_x = 0; current_y = 0; for (n=1 to x1) { Mx = current_x + 1; My = current_y + 0.5; f_of_M = slope*Mx - My; if (f_of_M < 0) // Plot E { current_x = current_x + 1; current_y = current_y; plot(current_x, current_y); } else // Plot NE { current_x = current_x + 1; My = current_y + 1; plot(current_x, current_y); } } plot(x1, y1); }

16 Q3A: Match the shading method to the technique for handling normals Shading methods: 1: Flat Shading 2: Goraud Shading 3: Phong Shading 4: Bump Mapping Normal Handling: A: Only the first normal of the triangle is used to calculate lighting in the entire triangle B: Normals are interpolated across the surface, and the light is computed at each fragment C: Normals are stored in a texture and used instead of Phong normals D: The light intensity is computed at each vertex and interpolated across the surface

17 Q3A: Match the shading method to the technique for handling normals Shading methods: 1: Flat Shading 2: Goraud Shading 3: Phong Shading 4: Bump Mapping Normal Handling: A: Only the first normal of the triangle is used to calculate lighting in the entire triangle B: Normals are interpolated across the surface, and the light is computed at each fragment C: Normals are stored in a texture and used instead of Phong normals D: The light intensity is computed at each vertex and interpolated across the surface 1-A, 2-D, 3-B, 4-C

18 Q3A: Which of these statements are true regarding cube maps in WebGL? 1.Objects can be concave 2.No reflections between objects are supported 3.The implementation assumes that the environment is close to the object 4.You can use the same map on an object if the viewer moves. 5.Cube maps support self-reflections on an object 6.You need a reflection map for each object

19 Q3A: Which of these statements are true regarding cube maps in WebGL? 1.Objects can be concave 2.No reflections between objects are supported 3.The implementation assumes that the environment is close to the object 4.You should use the same map on an object if the viewer moves. 5.Cube maps support self-reflections within an object 6.You need a reflection map for each object 1:F, 2:T, 3:F, 4:F, 5:F, 6:T

20 Q4: Texture Filtering Suppose we have following texture of greyscale values: T(4,5)=0.25, T(4,4)=0.47, T(5,5)=0.98, T(5,4)=0.45 Find the Texture value at (4.2,4.7) using Nearest Neighbor and Bilinear Interpolation.

21 Q4: Texture Filtering Suppose we have following texture of greyscale values: T(4,5)=0.25, T(4,4)=0.47, T(5,5)=0.98, T(5,4)=0.45 Find the Texture value at (4.2,4.7) using Nearest Neighbor and Bilinear Interpolation. Nearest Neighbor: (4.2, 4.7) is closer to (4,5), so T(4.2,4.7)=0.25

22 Bilinear Interpolation Let (u’,v’) = (0.2, 0.7) Interpolation in X: T top = (1-0.2)*T(4,5)+(1-0.8)*T(5,5) =0.396 T bottom =(1-0.2)*T(4,4)+(1-0.8)*T(5,4)= 0.466 Interpolation in Y: =(1-0.3)* T top + (1-0.7)* T bottom =0.417 Texture value at (4.2, 4.7) is 0.417


Download ppt "Exam 3 Review Questions. Q1: Rasterize the line (2, -1) to (4, -6) (hint: Bresenham)"

Similar presentations


Ads by Google