DDA Algorithm in Computer Graphics with Examples

DDA Algorithm ( The digital differential analyzer algorithm ): The DDA algorithm is an incremental scan conversion process. This type of approach is described by doing calculations at every step utilizing the results from the leading step.


Advantage and Disadvantage of DDA Algorithm: Because it calculates points on the line without using floating-point multiplication, the digital differential analyzer approach is faster than using the line equation directly. However, in order to determine each succeeding point, a floating-point addition is still required. Additionally, when its line is relatively long, cumulative error owing to limited accuracy in the floating-point representation might lead calculated points to move away from their true position. 


DDA Algorithm in C language:

DDA(a1, b1, a2, b2)

{

    da=a2-a1

    db=b2-b1

    if (abs(da)>abs(dy))

        step=abs(da)

    else

        step=abs(db)

    a_inc=da/step

    b_inc=db/step

    for (i=1; i<=step; i++)

    {

        putpixel(ai, bi)

        a=a+a_inc

        b=b+b_inc

    }

}


Example of DDA Algorithm:

Ex 1: Draw a line from the point (5,4) to the point (12, 7)


Solution:

Let,

    (a1,b1)=(5,4) and (a2, b2)=(12,7)

Now, Applying the DDA algorithm procedure for this math, 

    da=a2-a1=12-5=7

    db=b2-b1=7-4=3

Now the Slope, 

    m=db/da=3/7

Here, m<1 ( less than 45 degree)

then,

    step=da=7

Now, 

    a_inc=da/step=7/7=1

    b_inc=db/step=3/7=0.4

Now the Ponts are,

a     b     round(b)

5      4      4

6     4.4     4

7     4.8     5

8     5.2     5

9     5.6     6

10     6      6

11    6.4     6

12    6.8     7




Ex 2: Draw a line from the point (5,7) to the point (10, 15)


Solution:

Short Note: 

Here, m>1 (better than 45 degree)

Then, step=db


Ex 3: Draw a line from the point (12,9) to the point (17, 14)


Solution:

Short Note: 

Here, m=1 (equal to 45 degree)

Then, step=da=db

Post a Comment

Previous Post Next Post