3 Line And Circle Drawing Algorithms

Computer Graphics Ā· Unit 3

Line and Circle Drawing Algorithms

Exam-focused notes for Line and Circle Drawing Algorithms (Computer Graphics, BIT304): what the TU syllabus asks and how it has actually been tested, with 7 solved past questions from this unit.

Line and Circle Drawing Algorithms in short

Lines and circles are the most basic shapes in a drawing. Because the screen is a grid of pixels, we need fast algorithms that pick the pixels closest to the true shape.

Line and Circle Drawing Algorithms: notes

DDA line drawing algorithm

The DDA (Digital Differential Analyzer) algorithm draws a line by adding a small fixed step to x and y at each position. The line from $(x_1,y_1)$ to $(x_2,y_2)$ has slope $m = \dfrac{\Delta y}{\Delta x}$.

Algorithm:

  • Find $dx = x_2 - x_1$ and $dy = y_2 - y_1$.
  • Let $steps = \max(|dx|, |dy|)$.
  • Find the increments $x_{inc} = dx / steps$ and $y_{inc} = dy / steps$.
  • Plot $(x_1, y_1)$. Then repeat $steps$ times: add the increments to $x$ and $y$ and plot the rounded point.

Example: line from $(20,10)$ to $(30,18)$.

$$\begin{aligned} dx &= 10, \quad dy = 8 \ steps &= 10 \ x_{inc} &= 1, \quad y_{inc} = 0.8 \end{aligned}$$

kxyPlotted pixel
02010(20, 10)
12110.8(21, 11)
22211.6(22, 12)
32312.4(23, 12)
42413.2(24, 13)
52514.0(25, 14)
62614.8(26, 15)
72715.6(27, 16)
82816.4(28, 16)
92917.2(29, 17)
103018.0(30, 18)

Advantages: simple and faster than using $y = mx + c$ directly, since it avoids multiplication. Disadvantages: uses floating point and rounding, and the error builds up on long lines.

What this unit covers

  • DDA line drawing algorithm
  • Bresenham's line drawing algorithm
  • Comparison of line drawing algorithms
  • Midpoint circle drawing algorithm
  • Bresenham's circle drawing algorithm
  • Decision parameters for circle generation

DDA line drawing algorithm

2082 Ā· 10 marks

Bresenham's Circle Drawing Algorithm & DDA Line Algorithm Trace [10]

Show solved answer

Model Answer: Bresenham's Circle Drawing Algorithm & DDA Line Trace [10 marks]

Given Data (Extracted)

Part B (numeric):

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

Part A is descriptive (no numeric inputs required).


Part A: Bresenham's Circle Drawing Algorithm [5 marks]

Definition: Bresenham's circle drawing algorithm is an efficient scan-conversion technique that plots the pixels closest to a true circle using only integer arithmetic. It uses the eight-way symmetry of a circle, so it computes points only for one octant ($0°$ to $45°$) and reflects them to the other seven.

Eight-Way Symmetry: For a point $(x, y)$ on a circle centered at origin, the following also lie on the circle:

$$(x, y),\ (-x, y),\ (x, -y),\ (-x, -y),\ (y, x),\ (-y, x),\ (y, -x),\ (-y, -x)$$

Algorithm Steps:

  1. Input radius $r$ and center $(x_c, y_c)$.
  2. Initialize starting point: $x = 0,\ y = r$.
  3. Compute initial decision parameter: $p_0 = 3 - 2r$.
  4. At each step, test $p_k$:
    • If $p_k < 0$: next point is $(x_k + 1,\ y_k)$ and $p_{k+1} = p_k + 4x_k + 6$
    • If $p_k \ge 0$: next point is $(x_k + 1,\ y_k - 1)$ and $p_{k+1} = p_k + 4(x_k - y_k) + 10$
  5. Plot all 8 symmetric points, translated by adding $(x_c, y_c)$.
  6. Repeat steps 4-5 until $x \ge y$.

Advantages:

  • Uses only integer addition/subtraction (no multiplication or trigonometry)
  • Fast and hardware-friendly
  • Produces smooth, symmetric circles

Part B: DDA Algorithm Trace - Line from $(2, 2)$ to $(6, 6)$ [5 marks]

Step 1: Compute differences: $$dx = x_2 - x_1 = 6 - 2 = 4$$ $$dy = y_2 - y_1 = 6 - 2 = 4$$

Step 2: Number of steps: $$steps = \max(|dx|, |dy|) = \max(4, 4) = 4$$

Step 3: Increments: $$x_{inc} = \frac{dx}{steps} = \frac{4}{4} = 1, \qquad y_{inc} = \frac{dy}{steps} = \frac{4}{4} = 1$$

Step 4: Iteration Table:

Step$x$$y$Pixel Plotted $(\text{round}(x), \text{round}(y))$
02.02.0(2, 2)
13.03.0(3, 3)
24.04.0(4, 4)
35.05.0(5, 5)
46.06.0(6, 6)

Explanation: Slope $m = \dfrac{dy}{dx} = \dfrac{4}{4} = 1$ (a $45°$ line). Both $x$ and $y$ increase by exactly 1 each step, giving a perfect diagonal.

Result: Pixels plotted: $(2,2), (3,3), (4,4), (5,5), (6,6)$ - five pixels forming a continuous diagonal line.

Open this answer on its own page →

Midpoint circle drawing algorithm

2081 Ā· 5 marks

