Lecture Note
University
University of California San DiegoCourse
CSE167 | Computer GraphicsPages
8
Academic year
2023
Jake Tomson
Views
0
Camlin Page Date / / UNIT . II Output Primitives Points and Lines Output primitives are the basic building blocks needed to draw the images eg lines, circle, ellipsee, polygon etc There are two algorithms for drawing a line They are :- DDA line algorithm Bresenham's line algorithms The cartesian slope intercept equation for a straight line is y= mn +b / where m - shope of the line b= constant / y intercept. . If the end points of a line are (n.y.) and (nz,yz) the slope m can be calculated as m = y2 n2 ie m = By 2 An based on the line egn Algorithms for displaying straight lines are 1 and slope equi 2 Dy = m x 3
Date / / on = Dy 4 m If the slope . /ml the direction of line is moving towards the horizontal direction If the slope /ml = 1 , then the direction will be straight ( ie D x = Dy / straight line) If the slope /m/ >1, the direction of line is moving to wards the vertical direction. DDA algorithm (Digital Differential Analyser) DDA is a scan conversion line algorithm based on calculating either Dy or D n using the equation Dy = MAn and on = Dy m We sample the line at unit intervals in one coordinate and determine the corresponding integer values nearest the line path for the other coordinates. Consider a line with the positive slope as in the figure y y' n! n2
case 1: if m < -1, then n - coordinate changes in unit intervals ie x K+1 xk + I to find y coordinate, m = YK+1 - -y, K n - x K+1 K = y - Yk K+1 n + n K K m = Ykti - Yk YK+1 = Yk tm 5 here y moves in slope intervals case 2: for lines with a positive slope greater than! we reverse the roles of n andy ie if m 71 , then y coordinate changes
Camlin Page Date / / in unit interval. ie Ykti Yk + I m y yk k +1 x KH xk = Yk + I YK nk+1 nk m = I x K+1 xk n x = 7 1 6 K+1 K m NOTEX egn 5 and 6 are based on the assumption that the lines are processed from left endpoint to right endpoint. If this processing is reversed t , 80 that the starting endpoint is at the right, then either we have An = and yk+ = YK m OR Dy = - 1 and n = n 1 k+1 K m in case 2 , the ycoordinate changes in unit intervals and n coordinate changes in 1/m intervals.
Date case 3: if m = 1, n and y coordinate changes in unit intervals x k+1 = xk 41 YK+I = Yk + 1 m7' m=1 yme, Algorithm 1) Read the x coordinates of lines as na, ya, xb yb 2) Assign the difference between nb and nia todx " jb and yo a tody 3) Initialize x and y as n a and ya respectively.
Camlin Page Date / / 4) If the absolute difference value of dn > dy, then assign steps as absolute value of dx otherwise assign steps as absolute value of dy. 5) set n increment as dx divided by steps 6) and y increment as dy divided by stepe. Plot pixel with parameters n and y. 7) Assign 'K' as 0 and until K< steps. 7.a) add n with x increment to obtain new value of n 7.b) add y with y increment to obtain new value of 7.c) increment value of K. 7.d) plot pixel with parameters as new value of n andy. example Ques if the coordinates (0,0) and (4,5) m = yb - ya xb - xa = 5 - O 4-0 5 7 1 ie 1.25 > / 4 m > + Yati = ya + 1
Date ya+ = 0+1 = I Nati xa + 1 m = 0 + 4 5 nati = 0.8 check d no greater and then 5 x y n y coordinate plotted plotted 0 0 0 0 (0,0) 8 1 1 is (1,1) 1.6 2 2 12 (2,2) 2.4 3 2 3 of (2,3) 3.2 4 3 4 (3,4) 4 5 4 5 (4,5) na ya Ques If the coordinate points are (22,3) and (12,8) 2b/yb m = yb - ya tx x b - na = 8-3 - = 5 /10 0.5 12-2 10 /10 le 2 0.5 L L 1
Date / / mL/ xa+1 = x + I for incrementing 2+1 = 3 dn 10 = / no-gsteps 10 Ya+i = ya m dy 5=0.5 11, 3+ 1 no sseeps 10 2 ya+i 3-5 dn = 1.0 and dy = 5 so no . of steps = 10 n y n y coordinate plotted plotted 16% 2 3 2 3 (2,3) 20 3 3.5 3 4 (3,4) 4 4 4 4 (4,4) 5 4.5 5 5 (5,5) 6 5 6 5 (6,5) 7 5.5 7 6 (7,6) 8 6 8 6 25 (8,6) 9 6.6 9 7 (9,7) 10 7 10 7 (10,7) 11 7.5 11 8 (11,8) 12 8 12 8 ( (12,8)
Output Primitives and DDA Algorithm
Please or to post comments