DDA Simple and Symmetrical
DDA Simple and Symmetrical
equation of line is :
y=mx+c where mis the slope of line∧c is the y intercept
y 2− y 1 dx
m ( slope of line )= =
x 2−x 1 dy
dy = y 2− y 1 ¿
Step 3: Based on the calculated difference in step-2, you need to identify the number of steps to put pixel.
If x >dy ¿ , then you need more steps in x coordinate; otherwise in y coordinate.
dx
x increment =
float ( steps )
dy
y increment =
float ( steps )
Step 5: Put the pixel by successfully incrementing x and y coordinates accordingly and complete the
drawing of the line.
Example 1: Plot the straight line from (10,15) to (20,21) using simple DDA Algorithm.
Step 1: Calculate dx and dy.
dx=20−10=10∧dy =21-15=6
Step2: Calculate slope of line.
6
m ( slope of line )= =0.6
10
Step 3: Calculate the number of steps need to increment in coordinates or length of line
if(abs(dx)>dy)
Steps=dx
else
Steps=dy
For this line the number of steps will be equals to dx i.e=10
Step 4:
x increment =1
dy
y increment = or =m
float ( steps )
x
0 1 2 3 4 5 6 7 8 9 10 1 12 1 14 1 16 1 18 1 20 21
1 3 5 7 9
1
2
3
4
5
6
7
y 8
9
10
11
12
13
14
15
16
17
18
19
20
21
m>1 1 y +1
x+
m
m=1 x +1 y +1
Advantages of DDA Algorithm
1) It is fast method for calculating pixel positing than the direct use of Equation 1. It eliminates the
multiplication by making use of raster characteristics, so that appropriate increments are applied
in the x or y direction to step to pixel positions along the line path.
Drawback of DDA Algorithm
1) The accumulation of round off error in successive additions of floating point increment, however
can cause the calculated pixel positions to drift away from the true line path for long line
segment.
2) Rounding operations and floating point performance is time consuming.
Let us consider the straight line connecting ( x 1 , y 1) and ( x 2 , y 2 ) ,with the equation:
The increment in each direction are chosen at small convenient values to satisfy this relationship. The
“small convenient value” should be such that it does not exceed half to one pixel dimension. One way of
choosing it, to suit binary arithmetic, is as follow:
1. Find the smallest integer value of the exponent n in 2n which will be equal to or greater than the
larger of d x ∧d y , the x and y component respectively
n
Then 2 ≥larger of d x ∧d y
Or
log [ larger of d x ∧d y ]
n≥
log2
(Note: log 2 to base 10 is 0.301030 and natural log, then is in 2 to base e is 0.693147 )
2. Set the incremental factor approximately to value
−n
e=2
Then the increment x inc=e .(d x ),
dy
From eq.(1) the increment y inc=m. x inc= . e . d x =e .(d ¿¿ y)¿
dx
This needs two additional of fractional numbers, one each in x∧ y .
References: