---
title: "Bresenham: line (20,10) to (30,18)"
subject: "Computer Graphics"
chapter: 2
key: "semester_5/computer_graphics:digitize-line-20-10-30-18"
source: https://www.bctengineer.com/q/semester_5/computer_graphics/digitize-line-20-10-30-18
site: BCT Engineering
---

# Bresenham: line (20,10) to (30,18)

Computer Graphics · Chapter 2: Scan-Conversion

- Asked in: 2074 Asoj, 10 marks; 2078 Bhadra, 7 marks; 2070 Asar, 7 marks (asked 3 times)
- Video: [Bresenham's Line algorithm |  Example | CG | Computer Graphics | Lec-18 | Bhanu Priya](https://www.youtube.com/watch?v=h3gDB89h0os) — Education 4u
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/computer_graphics/digitize-line-20-10-30-18
- Whole chapter: https://www.bctengineer.com/md/semester_5/computer_graphics/chapter-2

## Question

Digitize the line with end points A(20,10) and B(30,18) using Bresenham's algorithm.

## Short answer

dx=10, dy=8, p0=6. If p<0 y unchanged and p+=16; else y incremented and p-=4. Pixels: (20,10), (21,11), (22,12), (23,12), (24,13), (25,14), (26,15), (27,16), (28,16), (29,17), (30,18).

## Answer

**Given:** A(20,10), B(30,18). Slope is 0 < m = 8/10 < 1, so x is incremented by 1 at each step.

```text
dx = 30 − 20 = 10,   dy = 18 − 10 = 8
2dy = 16,   2dy − 2dx = 16 − 20 = −4
p0 = 2dy − dx = 16 − 10 = 6
```

**Rule:** if p_k < 0: next point (x+1, y), p_k+1 = p_k + 2dy = p_k + 16.
If p_k ≥ 0: next point (x+1, y+1), p_k+1 = p_k + 2dy − 2dx = p_k − 4.

| k | p_k | (x_k, y_k) | Next point | p_k+1 |
|---|---|---|---|---|
| 0 | 6 | (20,10) | (21,11) | 2 |
| 1 | 2 | (21,11) | (22,12) | -2 |
| 2 | -2 | (22,12) | (23,12) | 14 |
| 3 | 14 | (23,12) | (24,13) | 10 |
| 4 | 10 | (24,13) | (25,14) | 6 |
| 5 | 6 | (25,14) | (26,15) | 2 |
| 6 | 2 | (26,15) | (27,16) | -2 |
| 7 | -2 | (27,16) | (28,16) | 14 |
| 8 | 14 | (28,16) | (29,17) | 10 |
| 9 | 10 | (29,17) | (30,18) | 6 |
| 10 | 6 | (30,18) | - | - |

Pixels plotted:

```text
(20,10) (21,11) (22,12) (23,12) (24,13) (25,14)
(26,15) (27,16) (28,16) (29,17) (30,18)
```

**Answer: the 11 pixels above, from (20,10) to (30,18).**

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. dx and dy are
   A. 8 and 10
   B. 30 and 18
   C. 10 and 8
   D. 20 and 10
   Answer: C. 30-20, 18-10. (Key point: dx dy)

2. p0 =
   A. 16
   B. -4
   C. 2
   D. 6
   Answer: D. 16 - 10. (Key point: p0)

3. If p >= 0, p_next =
   A. p - 4
   B. p + 16
   C. p + 4
   D. p - 16
   Answer: A. 2dy - 2dx = -4. (Key point: Updates)

4. The next pixel after (20,10) is
   A. (21,10)
   B. (21,11)
   C. (22,11)
   D. (20,11)
   Answer: B. p0 = 6 >= 0. (Key point: First pixel)

## Close variants set in other exams

- [Bresenham: line (10,20) to (15,2)](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Adigitize-line-10-20-15-2) — Computer Graphics, chapter 2, asked 4×

## Related in Computer Graphics

- [Bresenham: line (25,20) to (15,10)](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Adigitize-line-25-20-15-10) — Computer Graphics, chapter 2
- [Bresenham: endpoints (10,18),(15,8)](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Adigitize-point-10-18-15-8) — Computer Graphics, chapter 2
- [DDA versus Bresenham line algorithm](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Adda-vs-bresenham-line) — Computer Graphics, chapter 2, asked 6×
- [Write Bresenham's line algorithm](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Abresenham-line-algorithm) — Computer Graphics, chapter 2, asked 3×
- [Midpoint circle: r=10, centre (20,30)](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Acircle-r10-center-20-30) — Computer Graphics, chapter 2
- [3D rotation about axis (1,2,3)-(10,20,30)](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Arotate-3d-axis-1-2-3) — Computer Graphics, chapter 4

## Related in other subjects

- [AVL tree for 10 20 30 50 45 40 8 5 3](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aavl-build-10-20-30) — Data Structure and Algorithm, chapter 6
- [AVL tree for 10, 20, 30, 35, 50, ...](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aavl-build-10-20-30-35) — Data Structure and Algorithm, chapter 6
- [Series 1×10+3×20+6×30+…](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aseries-1x10-3x20) — Computer Programming, chapter 5
- [Audible noise of 765 kV line (18 kV/cm outer)](https://www.bctengineer.com/question.md?key=semester_8%2Fhigh_voltage_engineering%3Aan-765kv-centre-phase-30m) — High Voltage Engineering, chapter 5, asked 4×
