Skip to main content

Bresenham: line (10,20) to (15,2)

Short answer

Use Bresenham with |m|>1 negative. p0 = 2*5 – 18 = –8. y decrements each step; when p<0, x stays, p+=10; when p≥0, x+=1, p–=26. Resulting pixels: (10,20), (10,19), (11,18), (11,17), (11,16), (11,15), (12,14), (12,13), (12,12), (13,11), (13,10), (13,9), (13,8), (14,7), (14,6), (14,5), (14,4), (15,3), (15,2).

Digitize a line with end points (10,20) and (15,2) using Bresenham's algorithm.

Given: (10,20) to (15,2). Δx = 5, |Δy| = 18, the slope is negative with |m| = 3.6 > 1. So y is decremented by 1 at each step and the decision parameter decides whether x stays or increases.

p0 = 2Δx − |Δy| = 10 − 18 = −8
If p < 0: x same,  p = p + 2Δx = p + 10
If p ≥ 0: x + 1,   p = p + 2Δx − 2|Δy| = p − 26
kp_k(x_k, y_k)
0-8(10,20)
12(10,19)
2-24(11,18)
3-14(11,17)
4-4(11,16)
56(11,15)
6-20(12,14)
7-10(12,13)
80(12,12)
9-26(13,11)
10-16(13,10)
11-6(13,9)
124(13,8)
13-22(14,7)
14-12(14,6)
15-2(14,5)
168(14,4)
17-18(15,3)
18-8(15,2)

Pixels:

(10,20) (10,19) (11,18) (11,17) (11,16) (11,15) (12,14) (12,13)
(12,12) (13,11) (13,10) (13,9) (13,8) (14,7) (14,6) (14,5)
(14,4) (15,3) (15,2)

Answer: 19 pixels from (10,20) to (15,2) as listed.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Graphics chapter 2 questions →