Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

1.7 Bresenham / Midpoint Circle Algorithm

Lesson 8 of 32 in the free Computer Graphics notes on Siksha Sarovar, written by Rohit Jangra.

Goal

Scan-convert a circle of radius r centered at origin (later translated) using only integer arithmetic, exploiting 8-way symmetry.

8-Way Symmetry

For a pixel (x, y) on the circle, the points (+/-x, +/-y) and (+/-y, +/-x) are also on the circle. We compute one octant (from (0, r) clockwise to where x = y) and mirror it.

Decision Variable (Midpoint)

At step k we are at (x_k, y_k). Next candidates are E = (x_k+1, y_k) and SE = (x_k+1, y_k-1). The midpoint is M = (x_k+1, y_k - 0.5). The implicit circle function f(x, y) = x^2 + y^2 - r^2.

  • If f(M) < 0, midpoint is inside circle -> choose E.
  • If f(M) >= 0, midpoint is outside or on -> choose SE.

To stay integer, define p_k = f(M) and update incrementally:

  • p_0 = 1 - r (after multiplying out and simplifying).
  • If p_k < 0: p_(k+1) = p_k + 2*x_(k+1) + 1.
  • Else: p_(k+1) = p_k + 2x_(k+1) + 1 - 2y_(k+1).

Worked Example, r = 10

Start (x, y) = (0, 10), p = 1 - 10 = -9. Plot 8 symmetric points each step.

kxypnext
0010-9E
1110-9 + 2*1 + 1 = -6E
2210-6 + 2*2 + 1 = -1E
3310-1 + 2*3 + 1 = 6SE
4496 + 24 + 1 - 29 = -3E
559-3 + 2*5 + 1 = 8SE
6688 + 26 + 1 - 28 = 5SE
777x >= y stop-

Octant pixels: (0,10) (1,10) (2,10) (3,10) (4,9) (5,9) (6,8) (7,7). Mirror to fill the full circle.

Why Midpoint

Pure Bresenham circle uses a slightly different decision; the midpoint formulation is cleaner and generalizes to ellipses (two-region midpoint algorithm where the slope crosses 1).

Properties

  • Integer-only arithmetic.
  • At most 1 unit normal error.
  • 8x speedup vs naive scan from symmetry.
  • Easily extended to filled circle by drawing horizontal spans between symmetric pairs.