Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Bresenham'S Line Drawing Algorithm

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

BRESENHAM’S

LINE DRAWING ALGORITHM

Rasmi M
Assistant Professor
Department of Computer Science and Applications
St. Mary’s College Thrissur
INTRODUCTION

 Developed by Jack Bresenham.

 Raster line-generating algorithm.

 Scan conversion takes place using only incremental


integer calculations.

Bresenham’s Line Drawing Algorithm, Rasmi M, St.Mary’s College


 Accurate and efficient than DDA line drawing
algorithm.

 Guarantees connected (gap-less) lines where


each point is drawn exactly 1 time.

 Also known as the midpoint line algorithm.

Bresenham’s Line Drawing Algorithm, Rasmi M, St.Mary’s College


 The computer has to select pixels to draw a line.
 It has to select two points and then draw a line between them.
 It also needs some parameters for computations.
 Groupof pixels look like a matrix having x and y axis.

Bresenham’s Line Drawing Algorithm, Rasmi M, St.Mary’s College


P

 We need a decision parameter todecide which pixel to choose.

Bresenham’s Line Drawing Algorithm, Rasmi M, St.Mary’s College


DERIVATION

 Starting from the left endpoint (x0,y0) of a given line, we step to


each successive column and plot the pixel whose scan-line y value
is close to the line path.
 At the sample position xk+1 the vertical separations from the
line are labelled dupper and dlower.

Bresenham’s Line Drawing Algorithm, Rasmi M, St.Mary’s College


 The y coordinate on the line at xk+1 is calculated as
y=(mx+c)
 We know that the slope m=Δy/Δx

 Then,
dlower= y-yk
dupper=(yk+1)-y

 Replacing the value of y ;

dlower=m(xk+1)+c-yk
dupper=(yk+1)-m(xk+1)-c

Bresenham’s Line Drawing Algorithm, Rasmi M, St.Mary’s College


 Now we substract

dlower-dupper=2m(xk+1)-2yk+2c-1 .

Replacing m;
Δx(dlower-dupper)=Δx(2Δy/Δx(xk+1)-2yk+2c-1)
=2Δy.xk-2Δx.yk+b
(b=-2yk+2c-1)

 Pk is the decision parameter. So,


Pk =Δx (dlower-dupper)

Bresenham’s Line Drawing Algorithm, Rasmi M, St.Mary’s College


 The sign of pk depends on dlower-dupper.
 If pk<0(-ve),then we choose the lowerpixel.
 If pk>0(+ve),then we choose the upperpixel.
 Pk determines which pixel is to be choosen.

Now, for pk+1


pk+1=2Δy.xk+1-2Δx.yk+1+b
So,
pk+1-pk=2Δy(xk+1-xk)-2Δx(yk+1-yk)
pk+1=pk=2Δy-2Δx(yk+1-yk)

 The term yk+1-yk,is either 0 or 1 depending upon the sign of the


parameterp k.

Bresenham’s Line Drawing Algorithm, Rasmi M, St.Mary’s College


 The first decision parameter p0 is calculated as
p0=2Δy-Δx

BRESENHAM’S LINE DRAWING


ALGORITHM

1. Input the two line endpoints and store the left end point in (x0,y0).
2. Load (x0,y0) into the frame buffer that is plot the first point.
3. Calculate the constants x,y,2Δy-2Δx and obtain the starting value
for the decision parameter as
p0=2Δy-Δx

Bresenham’s Line Drawing Algorithm, Rasmi M, St.Mary’s College


4. At each xk ,along the line, starting atk=0, perform the
following test:

 If pk<0, the next point to plot is (xk+1,yk) and


pk+1=pk+2Δy
 Otherwise,the next point to plot is (xk+1,yk+1) and
pk+1=pk+2Δy-2Δx

5.Repeat step 4 Δx times.

Bresenham’s Line Drawing Algorithm, Rasmi M, St.Mary’s College


EXAMPLE

Bresenham’s Line Drawing Algorithm, Rasmi M, St.Mary’s College


Bresenham’s Line Drawing Algorithm, Rasmi M, St.Mary’s College
REFERENCE

Donald Hearn and M Pauline Baker, Computer Graphics, PHI,


New Delhi.

2. Zhigang Xiang and Roy Plasock, Computer Graphics,


Schaum’s Outlines.

 3. Deborah Morley, Understanding Computer Today And


Tomorrow, Introductory Edition.

Bresenham’s Line Drawing Algorithm, Rasmi M, St.Mary’s College

You might also like