following is a code for scan converting a line using DDA algorithm. But I'm not getting any line segment in the output. The code is:
/*start*/
#include <graphics.h>
#include <stdio.h>
float m;
main()
{
int x1,y1,x2,y2;
float dx,dy;
void slopelessthanon e(int,int,int);
initgraph(&gdri ver, &gmode, "c:\\tc\\bg i");
printf("Enter coordinates of first point:");
scanf("%d%d",&x 1,&y1);
printf("Enter coordinates of second point:");
scanf("%d%d",&x 2,&y2);
dx=x2-x1;
dy=y2-y1;
m=dy/dx;
printf("%f",m);
if (abs(m)<1) /*I'm considering only one case initially*/
slopelessthanon e(x1,x2,y1);
getch();
closegraph();
return;
}
void slopelessthanon e(int x1, int y1, int x2)
{
float x,y;
int i=1;
x=x1;
y=y1;
clrscr();
while(x<=x2){
putpixel(x,y,WH ITE);
x+=1;
y+=i*m;
i++;
}
}
/*end
Basically in the output when i enter coordinates of the two points, only one dot(i.e. one pixel) gets plotted. There is no line segment. I guess this means that the while loop is executing only once. But i couldn't find the reason.
If anybody could help... thanx!
/*start*/
#include <graphics.h>
#include <stdio.h>
float m;
main()
{
int x1,y1,x2,y2;
float dx,dy;
void slopelessthanon e(int,int,int);
initgraph(&gdri ver, &gmode, "c:\\tc\\bg i");
printf("Enter coordinates of first point:");
scanf("%d%d",&x 1,&y1);
printf("Enter coordinates of second point:");
scanf("%d%d",&x 2,&y2);
dx=x2-x1;
dy=y2-y1;
m=dy/dx;
printf("%f",m);
if (abs(m)<1) /*I'm considering only one case initially*/
slopelessthanon e(x1,x2,y1);
getch();
closegraph();
return;
}
void slopelessthanon e(int x1, int y1, int x2)
{
float x,y;
int i=1;
x=x1;
y=y1;
clrscr();
while(x<=x2){
putpixel(x,y,WH ITE);
x+=1;
y+=i*m;
i++;
}
}
/*end
Basically in the output when i enter coordinates of the two points, only one dot(i.e. one pixel) gets plotted. There is no line segment. I guess this means that the while loop is executing only once. But i couldn't find the reason.
If anybody could help... thanx!
Comment