DDA Algorithm

The digital drflerential analyzer (DDA) is a scan-conversion line algorithm.

This algorithm is summarized in the following procedure

  1. Accept the two end points pixel positions as input.

    A(x1, y1)
    B(x2, y2)


  2. Horizontal and vertical differences between the endpoint positions are assigned to parameters dx and dy.

    dx = x2 - x1
    dy = y2 - y1


  3. The difference with the greater magnitude determines the value of parameter steps.

    if |dx| > |dy|      (compare absolute values of dx and dy)
        steps = dx
    else
        steps = dy

  4. We determine the Incremental Factor needed at each step to generate the next pixel position along the line path.

    Δx = dx ⁄ steps
    Δy = dy ⁄ steps

  5. Plot the initial points on the line

    xnew = x1
    ynew = y1

    setPixel ( xnew , ynew )

  6. Generate new pixel on line by incrementing x and y, we repeat the process steps times.

    for (k = 0; k < steps; k++)

        xnew = xnew + Δx
        ynew = ynew + Δy

        setPixel ( xnew , ynew )