2081 1

CSC214 · 2081 · 10 marks

Derive the expression for Bresenham's Line Drawing algorithm. Trace the points in the line path with starting point (6, 12) and end point (10, 5) using Bresenham’s line drawing algorithm.

Derive the expression for Bresenham's Line Drawing algorithm. Trace the points in the line path with starting point (6, 12) and end point (10, 5) using Bresenham’s line drawing algorithm.[10]

Computer GraphicsChapter 2: Scan Conversion AlgorithmScan Converting a Point and a straight LineNumerical: Bresenham's line algorithm

Bresenham's Line Drawing Algorithm

Part 1: Derivation

Concept

Bresenham's algorithm draws a line using only integer arithmetic (addition, subtraction, and multiplication by 2). It selects, at each step, the pixel nearest to the true line path.

Derivation (for slope $0 < m < 1$)

Assume we have plotted pixel $(x_k, y_k)$. The next pixel is either:

  • E: $(x_k+1, y_k)$
  • NE: $(x_k+1, y_k+1)$

True line at $x = x_k+1$: $$y = m(x_k+1) + b, \qquad m = \frac{\Delta y}{\Delta x}$$

Distances from true line to the two candidates: $$d_1 = y - y_k = m(x_k+1) + b - y_k$$ $$d_2 = (y_k+1) - y = y_k + 1 - m(x_k+1) - b$$

$$d_1 - d_2 = 2m(x_k+1) + 2b - 2y_k - 1$$

Define decision parameter $p_k = \Delta x (d_1 - d_2)$ (multiply by $\Delta x > 0$ to remove the fraction):

$$p_k = 2\Delta y \cdot x_k - 2\Delta x \cdot y_k + c, \quad c = 2\Delta y + \Delta x(2b-1)$$

Rule:

  • If $p_k < 0$: choose E, plot $(x_k+1, y_k)$
  • If $p_k \ge 0$: choose NE, plot $(x_k+1, y_k+1)$

Recurrence

$$p_{k+1} - p_k = 2\Delta y (x_{k+1}-x_k) - 2\Delta x (y_{k+1}-y_k)$$

Since $x_{k+1} = x_k + 1$:

CaseNext $y$Update
$p_k < 0$$y_k$$p_{k+1} = p_k + 2\Delta y$
$p_k \ge 0$$y_k+1$$p_{k+1} = p_k + 2\Delta y - 2\Delta x$

Initial value: $$\boxed{p_0 = 2\Delta y - \Delta x}$$


Part 2: Tracing (6, 12) to (10, 5)

Parameters

$$x_1=6,\ y_1=12,\ x_2=10,\ y_2=5$$ $$\Delta x = |10-6| = 4, \qquad \Delta y = |5-12| = 7$$

Slope magnitude $= \frac{7}{4} = 1.75 > 1$ → steep line, so we step along the y-axis.

Since $x$ increases ($6 \to 10$) and $y$ decreases ($12 \to 5$), we step -1 in y each step and possibly +1 in x.

Adjusted rules (driving variable = y, $\Delta y = 7$ steps)

$$p_0 = 2\Delta x - \Delta y = 2(4) - 7 = 1$$

  • $2\Delta x = 8$
  • $2\Delta x - 2\Delta y = 8 - 14 = -6$

Rules (step $y \to y-1$ each iteration):

  • If $p_k < 0$: $x$ stays, $p_{k+1} = p_k + 8$
  • If $p_k \ge 0$: $x \to x+1$, $p_{k+1} = p_k - 6$

Trace Table

Start plotted: $(6, 12)$, $p_0 = 1$

Step $k$$p_k$DecisionNew $(x, y)$Next $p$
01$\ge 0$: x+1, y-1(7, 11)$1-6=-5$
1-5$<0$: x same, y-1(7, 10)$-5+8=3$
23$\ge 0$: x+1, y-1(8, 9)$3-6=-3$
3-3$<0$: x same, y-1(8, 8)$-3+8=5$
45$\ge 0$: x+1, y-1(9, 7)$5-6=-1$
5-1$<0$: x same, y-1(9, 6)$-1+8=7$
67$\ge 0$: x+1, y-1(10, 5)end

Points Plotted

$$(6,12),\ (7,11),\ (7,10),\ (8,9),\ (8,8),\ (9,7),\ (9,6),\ (10,5)$$

The endpoint $(10, 5)$ is reached correctly after 7 steps.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.