Let us understand how DDA Algorithm works by taking some examples and solving them too. Just keep in mind two things one, Y=mx+b is the line equation. Second, If m is less than one increase X and calculate Y. If m is more than 1 then increase Y and calculate X. DDA Algorithm is explained by taking some examples.
Draw a line from (1,1) to (8,7) using DDA and BLA algorithms.
DDA- Digital Differential Analyser
This case is for slope (m) less than 1. Slope (m) =(7-1)/(8-1) = 6/7 .
S-1: x1=1; y1=1; x2=8; y2=7.
S-2: m=(7-1)/(8-1) = 6/7 which is less than 1.
S-3: As m (6/7) is less than 1 therefore x is increased and y is calculated.
S-4 : The step will be x1=x1+1 and y1= y1+6/7
The algorithm will stop here as the x value has reached 7 though y has not reached 9. This is the limitation of this algorithm.
—————————————————————–
Lets take another example.
Draw a line using DDA Algorithm from (0,0) to (4,6)
This case is for slope (m) greater than 1. Slope (m) =(6-0)/(4-0) = 6/4 .
S-1: x1=0; y1=0; x2=4; y2=6
S-2: m=(6-0)/(4-0) = 6/4 which is more than 1.
S-3: As m (6/4) is greater than 1 therefore y is increased and x is calculated.
S-4 : But first we will calculate b (remember the equation of line : y=mx+b), so b = y1-m*x1; There fore b = 0 – 6/4*0 = 0. Which means that b =0.
S-4 : Now increase the value of y and calculate value of x.
- To calculate x, take line equation and find x , which would be x=(y-b)/m
- We will start from x1 =0, y1=0 , b =0 and m = 6/4
- The step will be y1=y1+1 and x1= (y1-0)/(6/4), After simplifying , x1= (y1)*4/6
The algorithm will stop here because the Y and X values have reached the End point (4,6).
Now let’s solve the same numerical using BLA Algorithm.
S-1: x1=1; y1=1; x2=8; y2=7.
S-2: dy=7-1 = 6 and dx = 8-1 = 7
dy-dx = 6-7 = -1; and 2 * dy = 12;
S-3: d=2*6 – 7 = 5;
S-4: we will increase x by 1 every step as m is less than 1 and calculate y as follows
- If d >=0 then x1 = x1 + 1 and y1 = y1 + 1 with new d = d + 2*(dy-dx)
- If d<0 then x1 = x1 + 1 and y1 will not change with new d = d + 2*d
That's all.
Thanks for ur watching!!!!!!
Zhengzhi