Program to Draw a line using DDA(digital differential analyzer) Method

/* Program to Draw a line using DDA(digital differential analyzer) Method */

#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
float m,minv,dx,dy,x1,x2,y1,y2,x,y;
cout<<“\n\t\t\t\**DDA Method to draw a line**\n”;
cout<<“\nenter the x coordinates(x1,x2)\n”;
cin>>x1>>x2;
cout<<“\nenter the y coordinates(y1,y2)\n”;
cin>>y1>>y2;
x=x1;
y=y1;
dx=x2-x1;
dy=y2-y1;
m=dy/dx;
minv=dx/dy;
int gd=DETECT,gm;
initgraph(&gd,&gm,””);
setbkcolor(WHITE);
if(m<0)
{
while(x<=x2)
{
putpixel(x,int(y+0.5),8);
x++;
y=y+m;
}
}
else
{
while(y<=y2)
{
putpixel(int(x+0.5),y,8);
y++;
x=x+minv;
}
}
setcolor(8);
outtextxy(110,60,”line  using DDA (incremental) Technique”);
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *