14959_DDA Line | Line (Geometry) | Equations

DDA Line-drawing Algorithm

By Thiyagaraaj M

DDA Line Drawing Algorithm
By Thiyagaraaj M Contents 1. Line Equation 2.DDA Line Algorithm 3.Advantage & Disadvantage 4.Algorithm : A naïve line-drawing algorithm 5. C Programming Code 6.Example 7. References

http://i.thiyagaraaj.com/

Page - 1

here. slope m: m = ( y2 .( 4 ) http://i.y1) / ( x2 .thiyagaraaj.y1) -----(1) Determine the values for the slope m and y intercept b with the following calculation.DDA Line-drawing Algorithm By Thiyagaraaj M Line Equation The Cartesian slop-intercept equation for a straight line is y=mx+b with m->slope b->y intercept The 2 end points of a line segment are specified at a position(x1.( 5 ) -----. Dx Similarly x interval Dx from the equation m = Dy / Dx Dx = Dy /m ------.x1 ) m= Dy / Dx y intercept b b=y1-mx1 Algorithms for displaying straight line based on this equation y interval Dy from the equation -----(2) ------ (3) • • m= Dy / Dx Dy= m.2 .com/ Page .

Step : 1 If the slope is less than or equal to 1 .thiyagaraaj.com/ Page . m->any real numbers between 0 and 1 Calculate y values must be rounded to the nearest integer Step : 2 If the slope is greater than 1 .the unit x intervals Dx=1 and compute each successive y values. Dx=1 m = Dy / Dx m = ( y2-y1 ) / 1 m = ( yk+1 – yk ) /1 yk+1 = yk + m • • • -------. http://i.DDA Line-drawing Algorithm By Thiyagaraaj M Line DDA Algorithm: • • • The digital differential analyzer(DDA) is a scan conversion line algorithm based on calculation either Dy or Dx.( 6 ) subscript k takes integer values starting from 1.( 7 ) • Equation 6 and Equation 7 that the lines are to be processed from left end point to the right end point.3 . The line at unit intervals is one coordinate and determine corresponding integer values nearest line for the other coordinate. Dy=1 m= Dy / Dx m= 1/ ( x2-x1 ) m = 1 / ( xk+1 – xk ) xk+1 = xk + ( 1 / m ) ------. Consider first a line with positive slope.for the first point and increment by 1 until the final end point is reached.the roles of x any y at the unit y intervals Dy=1 and compute each successive y values.

-------. the starting point at the right Dx=-1 m= Dy / Dx m = ( y2 – y1 ) / -1 yk+1 = yk .( 9 ) Equation 6 and Equation 9 used to calculate pixel position along a line with –ve slope.4 .com/ Page . Advantage: faster method for calculating pixel position then the equation of a pixel position. Dy=-1 m= Dy / Dx m = -1 / ( x2 – x1 ) m = -1 / ( xk+1 – xk ) xk+1 = xk + ( 1 / m ) -------.( 8 ) Step : 4 Here. http://i.m Iintervals Dy=1 and compute each successive y values.thiyagaraaj.DDA Line-drawing Algorithm By Thiyagaraaj M Step : 3 If the processing is reversed. Y=mx+b Disadvantage: The accumulation of round of error is successive addition of the floating point increments is used to find the pixel position but it take lot of time to compute the pixel position.

float xincrement. putpixel(round(x).y1 for x from x1 to x2 { y = y1 + (dy) * (x .int ya.2) for(k=0.DDA Line-drawing Algorithm By Thiyagaraaj M Algorithm : A naïve line-drawing algorithm dx = x2 . yincrement=dy/(float)steps.round(y).k<steps.y=ya. putpixel(round(x).x=xa.steps.x1)/(dx) pixel(x.dy=yb-ya.yincrement. y+=yincrement.com/ Page . if(abs(dx)>abs(dy)) steps=abs(dx).2).5 .k.thiyagaraaj.int xb.x1 dy = y2 .k++) { x+=xincrement. xincrement=dx/(float)steps.int yb) int dx=xb-xa.round(y). } } { http://i. else steps=abs(dy). y) } C Programming void linedda(int xa.

10) dx=6 dy=8 xincrement=6/8=0.k<8.75+0.com/tutorials/computer-graphics-programs-using-c-programming little drops .thiyagaraaj.25 yincrement=2+1=3 2=>(3.DDA Line-drawing Algorithm By Thiyagaraaj M Example: xa.com/tutorials/computer-graphics little drops . little drops .2) for(k=1.2) xb.75 yincrement=8/8=1 1) for(k=0.3) 2) it will be incremented upto the final end point is reached.yb=>(8.Computer Graphics 2.6 .DDA Line Algorithm http://i.Computer Graphics Using C Programming http://i. References References 1.k++) xincrement=0.thiyagaraaj.com/ Page .thiyagaraaj.ya=>(2.com/articles/articles/dda-line-algorithm http://i. 3.75=1. http://i.k<8.k++) xincrement=1.50+0.thiyagaraaj.75=2.50 yincrement=1+1=2 1=>(2.

Sign up to vote on this title
UsefulNot useful