-
Notifications
You must be signed in to change notification settings - Fork 0
/
BresenhamLineDrawingAlgo.c
55 lines (46 loc) · 1.01 KB
/
BresenhamLineDrawingAlgo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<stdio.h>
int main()
{
float x1,y1,x2,y2,m,i,j,p;
int dx=0,dy=0;
printf("enter the first point---\n");
printf("Enter the value of X1 : ");
scanf("%f",&x1);
printf("Enter the value of Y1 : ");
scanf("%f",&y1);
printf("enter the second point--\n");
printf("Enter the value of X2 : ");
scanf("%f",&x2);
printf("Enter the value of Y2 : ");
scanf("%f",&y2);
dx=x2-x1;
dy=y2-y1;
p=(2*dy)-dx;
i = x1;
j = y1;
while(i<=x2,j<=y2)
{
if(p >= 0)
{
i++;
j++;
if((i>x2)||(j>y2))
{
break;
}
printf("%0.2f %0.2f\n",i,j);
p = p+(2*dy)-(2*dx);
}
else if(p < 0)
{
i++;
if((i>x2)||(j>y2))
{
break;
}
printf("%0.2f %0.2f\n",i,j);
p = p+(2*dy);
}
}
return 0;
}