Digital Differential Analyzer Algorithm for line drawing

Here is the Digital Differential Analyzer method for obtaining a rasterized straight line:

1. Read end points (x1, y1 ) and (x2, y2).
If x1= x2 and y1=y2.
Plot Point.
2. Δx= |x2-x1| and Δy= |y2-y1|
3. If (Δx≥ Δy)
length = Δx
length = Δy
end if
4. Δx= (x2-x1)/length
Δy= (y2-y1)/length
5. x= x1 + 0.5 *Sign(Δx)
y= y1 + 0.5 *Sign(Δx)
[Sign function lets the algorithm to work in all quadrants. Factor 0.5 is used to round the values in Integer function.]
6.    i=1
While (i≤ length)
Plot (Integer (x), Integer (y))
x=x + Δx
y=y + Δy
7. Stop.

Advantages of Digital Differential Analyzer Algorithm:

  1. It is a fast method for calculating pixel positions.
  2. It is a simple algorithm.

Disadvantages of Digital Differential Analyzer Algorithm:

  1. End point accuracy is poor.
  2. Floating point calculation is time consuming.


  1. William Davis says

    thank you I needed this formula for a program that plots the window on the screen.

Leave a Reply