Digitize circle with center (0, 0) and radius = 6. [5]

  • Center: $(xc, yc) = (0, 0)$ - Radius: $r = 6$ - Start point: $(x, y) = (0, r) = (0, 6)$ - Initial decision parameter: $p0 = 1 - r = 1 - 6 = -5$ We compute points in the second octant ($x$ from 0 up to $x = y$), then apply 8-way symmetry. - If $p < 0$: choose E, next $x+1$, $y$ same,
Open this answer on its own page →

0 Ā· 5 marks

Write mid point circle drawing algorithm. [5]

The Midpoint Circle Drawing Algorithm (also called Bresenham's Circle Algorithm) is used to draw circles on a raster display by determining which pixels should be illuminated to form a circle with a given center and radius. The algorithm uses the midpoint between two candidate pixels to decide wh...

Open this answer on its own page →

Bresenham's line drawing algorithm

2080 Ā· 10 marks

Write the algorithm for Bresenham's line drawing? Digitize a line with end points A(6, 9) and B(10,5) using Bresenham's line drawing algorithm.[10]

  • Endpoint A: $(x1, y1) = (6, 9)$ - Endpoint B: $(x2, y2) = (10, 5)$ 1. Input the two endpoints $(x1, y1)$ and $(x2, y2)$. 2. Compute $\Delta x = x2 - x1$ and $\Delta y = y2 - y1$. 3. Plot the first point $(x1, y1)$. 4. Calculate the initial decision parameter: $$p0 = 2\Delta y - \Delta x$$ 5. At...
Open this answer on its own page →

2079 Ā· 10 marks

List the major differences between DDA and Bresenham's algorithm. Illustrate the Bresenham's algorithm to the line with end points(10, 6) and (12, 1).[10]

Show solved answer

DDA vs Bresenham's Algorithm & Numerical Illustration

Given

  • Endpoint 1: $(x_1, y_1) = (10, 6)$
  • Endpoint 2: $(x_2, y_2) = (12, 1)$

Major Differences between DDA and Bresenham's Algorithm

FeatureDDA AlgorithmBresenham's Algorithm
ComputationUses floating-point arithmeticUses only integer arithmetic
SpeedSlower (floating-point operations)Faster (integer operations)
RoundingRequires rounding each stepNo rounding needed
AccuracyLess accurate (rounding errors)More accurate
OperationsMultiplication and divisionOnly addition and subtraction
Decision ParameterNone usedUses decision parameter $p_k$
EfficiencyLess efficientMore efficient
HardwareDifficult to implementEasy to implement

STEP 2 - Bresenham's Line: (10, 6) to (12, 1)

Calculate parameters

$$dx = x_2 - x_1 = 12 - 10 = 2$$ $$dy = y_2 - y_1 = 1 - 6 = -5$$ $$|dx| = 2, \quad |dy| = 5$$

Since $|dy| > |dx|$, the line is steep ($|m| > 1$). Drive the algorithm along the y-axis. Here $y$ decreases (6 → 1) so $y$ steps by $-1$; $x$ increases since $x_2 > x_1$.

Initialize decision parameter

$$p_0 = 2|dx| - |dy| = 2(2) - 5 = -1$$

Constants: $$2|dx| = 4, \qquad 2|dx| - 2|dy| = 4 - 10 = -6$$

Decision rule (steep line, y-axis driven)

  • If $p_k < 0$: next point $(x_k,\ y_k - 1)$, and $p_{k+1} = p_k + 2|dx|$
  • If $p_k \ge 0$: next point $(x_k + 1,\ y_k - 1)$, and $p_{k+1} = p_k + 2|dx| - 2|dy|$

Iteration Table

Step $k$$p_k$ConditionPoint $(x, y)$$p_{k+1}$
0-1$p_0 < 0$(10, 6)$-1 + 4 = 3$
13$p_1 \ge 0$(11, 5)$3 - 6 = -3$
2-3$p_2 < 0$(11, 4)$-3 + 4 = 1$
31$p_3 \ge 0$(12, 3)$1 - 6 = -5$
4-5$p_4 < 0$(12, 2)$-5 + 4 = -1$
5--(12, 1)-

Final Plotted Pixels

$$(10, 6) \to (11, 5) \to (11, 4) \to (12, 3) \to (12, 2) \to (12, 1)$$

Conclusion

Bresenham's algorithm avoids floating-point arithmetic, using only integer addition/subtraction and a decision parameter, making it faster, more accurate, and easier to implement in hardware than DDA.

Open this answer on its own page →

0 Ā· 5 marks

Derive the Bresenham's decision parameter to draw a line with negative slope. [5]

For a line with negative slope (m < -1 or -1 < m < 0), we move from point (xā‚€, yā‚€) to (xā‚™, yā‚™) where: - x increases (or stays same) - y decreases We assume the line equation: y = mx + c where m is negative At each step, we are at pixel (xā‚–, yā‚–). We must choose between two candidate pixels: - P₁: ...

Open this answer on its own page →

Decision parameters for circle generation

2079 Ā· 10 marks

How decision parameter can be used to draw circle? Calculate the points to draw a circle having radius 5 and center as (10, 5).[10]

  • Radius $r = 5$ - Center $(xc, yc) = (10, 5)$ The Midpoint Circle Algorithm uses a decision parameter to choose between two candidate pixels while scanning one octant, avoiding floating-point square roots. For a circle centered at origin: $$f(x, y) = x^2 + y^2 - r^2$$ - $f < 0$: point inside cir...
Open this answer on its own page →