On this page
DDA method
- Subtract the start coordinates from the end coordinates to get Δx and Δy.
- Set the number of steps to the larger of |Δx| and |Δy|. If the endpoints are identical, plot that one pixel and stop.
- Divide Δx and Δy by the number of steps to get the x and y increments.
- Plot the start point at step 0. Add the increments at each step and plot the rounded coordinates through the endpoint.
Exam check. Keep full precision as you calculate. Round only to choose each pixel. The tables display coordinates to up to three decimal places. This page rounds exact half values toward positive infinity.
Worked example 1
Shallow positive slope
Draw the line from (1, 1) to (8, 7).
Δx = 7, Δy = 6Steps = 7 x increment = 1, y increment = 6/7
| Step | x | y | Plotted pixel |
|---|---|---|---|
| 0 | 1 | 1 | (1, 1) |
| 1 | 2 | 1.857 | (2, 2) |
| 2 | 3 | 2.714 | (3, 3) |
| 3 | 4 | 3.571 | (4, 4) |
| 4 | 5 | 4.429 | (5, 4) |
| 5 | 6 | 5.286 | (6, 5) |
| 6 | 7 | 6.143 | (7, 6) |
| 7 | 8 | 7 | (8, 7) |
Worked example 2
Steep positive slope
Draw the line from (0, 0) to (4, 6).
Δx = 4, Δy = 6Steps = 6 x increment = 2/3, y increment = 1
| Step | x | y | Plotted pixel |
|---|---|---|---|
| 0 | 0 | 0 | (0, 0) |
| 1 | 0.667 | 1 | (1, 1) |
| 2 | 1.333 | 2 | (1, 2) |
| 3 | 2 | 3 | (2, 3) |
| 4 | 2.667 | 4 | (3, 4) |
| 5 | 3.333 | 5 | (3, 5) |
| 6 | 4 | 6 | (4, 6) |
Worked example 3
45° line
Draw the line from (0, 0) to (7, 7).
Δx = 7, Δy = 7Steps = 7 x increment = 1, y increment = 1
| Step | x | y | Plotted pixel |
|---|---|---|---|
| 0 | 0 | 0 | (0, 0) |
| 1 | 1 | 1 | (1, 1) |
| 2 | 2 | 2 | (2, 2) |
| 3 | 3 | 3 | (3, 3) |
| 4 | 4 | 4 | (4, 4) |
| 5 | 5 | 5 | (5, 5) |
| 6 | 6 | 6 | (6, 6) |
| 7 | 7 | 7 | (7, 7) |
Worked example 4
Shallow slope with a non-zero start
Draw the line from (2, 3) to (9, 8).
Δx = 7, Δy = 5Steps = 7 x increment = 1, y increment = 5/7
| Step | x | y | Plotted pixel |
|---|---|---|---|
| 0 | 2 | 3 | (2, 3) |
| 1 | 3 | 3.714 | (3, 4) |
| 2 | 4 | 4.429 | (4, 4) |
| 3 | 5 | 5.143 | (5, 5) |
| 4 | 6 | 5.857 | (6, 6) |
| 5 | 7 | 6.571 | (7, 7) |
| 6 | 8 | 7.286 | (8, 7) |
| 7 | 9 | 8 | (9, 8) |
Try a line with a negative slope
Find the pixels from (1, 5) to (8, 2) using DDA.
Reveal the solution
Δx = 7, Δy = -3Steps = 7 x increment = 1, y increment = -3/7
| Step | x | y | Plotted pixel |
|---|---|---|---|
| 0 | 1 | 5 | (1, 5) |
| 1 | 2 | 4.571 | (2, 5) |
| 2 | 3 | 4.143 | (3, 4) |
| 3 | 4 | 3.714 | (4, 4) |
| 4 | 5 | 3.286 | (5, 3) |
| 5 | 6 | 2.857 | (6, 3) |
| 6 | 7 | 2.429 | (7, 2) |
| 7 | 8 | 2 | (8, 2) |
Compare with Bresenham’s line algorithm · DDA method reference