-
Notifications
You must be signed in to change notification settings - Fork 0
/
DDA.C
55 lines (47 loc) · 1.07 KB
/
DDA.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
// A program to print a line using DDA (Digital Differential Algorithm) Algorithm.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
void dda(float, float, float, float);
main()
{
float x0,x1,y0,y1;
clrscr();
{
printf("Enter the value of x1 and y1 :\n");
scanf("%f%f",&x0,&y0);
printf("\n\nEnter the value of x2 and y2 : \n");
scanf("%f%f",&x1,&y1);
dda(x0,x1,y0,y1);
}
}
void dda(float x0,float x1,float y0,float y1)
{
int gd=DETECT,gm;
float dx,dy,i,xinc,yinc,step;
dx=(x1-x0); //difference between x-coordinates
dy=(y1-y0); //difference between y-coordinates
//assigning the value of step
if (abs(dx)>abs(dy))
{
step=abs(dx);
}
else
{
step=abs(dy);
}
xinc=dx/step; //increment in x-coordinate
yinc=dy/step; //increment in y-coordinate
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
outtext("Line drawn using DDA Algorithm.");
for(i=0;i<step;i++)
{
putpixel(x0,y0,RED);
x0=x0+xinc;
y0=y0+yinc;
}
//line(x0,y0,x1,y1);
getch();
closegraph();
}