On this page

DDA method

  1. Subtract the start coordinates from the end coordinates to get Δx and Δy.
  2. Set the number of steps to the larger of |Δx| and |Δy|. If the endpoints are identical, plot that one pixel and stop.
  3. Divide Δx and Δy by the number of steps to get the x and y increments.
  4. 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

StepxyPlotted pixel
011(1, 1)
121.857(2, 2)
232.714(3, 3)
343.571(4, 4)
454.429(5, 4)
565.286(6, 5)
676.143(7, 6)
787(8, 7)
01234567801234567xy
Shaded squares show the plotted pixels. The dashed line joins the exact endpoints.

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

StepxyPlotted pixel
000(0, 0)
10.6671(1, 1)
21.3332(1, 2)
323(2, 3)
42.6674(3, 4)
53.3335(3, 5)
646(4, 6)
012340123456xy
Shaded squares show the plotted pixels. The dashed line joins the exact endpoints.

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

StepxyPlotted pixel
000(0, 0)
111(1, 1)
222(2, 2)
333(3, 3)
444(4, 4)
555(5, 5)
666(6, 6)
777(7, 7)
0123456701234567xy
Shaded squares show the plotted pixels. The dashed line joins the exact endpoints.

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

StepxyPlotted pixel
023(2, 3)
133.714(3, 4)
244.429(4, 4)
355.143(5, 5)
465.857(6, 6)
576.571(7, 7)
687.286(8, 7)
798(9, 8)
0123456789012345678xy
Shaded squares show the plotted pixels. The dashed line joins the exact endpoints.

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

StepxyPlotted pixel
015(1, 5)
124.571(2, 5)
234.143(3, 4)
343.714(4, 4)
453.286(5, 3)
562.857(6, 3)
672.429(7, 2)
782(8, 2)
012345678012345xy
Shaded squares show the plotted pixels. The dashed line joins the exact endpoints.

Compare with Bresenham’s line algorithm · DDA method reference