Practice Exam 1.) To find a perpendicular vector to two other vectors, use the cross-product. Then normalize the resulting vector to get length (magnitude) of one. a = (.707, 0, .707) b = (-.707, 0, .707) .707 * .707 = .496 a x b = ((a.y)(b.z)-(a.z)(b.y))i + ((a.z)(b.x)-(a.x)(b.z))j + ((a.x)(b.y)-(a.y)(b.x))k = (0 - 0)i + (-.496 -.496)j + (0 - 0)k = (0, -.992, 0.0) |a x b| = sqrt(0+(-.992)^2 + 0) = .992 vector of length 1, perpindicular to a and b = (0, -.992/.992, 0) = (0,-1,0) 2.) To find an angle, use the dot product in the equation: a = (.707, 0, .707) b = (-.707, 0, .707) n = angle cos (n) = (a . b)/(|a||b|) (Assume .707*.707 = 0.5 exactly) |a| = sqrt (.707^2 + 0 + .707^2) = 1.0 |b| = sqrt ((-.707)^2 + 0 + .707^2) = 1.0 a . b = (a.x)(b.x) + (a.y)(b.y) + (a.z)(b.z) = .5 + 0 - .5 = 0 cos (n) = 0 , n = pi/2 = 90 degrees 3.)length of (1,2,3) = sqrt (1*1 + 2*2 + 3*3) = sqrt(14) 4.) (1,2,1) * | 0 1 0| |-1 0 0| = ((-1 * 2), (1 * 1), (1 * 1)) = (-2, 1, 1) | 0 0 1| Each element in the new vector is the sum of each element in the original vector times the column in the matrix. 5.) | 0 1 0| | 2 0 0| | 0 2 0| |-1 0 0| * | 0 2 0| = |-2 0 0| | 0 0 1| | 0 0 1| | 0 0 1| Remember that matrices must conform, e.g. # of elements in column of first matrix = # in row in second matrix. Then multiply each col in first by each row in second Line Drawing 1.) Bresenham's uses integer arithmetic, so it is fast and efficient. Bresenham's also approximates the line very well, by placing vertical jumps appropriately. 2.) In the algorithm: w = difference in x direction of two vertices = 5 - 0 = 5 h = difference in y direction of two vertices = 2 - 1 = 1 F(x, y) = (2 * h) - w if F(x,y) < 0 then F(x, y) += 2 * h else F(x,y) += 2(h-w) y++ so, if F(x,y) = -3, the next value will be F(x, y) += 2 * h F(x,y) = -3 + (2*1) = -1 3D Clipping: A.) V0 = (-1,-1,0) V1 = (1, 1, 1) xwmin = 0; xwmax = 2; ywmin = -1; ywmax = 1; zwmin = 0; zwmax = 1; Top.Bottom.Right.Left.Front.Back V0 0 . 0 . 0 . 1 . 0 . 0 V1 0 . 0 . 0 . 0 . 0 . 0 B.) Parametric equations: x = x0 + (x1 - x0)t = -1 + (1 -(-1))t = -1+2t y = y0 + (y1 - y0)t = -1 + (1 -(-1))t = -1+2t z = z0 + (z1 - z0)t = 0 + (1 -0)t = t C.) The only clipping you need to worry about is the one with V0 at the left limit, xwmin = 0 x = 0 = -1 + 2t => t = 1/2 y = -1 + 2(1/2) = 0 z = 1/2 => the line endpoints are: V0' = (0,0,1/2) V1 = (1,1,1) Fill Algorithms: Recursive boundary fill will check the spot (3,3) 2 times: Once when the function is called recursively on the spot, once from its right neighbor. It doesn't get checked by any cells in the grey area. ScanLine Algorithms: V0 = (3,6) V1 = (5,4) V2 = (3,2) A = V0-V2 B = V1-V2 C = V2-V0 a.) The edge data structures are: | ymax | x now | 1/m |, 1/m is 1/slope = 1/(rise/run) The y-bucket only holds edges that start on the scanline (yvalue): 6 | | 5 | | 4 | | - |6|4|-1| 3 | | A 2 | | - |6|3|0| - |4|3|1| 1 | | C B 0 | | b.) 5 | | - AEL - |6|3|0| - |6|4|-1| C A There should only be pairs on the active edge list, B has stopped, so it was discarded. Window to Viewport Transformations: V0 = (50,0) V1 = (200,400) xwmin = -100, xwmax = 200 ywmin = -200, ywmax = 400 umin = 500, umax = 1000 vmin = 0 vmax = 1000 The equations for the transformatin are: (xw - xwmin)/(xwmax - xwmin) = (xv - umin)/(umax - umin) (yw - ywmin)/(ywmax - ywmin) = (yv - vmin)/(vmax - vmin) xv1 = ((xw1 - xwmin)*(umax - umin)/(xwmax - xwmin)) + umin = (50 - (-100))*(1000 - 500)/(200 - (-100)) + 500 = 150 * 500 / (300) + 500 = 750 xv2 = ((xw2 - xwmin)*(umax - umin)/(xwmax - xwmin)) + umin = (200 - (-100))*(1000 - 500)/(200 - (-100)) + 500 = 300 * 500 / 300 + 500 = 1000 yv1 = ((yw1 - ywmin)*(vmax - vmin)/(ywmax - ywmin)) + vmin = (0 - (-200))*(1000 - 0)/(400 - (-200)) + 0 = 200 * 1000 / 600 = 333.333 yv2 = ((yw1 - ywmin)*(vmax - vmin)/(ywmax - ywmin)) + vmin = (400 - (-200))*(1000 - 0)/(400 - (-200)) + 0 = 600 * 1000 / 600 = 1000 V0' = (750, 333.33) V1' = (1000, 1000)