Circle Drawing Algorithms

Midpoint Circle Algorithm in Computer Graphics

The Midpoint Circle Algorithm draws a circle by calculating one octant and reflecting each point into the other seven octants. It uses an integer decision parameter, so it is efficient and widely taught in computer graphics courses.

Published May 28, 2026 - 9 min read

What is the Midpoint Circle Algorithm?

The Midpoint Circle Algorithm is a raster graphics algorithm used to draw a circle on a pixel screen. Instead of checking every point on the screen, it calculates the best next pixel around the circle boundary.

The algorithm starts at the top of the circle, moves through one octant, and uses symmetry to plot the remaining seven matching points. This makes circle drawing much faster than testing all possible coordinates.

Eight-way symmetry of a circle

A circle is symmetric in eight directions. If one point (x, y) lies on the circle relative to the center, then seven more points can be plotted without recalculating them.

(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)

Decision parameter formula

For a circle with radius r, the algorithm starts with:

x = 0
y = r
p = 1 - r

If p < 0, the midpoint is inside the circle, so x increases and y stays the same. If p >= 0, the midpoint is outside or on the circle, so x increases and y decreases.

Steps of Midpoint Circle Algorithm

  1. Read the circle center (xc, yc) and radius r.
  2. Initialize x = 0, y = r, and p = 1 - r.
  3. Plot the eight symmetric points.
  4. If p < 0, update p = p + 2x + 3.
  5. If p >= 0, decrease y and update p = p + 2(x - y) + 5.
  6. Increase x and repeat until x > y.

Example calculation

Suppose the radius is 5. The initial values are:

x = 0
y = 5
p = 1 - 5 = -4
Step x y p Decision
005-4Inside, y unchanged
115-1Inside, y unchanged
2254Outside, decrease y
3343Outside, decrease y

Midpoint Circle Algorithm program in C using graphics.h

This program draws a circle using the midpoint method. It does not call the built-in circle() function; instead, it plots pixels manually with putpixel().

C / graphics.h
#include <graphics.h>
#include <conio.h>
#include <dos.h>
#include <stdio.h>

void plotCirclePoints(int xc, int yc, int x, int y)
{
    putpixel(xc + x, yc + y, WHITE);
    putpixel(xc - x, yc + y, WHITE);
    putpixel(xc + x, yc - y, WHITE);
    putpixel(xc - x, yc - y, WHITE);
    putpixel(xc + y, yc + x, WHITE);
    putpixel(xc - y, yc + x, WHITE);
    putpixel(xc + y, yc - x, WHITE);
    putpixel(xc - y, yc - x, WHITE);
}

void drawMidpointCircle(int xc, int yc, int radius)
{
    int x = 0;
    int y = radius;
    int p = 1 - radius;

    plotCirclePoints(xc, yc, x, y);

    while (x < y)
    {
        x++;

        if (p < 0)
        {
            p = p + (2 * x) + 3;
        }
        else
        {
            y--;
            p = p + (2 * (x - y)) + 5;
        }

        plotCirclePoints(xc, yc, x, y);
        delay(40);
    }
}

int main()
{
    int gd = DETECT, gm;
    int xc, yc, radius;

    printf("Enter center x y: ");
    scanf("%d %d", &xc, &yc);

    printf("Enter radius: ");
    scanf("%d", &radius);

    initgraph(&gd, &gm, "");

    drawMidpointCircle(xc, yc, radius);

    getch();
    closegraph();
    return 0;
}

Try it online: open the graphics.h online compiler, paste the program, then use center 320 240 and radius 100.

Advantages of Midpoint Circle Algorithm

  • It uses integer arithmetic, so it is efficient.
  • It plots only one octant and mirrors the remaining points.
  • It avoids expensive trigonometric functions.
  • It is easy to adapt for classic graphics.h programs.

Limitations

  • The circle boundary can look jagged because pixels are square.
  • The algorithm draws only the outline, not a filled circle.
  • Anti-aliasing is not included in the classic midpoint approach.

Common mistakes

Plotting only one point

If you plot only (x, y), you will draw just one octant. Use eight-way symmetry to complete the circle.

Calling circle() instead of putpixel()

The goal is to implement the algorithm manually. Calling circle(xc, yc, radius) uses the built-in graphics.h function and skips the midpoint logic.

Using the wrong loop condition

The loop should continue while x < y or x <= y. Stopping too early leaves gaps near the diagonal of the circle.

Summary

The Midpoint Circle Algorithm draws a circle efficiently by using a decision parameter and eight-way symmetry. It is one of the most important beginner algorithms for understanding how curved shapes are rasterized on a pixel screen.