#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int x0,x1,y0,y1,dx,dy,i=0;
float slope,Po,x2,y2,P2,temp,x,y;
printf("Enter the two ends points:\n");
scanf("%d%d",&x0,&y0);
printf("Enter the next two end points:\n");
scanf("%d%d",&x1,&y1);
dx=x1-x0;
dy=y1-y0;
slope=dy/dx;
if (slope<1)//Satisfying formula for the slope.
{
Po=2*(fabs(dy))-(fabs(dx));
}
else
{
Po=2*(fabs(dx))-(fabs(dy));
}
if(Po<0)
{
x2=x0+1;
y2=y0;
P2=Po+(2*(abs(dy)));
}
else
{
x2=x0+1;
y2=y0+1;
P2=Po+2*dy-2*dx;
}
printf("k\tPk\tXk+1,Yk+1\tPk+1");
printf("\n%d\t%.2f\t%.2f,%.2f\t%.2f",i,Po,x2,y2,P2);
do
{
i++;
temp=P2;
Po=temp;//assigining new value to Po
x=x2;
x0=x;//assigning new value to x0
y=y2;
y0=y;//assigning new value to y0
if(Po<0)
{
x2=x0+1;
y2=y0;
P2=Po+(2*(abs(dy)));
}
else
{
x2=x0+1;
y2=y0+1;
P2=Po+2*dy-2*dx;
}
printf("\n%d\t%.2f\t%.2f,%.2f\t%.2f",i,Po,x2,y2,P2);
}while(i<dx);//using do-while loop for finding value up to dx times.

}

Share To:

Arogya Thapa Magar

Post A Comment:

0 comments so far,add yours