You are on page 1of 16

BRESENHAM’S

LINE DRAWING ALGORITHM

PRESENTED BY :
AHTESHAM ULLAH KHAN
1604610013
CSE 3RD YR.
(A1)
About BRESENHEM …..
Bresenham's line algorithm is named after Jack Elton
Bresenham who developed it in 1962 at IBM Born in Clovis, New
Mexico he received his B.S.E.E. degree from the University of New
Mexico in 1959; his M.S.I.E. degree from Stanford University in
1960; and his Ph.D. from Stanford University in 1964. He joined
IBM in 1960 and retired after 27 years of service as a Senior
Technical Staff Member in 1987. He was also a professor of
Computer Science for 16 years at Winthrop University. His four
children are: Janet Lyn, Craig Elton (died 1963), Linda Jo (died
2008), and David Floyd.
WHAT IS BRESENHEM’S LINE DRAWING ALGORITHM
The holder of nine patents; in 1962, while at IBM, he developed a
line algorithm, known as Bresenham's line algorithm. It is one of
the earliest algorithms discovered in the field of computer
graphics. Bresenham's line algorithm is an algorithm that
determines which points in an n-dimensional raster should be
plotted in order to form a close approximation to a straight line
between two given points. It is commonly used to draw lines on a
computer screen, as it uses only integer addition, subtraction and
bit shifting, all of which are very cheap operations in standard
computer architectures. It is one of the earliest algorithms
developed in the field of computer graphics.
PROBLEM

Decide what is the next pixel


position
 (11,11) or (11,12)
For the pixel position
xk+1=xk+1,
which one we should
choose:
(xk+1,yk) or (xk+1, yk+1)
ILLUSTRATING BRESENHAM’S APPROACH

If dlower< dupper then pk is


negative.
Plot the lower pixel
Otherwise
Plot the upper pixel
(North East)
ALGORITHM
STEP 1 : INPUT X1, Y1, X2 , Y2
STEP 2 : CALCULATE ΔX =X2-X1 , Δ Y =Y2-Y1
E= - ΔX
STEP 3 : X=X1 ,Y=Y1
STEP 4 : PUT PIXEL (X,Y)
STEP 5 : IF E< 0
THEN
E=E+2 ΔY
X=X+1 , Y=Y
ELSE
E=E+2 ΔY – 2 ΔX
X=X+1 , Y=Y+1
STEP 6 : PUT PIXEL (X,Y)
STEP 7 : REPEAT STEP 5,6 ΔX TIME
EXAMPLE

LINE END POINTS: ( x0 , y0 )  (5,8); ( x1 , y1 )  (9,11)

DELTAS: dx  4; dy  3

INITIALLY p(5,8)  2(dy )-(dx)


 64  2  0
p  2  NE
FIRST POINT IS : (8,5)
SECOND POINT IS : ( 9,6) AND SO ON
PROGRAM
#include<stdio.h> #include<graphics.h>
void drawline(int x0, int y0, int x1, int y1){
int dx, dy, p, x, y;
dx=x1-x0; dy=y1-y0;
x=x0; y=y0;
p=2*dy-dx;
while(x<x1){
if(p>=0){
putpixel(x,y,7);
y=y+1; p=p+2*dy-2*dx;}
else{
putpixel(x,y,7);
p=p+2*dy;}
x=x+1;}}
int main(){
int gdriver=DETECT, gmode, error, x0, y0, x1, y1;
initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
printf("Enter co-ordinates of first point: ");
scanf("%d%d", &x0, &y0);
printf("Enter co-ordinates of second point: ");
scanf("%d%d", &x1, &y1);
drawline(x0, y0, x1, y1);
return 0:

You might also like