0% found this document useful (0 votes)
56 views8 pages

Difference of Dda and Beresenham

Bresenham's Line Generation algorithm is an efficient method for drawing lines on digital displays using only integer arithmetic, making it faster and more accurate than the Digital Differential Analyzer (DDA) algorithm, which relies on floating-point calculations. The algorithm works by determining pixel positions based on the closest y-coordinate to the theoretical line path, using a decision parameter to decide which pixel to plot next. The process involves iterating through the x-coordinates and adjusting the y-coordinate based on the calculated decision parameter, allowing for precise line rendering.

Uploaded by

fitahope10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views8 pages

Difference of Dda and Beresenham

Bresenham's Line Generation algorithm is an efficient method for drawing lines on digital displays using only integer arithmetic, making it faster and more accurate than the Digital Differential Analyzer (DDA) algorithm, which relies on floating-point calculations. The algorithm works by determining pixel positions based on the closest y-coordinate to the theoretical line path, using a decision parameter to decide which pixel to plot next. The process involves iterating through the x-coordinates and adjusting the y-coordinate based on the calculated decision parameter, allowing for precise line rendering.

Uploaded by

fitahope10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Bresenham’s Line Generation

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.

Digital Differential Analyzer Bresenhams Line Drawing Algorithm

DDA algorithm uses floating Bresenhams algorithm uses fixed points


Arithmetic
points i.e. Real Arithmetic. i.e. Integer Arithmetic.
DDA algorithm uses
Bresenhams algorithm uses only
Operations multiplication and division in its
subtraction and addition in its operations.
operations.

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

(Xk, yk) (Xk+1,yk)

Y=m(Xk+1)+b . . . . . . . ……. eq 1

d1=y – yk

d1=m(xk+1)+b – Yk ( from eq (1)) …..( 2)

And d2= (Yk+1) – Y

=(YK+1) – [m(Xk+1)+b]

=(YK+1) – m(Xk+1) – b …….(3)

The difference is given as

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

d1-d2 = 2m(Xk+1)-2Yk+2b –1 ………(4)

A decision parameter Pk can be obtained by substituting m= dy/dx in equation 4

= 2 dy/dx (Xk+1) – 2Yk + 2b – 1

= (2 dy(Xk+1)-2 dx.Yk + 2b.dx -dx )/dx

dx(d1-d2) = 2 dy(Xk+1)-2 dx.Yk + 2b.dx - dx

=2 dyXk+2 dy-2 dx.Yk + 2b.dx -dx

4
=2 dyXk- 2 dx.Yk + c where c=2dy+2b.dx-dx

Where, dx(d1-d2) = Pk and

c= 2 dy+ dx(2b-1)

Pk = 2 dyXk- 2 dx.Yk + c . . . . . . . . . . . . . . . . . . . … …(5 )

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.

At k+1 step, the value of Pk is given as

PK+1 = 2 dyXk+1- 2 dx.Yk+1 + c …………………………………..(6 ) (from 5)

Eq 6 – eq 5

Pk+1 – Pk = (2 dyXk+1- 2 dx.Yk+1 + c ) - (2 dyXk+2 dx.Yk + c)

= 2dy(Xk+1-Xk ) – 2 dx(Yk+1 – Yk ) ………….(7)

Since Xk+1 = Xk +1 The eqn 7 becomes

Pk+1 – Pk = 2dy(Xk +1 -Xk ) – 2 dx(Yk+1 – Yk )

= 2dy - 2 dx(Yk+1 – Yk )

Pk+1 = Pk + 2dy - 2 dx(Yk+1 – Yk ) ………………..( 8)

Where (Yk+1 – Yk) is either 0 or 1 based on the sign of Pk

If 0 then pk+1=pk+2dy

If 1 then pk+1=pk+2dy-2dx .

The starting parameter P0 at the pixel position (X0,Y0) is given as

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

dx=x1-x0, dy=y1-y0, P0 = 2dy –dx

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

Else, the next point is (Xk+1, Yk+1) and

Pk+1 = Pk + 2dy –2dx (step 3)

Step 5: iterate through step (4) dx times.

Or

Step 1: Enter the 2 end points for a line (X0,Y0), (X1,Y1).

Step 2: Plot (X0,Y0,colo).

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

the next point to be plotted is at (Xk+1, Yk)

Pk+1 = Pk + 2dy

Else the next point is (Xk+1, Yk+1)

Pk+1 = Pk + 2dy –2dx

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

The initial decision parameter P0 is

P0 = 2dy – dx = 2(8) – 10 = 16 – 10 = 6

The constants 2dy and 2dy-2dx are

2dy = 2(8) = 16 2dy-2dx = 2(8)- 2(10) =16 – 20=-4

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

You might also like