**Digital Differential Analyzer Algorithm (DDA)**

- The digital differential analyzer (DDA) is an incremental scan conversion method that is based on calculating either Δx or Δy.
- This algorithm generates line from their differential equations.
- The name ‘
*DDA*‘ comes from the mechanical device that is used to solve differential equations by numerical methods. It finds out successive (x, y) values by simultaneously incrementing x and y by small steps proportional to the first derivative of x and y. - Given the endpoints (x
_{1}, y_{1}) and (x_{2}, y_{2}) of a line segment, we know the slope*m*is represented as :

m = y

_{2 }– y_{1}/ x_{2 }– x_{1}

- If (x
_{i}, y_{i}) and (x_{i+1}, y_{i+1}) are the two consecutive points lying on this line segment, slope m can also be expressed as:

m = y

_{i+1}– y_{i }/ x_{i+1 }– x_{i}

Thus, we can say y_{i+1} – y_{i} = Δy and x_{i+1 }– x_{i} = Δx

∴ m =Δy / Δx

- In DDA algorithm, the line is sampled at unit interval in one coordinate and corresponding integer value (nearest to the line path) is then calculated for the other coordinate i.e. either Δx = 1 or Δy = 1.

- Consider a line with positive slope (i.e. x
_{1}< x_{2}and y_{1}< y_{2}). The line processed from left endpoint to the right endpoint. - If slope m of a line is less than equal to 1 i.e. | m |≤1 or lΔyl < IΔxl, we sample the line at unit
*x*interval i.e. Δx=1. - Therefore, Δy calculated as:

Δy = m . Δx

∴ Δy = m

- As a result the coordinate values of next point (x
_{i+1}, y_{i+1}) calculated as:

x

_{i+1 }= x_{i}+ Δxy

_{i+1}= y_{i }+ Δy

Substituting Δx = 1 and Δy = m, we get :

x

_{i+1 }= x_{i}+ 1y

_{i+1}= y_{i }+ m

- If slope m of a line is greater than 1 i.e. I ml>1 or lΔyl > IΔxl, we sample the line at unit y interval i.e. Δy = 1.
- Therefore Δx is calculated as :

Δx = Δy / m

Δx = 1 / m

- Substituting Δx = 1/m and Δy = 1 in equation, we get:

x

_{i+1 }= x_{i}+ 1/my

_{i+1}= y_{i }+ 1

- Now consider a line with negative slope (i.e. x
_{2}< x_{1}and y_{2}< y_{1}). The line processed from right endpoint to left endpoint. - If the slope
*m*of line is less than equal to 1 i.e. I m l≤1 then Δx = -1 and Δy = – m

Thus the value of (x_{i+1}, y_{i+1}) are :

x

_{i+1 }= x_{i}– 1y

_{i+1}= y_{i }– m

- If the slope m of a line is greater than 1 i.e. I m >1 then Δx = -1/m and Δy = 1. The coordinate values of next point are :

x

_{i+1 }= x_{i}– 1/my

_{i+1}= y_{i }– 1

### Advantage of Digital Differential Analyzer Algorithm

- Digital Differential Analyzer algorithm is faster than the direct use of line equation as it calculate points on the line without any floating point multiplication.

### Disadvantages of DDA algorithm

- It is time consuming as it deals with rounding off operation and floating point arithmetic.
- It is orientation dependent, because of this the endpoint accuracy is poor.

[su_button url=”https://h-educate.in/wp-content/uploads/2022/02/Digital-Differential-Analyzer-Algorithm.pdf” background=”#0ba600″ color=”#ffffff” size=”10″ wide=”yes”]Download as Pdf[/su_button]

### Algorithm for DDA in programming

Given the endpoints of a line segment : (x_{1}, y_{1}) and (x_{2}, y_{2}), the following steps are used to plot a line :

1. Input the two endpoint coordinates (x_{1}, y_{1}) and (x_{2}, y_{2})

2. Calculate the value of dx and dy :

dx = x

_{2}– x_{1}dy = y

_{2}– y_{1}

3. Set the running coordinates (x, y) to the starting value (x_{1}, y_{1}).

4. Determine the length of a line.

If abs (dx) ≥ abs (dy) then

set length = abs (dx)

else

set length = abs (dy)

5. Calculate the incremental values in x and y directions as :

Δx = dx / length

Δy = dy / length

6. Plot the point at current (x, y) location.

7. Calculate the Δx and Δy for subsequent points as :

i = 1 while (i ≤ length) { Plot (integer (x), integer (y)) x = x + Δx y = y + Δy i = i+1 }

### Flowchart of Digital Differential Analyzer Algorithm (DDA)

#### Related posts:-

[su_posts template=”templates/list-loop.php” posts_per_page=”3″ taxonomy=”link_category” tax_operator=”NOT IN” order=”

desc”]