Difference of Dda and Beresenham
Difference of Dda and Beresenham
The Bresenham algorithm is another incremental scan conversion algorithm. The big
advantage of this algorithm is that, it uses only integer calculations.
Difference Between DDA Line Drawing Algorithm and Bresenhams Line Drawing
Algorithm.
1
DDA algorithm is rather slowly Bresenhams algorithm is faster than DDA
than Bresenhams algorithm in algorithm in line drawing because it
Speed line drawing because it uses real performs only addition and subtraction in
arithmetic (floating-point its calculation and uses only integer
operations). arithmetic so it runs significantly faster.
DDA algorithm is not as accurate
Accuracy & Bresenhams algorithm is more efficient
and efficient as Bresenham
Efficiency and much accurate than DDA algorithm.
algorithm.
DDA algorithm can draw circles
Bresenhams algorithm can draw circles
and curves but that are not as
Drawing and curves with much more accuracy than
accurate as Bresenhams
DDA algorithm.
algorithm.
DDA algorithm round off the Bresenhams algorithm does not round off
Round Off coordinates to integer that is but takes the incremental value in its
nearest to the line. operation.
DDA algorithm uses an
Bresenhams algorithm is less expensive
enormous number of floating-
Expensive than DDA algorithm as it uses only
point multiplications so it is
addition and subtraction.
expensive.
Moving across the x axis in unit intervals and at each step choose between two different
y coordinates.
For example, as shown in the following illustration, from position (2, 3) you need to
choose between (3, 3) and (3, 4). You would like the point that is closer to the original
line.
2
At sample position Xk+1, the vertical separations from the mathematical line are labeled
as dupper and dlower.
The pixel positions on line can be identified by doing sampling at unit x intervals.
The process of sampling begins from the pixel position (X0,Y0) and proceeds by
plotting the pixels whose ‘Y’ value is nearest to the line path.
If the pixel to be displayed occurs at a position (X k, Yk) then the next pixel is either
at (Xk+1,Yk) or (Xk+1,Yk+1) i.e, (3,2) or (3,3)
The ‘Y’ coordinate at the pixel position Xk +1 can be obtained from
Y=m(Xk+1)+b . . . . . . . . . . ……. eq 1
the separation between (Xk+1,Yk) and (Xk+1,Y) is d1 and the separation between (Xk+1,Y)
and (Xk+1, Yk+1) is d2 then
d1 = y – yk and d2 = (Yk+1) – Y
3
(Xk+1, yk+1)
(Xk, yk+1)
d2
P0 d1
Y=m(Xk+1)+b . . . . . . . ……. eq 1
d1=y – yk
=(YK+1) – [m(Xk+1)+b]
d1-d2 = m(Xk+1)+b-Yk-[(Yk+1)-m(Xk+1)-b]
=m(Xk+1)+b-Yk-(Yk+1)+m(Xk+1)+b
=m(Xk+1)+b-Yk-Yk-1+m(Xk+1)+b
4
=2 dyXk- 2 dx.Yk + c where c=2dy+2b.dx-dx
c= 2 dy+ dx(2b-1)
The value of c is constant and is independent of the pixel position. It can be deleted in the
recursive calculations, of for Pk
if d1 < d2 (i.e, Yk is nearer to the line path than Yk+1) then, Pk is negative, then a lower
pixel (Yk) is plotted else, an upper pixel (Yk+1) is plotted.
Eq 6 – eq 5
= 2dy - 2 dx(Yk+1 – Yk )
If 0 then pk+1=pk+2dy
If 1 then pk+1=pk+2dy-2dx .
P0 = 2dy – dx ………………………(9)
Bresenham’s algorithm
5
Step 1: Enter the 2 end points for a line and store the left end point in (X0,Y0).
Step 2: Plot the first point be loading (X0,Y0) in the frame buffer.
Setp 3: determine the initial value of the decision parameter by calculating the constants
dx, dy, 2dy and 2dy-2dx as
Step 4: for each Xk, conduct the following test, starting from k= 0
If Pk <0, then the next point to be plotted is at (Xk+1, Yk) and, Pk+1 = Pk + 2dy
Or
Setp 3: determine the initial value of the decision parameter by calculating the constants
dx=x1-x0, dy=y1-y0, P0 = 2dy –dx
for k=0 to dx do
If Pk <0, then
Pk+1 = Pk + 2dy
Endfor
6
Example
Let the given end points for the line be (30,20) and (40, 28)
dy = y1 – y0 = 28 – 20 = 8
dx = x1 – x0 = 40 – 30 = 10
m = 0.8
P0 = 2dy – dx = 2(8) – 10 = 16 – 10 = 6
The starting point (x0, y0)=(30,20) and the successive pixel positions are given in the
following table
K P (X ,Y )
k k+1 k+1
0 6 (31,21)
1 2 (32,22
2 -2 33,22
3 14 34,23
4 10 35,24
5 6 36,25
7
6 2 37,26
7 -2 38,26
8 14 39,27
9 10 40,28