DDA LINE DRAWING ALGORITHM
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
#define ROUND(a)((int)(a+0.5))
void linebrel(int,int,int,int);
void main()
{
int gd=DETECT,gm,xa,xb,ya,yb;
clrscr();
initgraph(&gd,&gm,"c:/tc/bgi");
printf("Enter the starting point of line:");
scanf("%d%d",&xa,&ya);
printf("Enter the ending points of line:");
scanf("%d%d",&xb,&yb);
linebrel(xa,ya,xb,yb);
getch();
}
void linebrel(int xa,int ya,int xb,int yb)
{
int dx=xb-xa,dy=yb-ya,steps,k;
float xincrement,yincrement,x=xa,y=ya;
if(abs(dx)>abs(dy))
steps=abs(dx);
else
steps=abs(dy);
xincrement=dx/(float)steps;
yincrement=dy/(float)steps;
putpixel(ROUND(x),ROUND(y),5);
for(k=0;k<steps;k++)
{
x+=xincrement;
y+=yincrement;
putpixel(ROUND(x),ROUND(y),5);
}
}
NOTE : . I am sharing knowledge for education purpose only.
0 comments:
Post a Comment