2079 1

CSC214 ยท 2079 ยท 10 marks

Explain the working details of Mid-point circle algorithm? Trace the points along the line path having two end points (6,9) and (2,3) using Bresenham's line drawing algorithm.

Explain the working details of Mid-point circle algorithm? Trace the points along the line path having two end points (6,9) and (2,3) using Bresenham's line drawing algorithm.[10]

Computer GraphicsChapter 2: Scan Conversion AlgorithmScan Converting a Point and a straight LineNumerical: Bresenham line drawing

Mid-Point Circle Algorithm and Bresenham's Line Trace


PART 1: Mid-Point Circle Algorithm

Concept

The Mid-Point Circle Algorithm draws a circle using only integer arithmetic (additions/subtractions). At each step it uses a decision parameter to choose between two candidate pixels.

Eight-Way Symmetry

A circle centered at origin has 8-fold symmetry. If $(x, y)$ lies on the circle, so do:

$$(\pm x, \pm y), \quad (\pm y, \pm x)$$

So only one octant (0 to 45ยฐ) needs to be computed; the rest are reflected.

Circle Function

For a circle of radius $r$ centered at origin:

$$f(x, y) = x^2 + y^2 - r^2$$

  • $f < 0$: point inside
  • $f = 0$: point on circle
  • $f > 0$: point outside

Decision Parameter

Starting at $(0, r)$, moving in $+x$, the next pixel is either E $(x+1, y)$ or SE $(x+1, y-1)$. The midpoint is $\left(x+1, y-\tfrac{1}{2}\right)$:

$$P_k = f\left(x_k+1,\ y_k-\tfrac{1}{2}\right) = (x_k+1)^2 + \left(y_k-\tfrac{1}{2}\right)^2 - r^2$$

Initial value:

$$P_0 = \tfrac{5}{4} - r \approx 1 - r$$

Decision Rule

ConditionNext PixelUpdate
$P_k < 0$E $(x+1, y)$$P_{k+1} = P_k + 2x_{k+1} + 1$
$P_k \ge 0$SE $(x+1, y-1)$$P_{k+1} = P_k + 2x_{k+1} - 2y_{k+1} + 1$

Algorithm

1. (x, y) = (0, r);  P = 1 - r
2. Plot (x, y) and 8 symmetric points
3. While x < y:
       x = x + 1
       if P < 0:  P = P + 2x + 1
       else:      y = y - 1;  P = P + 2x - 2y + 1
       Plot (x, y) and 8 symmetric points

Advantages

  • Integer arithmetic only, no floating point
  • Fast and efficient
  • Accurate circle approximation

PART 2: Bresenham's Line Trace from (6, 9) to (2, 3)

Given data

  • Start: $(x_1, y_1) = (6, 9)$
  • End: $(x_2, y_2) = (2, 3)$

Step 1: Differences

$$\Delta x = |x_2 - x_1| = |2 - 6| = 4$$ $$\Delta y = |y_2 - y_1| = |3 - 9| = 6$$

Since $\Delta y > \Delta x$, slope $> 1$, so we step along the y-axis and decide x.

Direction of travel (from start to end):

  • x decreases: $x_{inc} = -1$
  • y decreases: $y_{inc} = -1$

Step 2: Initial Decision Parameter

For the steep case (driving along y):

$$P_0 = 2\Delta x - \Delta y = 2(4) - 6 = 2$$

Step 3: Update Rules (driving along y)

ConditionNext pointUpdate
$P_k < 0$y steps, x fixed$P_{k+1} = P_k + 2\Delta x$
$P_k \ge 0$x steps and y steps$P_{k+1} = P_k + 2\Delta x - 2\Delta y$

where $2\Delta x = 8$ and $2\Delta x - 2\Delta y = 8 - 12 = -4$.

Step 4: Trace Table

Plot start point $(6, 9)$. Then iterate for $\Delta y = 6$ steps (y from 9 down to 3).

Step$P_k$DecisionNext $(x, y)$
start--$(6, 9)$
1$P_0 = 2 \ge 0$x--, y--: $P = 2 - 4 = -2$$(5, 8)$
2$P_1 = -2 < 0$y--: $P = -2 + 8 = 6$$(5, 7)$
3$P_2 = 6 \ge 0$x--, y--: $P = 6 - 4 = 2$$(4, 6)$
4$P_3 = 2 \ge 0$x--, y--: $P = 2 - 4 = -2$$(3, 5)$
5$P_4 = -2 < 0$y--: $P = -2 + 8 = 6$$(3, 4)$
6$P_5 = 6 \ge 0$x--, y--: $P = 6 - 4 = 2$$(2, 3)$

Final Plotted Points

$$(6, 9),\ (5, 8),\ (5, 7),\ (4, 6),\ (3, 5),\ (3, 4),\ (2, 3)$$

Verification

Line has slope $\dfrac{3-9}{2-6} = \dfrac{-6}{-4} = 1.5$. The traced points correctly approximate this steep line, ending exactly at $(2, 3)$. โœ“

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