Skip to main content
Browse topics

Midpoint Circle Algorithm

3 min read Updated June 30, 2026
Share

The midpoint circle algorithm determines the pixel points needed to draw a circle. Circles are a frequently used component in pictures and graphs.

Given a center and radius:

text
Center position : (xc, yc)
Radius          : r

Circle equation approaches

The Pythagorean theorem expresses the circle distance relationship in Cartesian coordinates as:

text
(x - xc)^2 + (y - yc)^2 = r^2

That equation can calculate successive y values by stepping x:

text
y = yc ± sqrt( r^2 - (xc - x)^2 )

This approach is slow, and spacing between pixels is not uniform. One way to eliminate unequal spacing is to use polar coordinates r and θ:

text
x = xc + r cos θ
y = yc + r sin θ

The step size for θ depends on the display device.

Computations can be reduced by considering circle symmetry. The shape is similar in each quadrant — and in each octant. Once pixel positions for one octant are calculated, their reflections fill the rest of the circle.

Floating-point methods still cost too much computation time. The midpoint circle algorithm reduces that cost with integer decision parameters.

The midpoint circle algorithm

text
Screen center point     : (xc, yc)
Calculated pixel offset : (x, y)
Screen position         : (xc + x, yc + y)

The circle function is defined as:

text
fcircle(x, y) = x^2 + y^2 - r^2

Any point (x, y) on the boundary of a circle with radius r satisfies fcircle(x, y) = 0:

text
fcircle(x, y) < 0   →  (x, y) is inside the circle boundary
fcircle(x, y) = 0   →  (x, y) is on the circle boundary
fcircle(x, y) > 0   →  (x, y) is outside the circle boundary

Decision parameter

Sampling position:

text
(xk, yk)

Next pixel candidates:

text
(xk+1, yk)     or     (xk+1, yk-1)

The circle-function tests are performed at the midpoint between those two pixels. Assuming the pixel at (xk, yk) was just plotted, decide whether (xk+1, yk) or (xk+1, yk-1) is closer to the circle:

text
pk = fcircle(xk+1, yk - 1/2)
   = (xk + 1)^2 + (yk - 1/2)^2 - r^2
  • If pk < 0, the midpoint is inside the circle → choose (xk+1, yk)
  • Otherwise the midpoint is outside or on the boundary → choose (xk+1, yk-1)

Incremental updates

Successive decision parameters use incremental calculations:

text
pk+1 = fcircle(xk+1 + 1, yk+1 - 1/2)
     = [(xk + 1) + 1]^2 + [yk+1 - 1/2]^2 - r^2

pk+1 = pk + 2(xk+1) + (yk+1^2 - yk^2) - (yk+1 - yk) + 1

where yk+1 is either yk or yk-1, depending on the sign of pk.

Increments for pk+1:

text
if pk < 0:   pk+1 = pk + 2xk+1 + 1
otherwise:   pk+1 = pk + 2xk+1 + 1 - 2yk+1

The doubled terms also update incrementally:

text
2xk+1 = 2xk + 2
2yk+1 = 2yk - 2

Initial decision parameter

Start at (x0, y0) = (0, r):

text
p0 = fcircle(1, r - 1/2)
   = 1 + (r - 1/2)^2 - r^2
   = 5/4 - r

If radius r is an integer, round to:

text
p0 = 1 - r

since all later increments are integers.

Algorithm steps

  1. Input radius r and center (xc, yc). Obtain the first point on the origin-centered circle as (x0, y0) = (0, r).
  2. Calculate the initial decision parameter:
text
p0 = 5/4 - r
  1. At each xk position, starting at k = 0:
text
if pk < 0:
    next point = (xk+1, yk)
    pk+1 = pk + 2xk+1 + 1
else:
    next point = (xk+1, yk-1)
    pk+1 = pk + 2xk+1 + 1 - 2yk+1

where:
    2xk+1 = 2xk + 2
    2yk+1 = 2yk - 2
  1. Determine symmetry points in the other seven octants.
  2. Move each calculated pixel (x, y) onto the circular path centered on (xc, yc):
text
plot(x + xc, y + yc)
  1. Repeat steps 3–5 until x ≥ y.

Pseudocode

text
Input: xc, yc, r
x ← 0
y ← r
p ← 1 - r

plotEightWay(xc, yc, x, y)

while x < y:
    x ← x + 1
    if p < 0:
        p ← p + 2x + 1
    else:
        y ← y - 1
        p ← p + 2(x - y) + 1
    plotEightWay(xc, yc, x, y)

Eight-way symmetry plots:

text
(xc + x, yc + y)   (xc - x, yc + y)
(xc + x, yc - y)   (xc - x, yc - y)
(xc + y, yc + x)   (xc - y, yc + x)
(xc + y, yc - x)   (xc - y, yc - x)

Circle Algorithm Using C Programming

c
#include <stdio.h>
#include <conio.h>
#include <graphics.h>

void cliplot(int xctr, int yctr, int x, int y);
void Drawcircle(int x1, int y1, int r);

void main() {
   int gd = DETECT, gm;
   int x, y, r;

   printf("Enter the Mid points and Radius: ");
   scanf("%d%d%d", &x, &y, &r);

   initgraph(&gd, &gm, "");
   Drawcircle(x, y, r);
   getch();
   closegraph();
}

void Drawcircle(int x1, int y1, int r) {
   int x = 0, y = r, p = 1 - r;

   cliplot(x1, y1, x, y);
   while (x < y) {
      x++;
      if (p < 0)
         p += 2 * x + 1;
      else {
         y--;
         p += 2 * (x - y) + 1;
      }
      cliplot(x1, y1, x, y);
   }
}

void cliplot(int xctr, int yctr, int x, int y) {
   putpixel(xctr + x, yctr + y, 1);
   putpixel(xctr - x, yctr + y, 1);
   putpixel(xctr + x, yctr - y, 1);
   putpixel(xctr - x, yctr - y, 1);
   putpixel(xctr + y, yctr + x, 1);
   putpixel(xctr - y, yctr + x, 1);
   putpixel(xctr + y, yctr - x, 1);
   putpixel(xctr - y, yctr - x, 1);
}

Sample Output

text
Enter the Mid points and Radius: 200 200 80
(draws a circle centered at (200, 200) with radius 80)

Frequently Asked Questions

What is the midpoint circle algorithm?
It draws a circle using integer arithmetic by choosing the next pixel with a midpoint decision parameter.
Why use the midpoint circle algorithm?
It is efficient and avoids floating-point math by exploiting the circle's eight-way symmetry.
What is eight-way symmetry?
Computing one octant of the circle lets you mirror points to fill the other seven octants.

Related tutorials

Search tutorials