
Program to implement DDA Line generation algorithm for all 4 quadrants of a plane (x and y axis should meet at centre(320,240) i.e., Origin O(0,0) of user coordinate system)-MASTER GUIDE
Program to implement DDA Line generation algorithm for all 4 quadrants of a plane (x and y axis should meet at centre(320,240) i.e., Origin O(0,0) of user coordinate system)
#include<graphics.h>
#include<math.h>
void main()
{
int gd=DETECT,gm;
int x1,y1,x2,y2,dx,dy,steps,k;
float xinc,yinc,x,y;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
cleardevice();
printf("Enter the starting point of the line:");
scanf("%d%d",&x1,&y1);
printf("Enter ending point of the line:");
scanf("%d%d",&x2,&y2);
if(x1==x2 && y1==y2)
{
printf("Both ends points are same,line cannot be drawn");
getch();
closegraph();
}
dx=x2-x1;
dy=y2-y1;
if(abs(dx)>abs(dy))
steps=abs(dx);
else
steps=abs(dy);
xinc=dx/(float)steps;
yinc=dy/(float)steps;
x=x1;
y=y1;
line(0,240,640,240);
line(320,0,320,480);
outtextxy(320+10,240-10,"(0,0)");
putpixel(320+x,240-y,RED);
for(k=0;k<steps;k++)
{
x+=xinc;
y+=yinc;
putpixel(320+floor(x+0.5),240-floor(y+0.5),RED);
delay(50);
}
getch();
closegraph();
}
OUTPUT:
0 Response to "Program to implement DDA Line generation algorithm for all 4 quadrants of a plane (x and y axis should meet at centre(320,240) i.e., Origin O(0,0) of user coordinate system)-MASTER GUIDE"
Post a Comment