Bresenham’s Line Drawing Algorithm
In bresenham's line drawing algorithm, we find the closest possible points, and then by using those points, we form a line on the computer screen.
This algorithm is an incremental scan conversion line drawing algorithm. It is one of the efficient line drawing algorithms, because it uses integer addition and subtraction and a little bit of multiplication, these operations are easy to perform, that's why we can rapidly use these operations, and quickly form the lines simultaneously.
To further understand the working of bresenham's line drawing algorithm, you can check out the derivation of the bresenham's line drawing algorithm.
Program For Bresenham's Line drawing Algorithm
#include<stdio.h>
#include<graphics.h>
void main()
{
{
int gd =DETECT,gm;
initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
int x,x1,y,y1,dx,dy,pk;
printf("Enter first co-ordinates");
scanf(" %d%d",&x,&y);
printf("Enter second co-ordinates");
scanf(" %d%d",&x1,&y1);
dx=x1-x;
dy=y1-y;
pk=2*dy-dx;
while(x<x1)
{
x++;
x++;
if(pk<0)
{
{
pk+=2*dy;
}
else{
y++;
y++;
pk+=2*(dy-dx);
}
putpixel(x,y,9);
}
getch();
getch();
closegraph();
}
}
Further read>>
This comment has been removed by a blog administrator.
ReplyDelete