Rasterize a shallow line with an integer decision variable, avoiding
rounding at each pixel.
Example
Use an integer decision variable to choose line pixels without rounding each step.
highlighted = computed this step
Step 1 — Set up
Set up the integer error values.
dx=5,dy=3,D=1
Step 2 — Pixel A
Set this line pixel and update the error.
x1y1D1testD>0Dnext−3pixel (1,1)
Step 3 — Pixel B
Set this line pixel and update the error.
x2y2D−3testD≤0Dnext3pixel (2,2)
Step 4 — Pixel C
Set this line pixel and update the error.
x3y2D3testD>0Dnext−1pixel (2,3)
Step 5 — Pixel D
Set this line pixel and update the error.
x4y3D−1testD≤0Dnext5pixel (3,4)
Step 6 — Pixel E
Set this line pixel and update the error.
x5y3D5testD>0Dnext1pixel (3,5)
Step 7 — Pixel F
Set this line pixel and update the error.
x6y4D1testdoneDnext1pixel (4,6)
Step 8 — Result
The ordered line pixel set is complete.
line pixels complete
bresenham-lineNaive DDA steps along a line and rounds to pixels. Bresenham keeps an integer error value instead, so each step decides whether the next pixel stays level or moves up.