DDA Algorithm 1
DDA Algorithm 1
MANDAL’S
B. L. PATIL POLYTECHNIC, KHOPOLI.
PROJECT REPORT ON
Submitted by
1 DDA Algorithm
2 Advantages
3 Disadvantages
4 DDA Algorithm
6 Output
7 Symmetrical DDA
8 Example
DDA Algorithm
DDA stands for Digital Differential Analyzer. It is an incremental
method of scan conversion of line. In this method calculation is
performed at each step but by using results of previous steps.
yi=mxi+b......................equation 1
yi+1=mxi+1+b.................equation 2
m=
yi+1-yi=∆y.......................equation 3
yi+1-xi=∆x......................equation 4
yi+1=yi+∆y
∆y=m∆x
yi+1=yi+m∆x
∆x=∆y/m
xi+1=xi+∆x
xi+1=xi+∆y/m
yi+1=y1+m, x=x+1
Until x = x2
xi+1= , y=y+1
Until y → y2
Advantage:
Disadvantage:
1. It involves floating point additions rounding off is done.
Accumulations of round off error cause accumulation of error.
3. It is more suitable for generating line using the software. But it is less
suited for hardware implementation.
DDA Algorithm:
Else
Step7: xinc=dx/step
yinc=dy/step
assign x = x1
assign y = y1
Step9: x = x + xinc
y = y + yinc
Example: If a line is drawn from (2, 3) to (6, 15) with use of DDA. How
many points will needed to generate such line?
y1=3
x2= 6
y2=15
dx = 6 - 2 = 4
dy = 15 - 3 = 12
m=
#include<conio.h>
#include<stdio.h>
void main()
float x, y,dx,dy,steps;
setbkcolor(WHITE);
dx = (float)(x1 - x0);
dy = (float)(y1 - y0);
if(dx>=dy)
steps = dx;
else
{
steps = dy;
dx = dx/steps;
dy = dy/steps;
x = x0;
y = y0;
i = 1;
while(i<= steps)
putpixel(x, y, RED);
x += dx;
y += dy;
i=i+1;
getch();
closegraph();
Output:-
Symmetrical DDA:
x1=0
y1=0
x2=10
y2=5
dx = 10 - 0 = 10
dy = 5 - 0 = 0