Computer Graphics - Unit 2 (DDA )
Computer Graphics - Unit 2 (DDA )
DDA Algorithm
Introduction :
dx = X1 - X0
dy = Y1 - Y0
Advantage:
Disadvantage:
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?
x1=2
y1=3
x2= 6
y2=15
dx = 6 - 2 = 4
dy = 15 - 3 = 12
m=
Step7: xinc=dx/step
yinc=dy/step
assign x = x1
assign y = y1
Step8: Set pixel (x, y)
Step9: x = x + xinc
y = y + yinc
Set pixels (Round (x), Round (y))
#include<graphics.h>
#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();