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.
2. Δx= |x2-x1| and Δy= |y2-y1|
3. If (Δx≥ Δy)
length = Δx
length = Δy
4. Δx= (x2-x1)/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.]
While (i≤ length)
Plot (Integer (x), Integer (y))
x=x + Δx
y=y + Δy
Advantages of Digital Differential Analyzer Algorithm:
- It is a fast method for calculating pixel positions.
- It is a simple algorithm.
Disadvantages of Digital Differential Analyzer Algorithm:
- End point accuracy is poor.
- Floating point calculation is time consuming.