DDA Line

Description:              This program implements the DDA algorithm of line drawing.
 
Primary Input:        Two end point coordinates of the line.
Primary Output:       A line drawn according to the given end points.
Platform Used:         Turbo C++ version 3.0, Borland International Inc.
 

/*This program generates a line according to DDA algorithm for given end points. */

#include
#include
#include
#define ROUND(a) ((int)(a+0.5))
void lineDDA(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),BLUE);
for(k=0;k

 

Rate this post

Leave a Reply