CG DDA Algorithm
CG DDA Algorithm
6.
7. Stop
4. Example of DDA:
Consider the line from (3, 2) to (4, 7), use DDA line algorithm to rasterize this line.
Evaluate and tabulate all the steps involved.
Solution:
Given data,
Page 1
Page 2
Pixel
R(x)
R(y)
Initially
0
(3,2)
3.5
2.5
(3,3)
3.7
3.5
(3,4)
3.9
4.5
(4,5)
4.1
5.5
(4,6)
4.3
6.5
Length=5
(4,7)
4.5
7.5
7
6
5
4
3
2
1
(0, 0)
1
Page 3
int main( )
{
int gd=DETECT,gm;
int x1,x2,y1,y2,dx,dy,steps,k;
float xi,yi,x,y;
clrscr( );
initgraph (&gd,&gm,"c:\\turboc3\\bgi");
printf("Enter the co-ordinates of the first point \n"); //Read the value of point1
printf("x1= ");
scanf("%d/n",&x1);
printf("y1= ");
scanf("%d/n",&y1);
printf("Enter the co-ordinates of the second point \n"); //Read the value of point2
printf("x2= ");
scanf("%d/n",&x2);
printf("y2= ");
scanf("%d/n",&y2);
dx= x2-x1;
dy= y2-y1;
xi=(float)dx/steps;
yi=(float)dy/steps;
x=x1; //Initialize starting point
y=y1;
for(k=0;k<steps;k++)
{
putpixel (x,y,15);
x=x+xi;
Ms. Punam Patil
Page 4
6. Output:
Page 5