0% found this document useful (0 votes)
5 views3 pages

Bresenham's Line Drawing Algorithm

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

Bresenham's Line Drawing Algorithm

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

Procedure for Bresenham’s algorithm:

 [Link] line end points (x1,y1) and (x2,y2) such that they are not equal.
 2. dx=|x2-x1| and dy=|y2-y1|
 3.x=x1 and y=y1
 4.e=2*dy-dx
 5.i=1
 [Link] (x,y)
 [Link] (e>0)
 {
 x=y+1 e=e-2*dx
 }
 x=x+1 e=e+2*dy
 8.i=i+1
 9. if(i<dx) then goto step 6.
 10. Stop.
Program
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd=DETECT,gm=DETECT,length,dx,dy,x1,y1,x2,y2,e;
float x,y;
clrscr();
printf("\n enter coordinates of x1,y1,x2,y2");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
dx=x2-x1;
dy=y2-y1;
e=2*(dy-dx);
x=x1;
y=y1;
initgraph(&gd,&gm,"c://Turboc3//BGI");
while(x<=x2)
{
if(e<0)

x=x+1; y=y; e=e+2*dy;


}
else
{
x=x+1; y=y+1;
e=e+2*(dy-dx);
}
putpixel(x,y,15);
}
getch();
closegraph();
}

You might also like