Algorithmmmmmmmm

You might also like

Download as pdf
Download as pdf
You are on page 1of 2
f=) Aarvar an Sseare Componens 3.1.2, Bresenham’s Algorithm ‘The above DDA algorithm is certainly an improvement over the direct use ofthe line equations since it eliminates many of the complicated calculations. However, stil it requires some amount of floating point arithmetic for each of the pixel positions. This is still more expensive in terms of the toal Computation time since a large number of points need to be calculated for each ofthe Fine segments a shown in Example 3.1. Bresenham's method is an improvement over DDA since it completely eliminates the floating point arithmetic except for the initial computations. Al other computations are fully integer arithmati and hence is mote efficient for raster conversion {As for the DDA algorithm, stat from the same line equation and the same parameters. The basic argument for positioning the pixel here is the amount of deviation by which the calculated positon is from the aciual position obtained by the line equation in terms of dy and dy shown in Fig. 3:3. °@ Fig. 33. The Position of Individuat Pixels for Calewlation using Bresenham Procedure Let the current position be (X;, ¥)) at the ith position as shown in Fig. 3.3. Each of the circles in Fig. 3.3 represent the pixels in the successive positions. Then XyeXel 68) Also Yi=mX,+e oo) and Yam; +e 6.10) ‘These are shown in Fig. 3.3. Let d, and d be two parameters, which indicate where the next pixel is to be located. If dj is greater than d, then the y pixel is to be located at the +1 position else, it remains at the same position as previous location. d= ¥-Y=mX+ Dee-¥, eu 42 ¥,,,-Y=¥,,,-mX%+D-c @.12) y= dy = MK, + 1) 2Y, 4 20-1 G13) ‘Equation 3.13 still contains more computations and hence we would now define another parameter P which would define the relative position in terms of d, ~ dy P= (dy —ds) AX G14 Computer Graphics C=] Pi = AY X,— 20K ¥, +b G15) where b= 2 AY + 2c AK ~ AX ‘Similarly we can write Prat = 2AY (X + 1) = 2AX Yu +B G.16) ‘Taking the difference of two successive parameters, we can eliminate the constant terms from Bg. 316, to get Eg. 3.17. Py ~ P= 2AY ~ 2AX (Yq) — ¥) G17 ‘The same can also be writen as Piyy = P+ 2AY — 2AX (Y,.) — ¥) G.18) ‘The same can also be written as Pyy=Pi+24Y when Yj.) = ¥) G19) Py = P,+2AY-2AX when ¥,y = YL 820) From the start point (x, 94) yyemayte ay oi Substituting this in Eq. 3.15 and simplifying, we get P, = 2A¥~ ax 21 Hence from Eq. 3.17, when P, is negative, then the next pixel location remains the same as previous one and Eq. 3.19 becomes valid. Otherwise, Eq. 3.20 becomes valid Using these equations it is now possible to develop the algorithm for drawing the line on the screen ss shown in the flowchart (Fig. 3.4). The procedure just described is forthe ease when m > 1. The Frocedure can be repeated for the case when m < Iby interchanging X and Y similar to the DDA Algorithm. Example 32 Repeat the calculations for Example 3.1 using Bresenham’s algorithm, ‘Table 3.2 x ¥ a 8 » 39 2 40 2 40 2 87 a 24 3 2 2 407 8 26 273 a 2 139 4 28 5 45 » ed 46 30 46 31 a (Contd

You might also like