Midpoint circle drawing algorithm, pixel by pixel
A circle is continuous. A pixel grid needs a rule for choosing squares. Follow the midpoint algorithm, compare two boundary rules at the same radius, and check every selected coordinate.
Same radius. Different pixels.
At radius 5, the midpoint outline and the four-neighbor boundary both use 28 pixels. Yet 32 positions differ between their sets. Equal material counts do not guarantee the same shape. The eight-neighbor boundary uses 36 pixels, and the filled disk contains 81.
Every view uses center (5, 5), radius 5, and the same 11 × 11 grid. Columns and rows start at 0, from the top left. Dashed circles show the continuous radius; crosshairs mark the center.
SharedMidpoint onlyComparison only
Inspect exact differing coordinates
Coordinates are (column, row). These lists show positions, not a visual-quality score.
Midpoint only: (3,0) (4,0) (6,0) (7,0) (0,3) (10,3) (0,4) (10,4) (0,6) (10,6) (0,7) (10,7) (3,10) (4,10) (6,10) (7,10)
Comparison only: (3,1) (4,1) (6,1) (7,1) (1,3) (9,3) (1,4) (9,4) (1,6) (9,6) (1,7) (9,7) (3,9) (4,9) (6,9) (7,9)
Follow the first octant
Start with x = 0, y = r, d = 1 − r. Each row emits its point and up to seven reflections, then chooses the next step: E keeps y; SE decreases y. Reflected duplicates count once.
| Step | x | y | d before update | Next step |
|---|---|---|---|---|
| 0 | 0 | 5 | -4 | E |
| 1 | 1 | 5 | -1 | E |
| 2 | 2 | 5 | 4 | SE |
| 3 | 3 | 4 | 3 | Stop after this point |
Read the midpoint outline row by row
| Row | Occupied columns | Pixels |
|---|---|---|
| 0 | 3–7 | 5 |
| 1 | 2; 8 | 2 |
| 2 | 1; 9 | 2 |
| 3 | 0; 10 | 2 |
| 4 | 0; 10 | 2 |
| 5 | 0; 10 | 2 |
| 6 | 0; 10 | 2 |
| 7 | 0; 10 | 2 |
| 8 | 1; 9 | 2 |
| 9 | 2; 8 | 2 |
| 10 | 3–7 | 5 |
How the midpoint circle drawing algorithm works
The UIC circle-drawing notes describe choosing between neighboring pixels in one octant, then reflecting the choice around the center. This reference uses the following integer recurrence:
x = 0; y = r; d = 1 - r
while x <= y:
emit the eight reflections of (x, y)
if d < 0:
d = d + 2*x + 3
else:
d = d + 2*(x - y) + 5
y = y - 1
x = x + 1The coordinates here are relative to the center. Add (r, r) to place them in the 2r + 1 grid. If d is zero, this recurrence takes the SE branch. Axis and diagonal reflections can repeat a coordinate; the count includes each selected pixel only once.
What the comparison rules select
- Filled disk
- Keep a pixel when its center satisfies (x − r)² + (y − r)² ≤ r². Centers exactly on the circle are included.
- Four-neighbor boundary
- Keep a disk pixel if at least one neighbor directly above, below, left or right is outside the disk.
- Eight-neighbor boundary
- Also inspect the four diagonal neighbors. A disk pixel remains if any of these eight neighbors is outside.
These rules answer different questions. The boundary rules keep only centers inside the disk. Midpoint stepping follows the curve and can choose centers just outside it. A larger pixel count or a smaller difference does not establish better visual quality.
Red Blob Games’ circle-on-a-grid explanation discusses fills, outlines, center positions and radius conventions. Stefan Gustavson’s original midpoint demonstration provides another integer formulation. Those sources explain the algorithms; the comparison data below were computed for this reference.
Results for 64 integer radii
We computed radii 1–64, four pixel sets per radius: 256 method cases. Midpoint and four-neighbor masks differ at 63 of 64 radii; midpoint and eight-neighbor masks differ at all 64. The four-neighbor mask agrees with midpoint only at radius 1 in this range.
“Differing positions” means the symmetric difference: the number of coordinates included by exactly one method. It measures a change in selected pixels, not distance from the curve, aesthetic quality or drawing speed.
Inspect all 64 result rows
| Radius | Midpoint | 4-neighbor | 8-neighbor | Filled | Midpoint vs 4: differing positions | Midpoint vs 8: differing positions |
|---|---|---|---|---|---|---|
| 1 | 4 | 4 | 5 | 5 | 0 | 1 |
| 2 | 12 | 8 | 12 | 13 | 12 | 16 |
| 3 | 16 | 16 | 20 | 29 | 16 | 20 |
| 4 | 24 | 20 | 28 | 49 | 20 | 28 |
| 5 | 28 | 28 | 36 | 81 | 32 | 40 |
| 6 | 32 | 32 | 44 | 113 | 32 | 44 |
| 7 | 40 | 36 | 52 | 149 | 52 | 68 |
| 8 | 44 | 44 | 60 | 197 | 48 | 64 |
| 9 | 52 | 48 | 68 | 253 | 44 | 64 |
| 10 | 56 | 56 | 76 | 317 | 64 | 84 |
| 11 | 64 | 60 | 84 | 377 | 68 | 92 |
| 12 | 68 | 64 | 92 | 441 | 92 | 120 |
| 13 | 72 | 72 | 100 | 529 | 80 | 108 |
| 14 | 80 | 76 | 108 | 613 | 84 | 116 |
| 15 | 84 | 84 | 116 | 709 | 80 | 112 |
| 16 | 92 | 88 | 124 | 797 | 92 | 128 |
| 17 | 96 | 96 | 132 | 901 | 112 | 148 |
| 18 | 100 | 100 | 140 | 1009 | 128 | 168 |
| 19 | 108 | 104 | 148 | 1129 | 124 | 168 |
| 20 | 112 | 112 | 156 | 1257 | 112 | 156 |
| 21 | 120 | 116 | 164 | 1373 | 132 | 180 |
| 22 | 124 | 124 | 172 | 1517 | 128 | 176 |
| 23 | 132 | 128 | 180 | 1653 | 156 | 208 |
| 24 | 136 | 132 | 188 | 1793 | 164 | 220 |
| 25 | 140 | 140 | 196 | 1961 | 128 | 184 |
| 26 | 148 | 144 | 204 | 2121 | 172 | 232 |
| 27 | 152 | 152 | 212 | 2289 | 160 | 220 |
| 28 | 160 | 156 | 220 | 2453 | 196 | 260 |
| 29 | 164 | 164 | 228 | 2629 | 192 | 256 |
| 30 | 168 | 168 | 236 | 2821 | 176 | 244 |
| 31 | 176 | 172 | 244 | 3001 | 228 | 300 |
| 32 | 180 | 180 | 252 | 3209 | 192 | 264 |
| 33 | 188 | 184 | 260 | 3409 | 204 | 280 |
| 34 | 192 | 192 | 268 | 3625 | 192 | 268 |
| 35 | 196 | 196 | 276 | 3853 | 176 | 256 |
| 36 | 204 | 200 | 284 | 4053 | 252 | 336 |
| 37 | 208 | 208 | 292 | 4293 | 224 | 308 |
| 38 | 216 | 212 | 300 | 4513 | 260 | 348 |
| 39 | 220 | 220 | 308 | 4777 | 224 | 312 |
| 40 | 228 | 224 | 316 | 5025 | 236 | 328 |
| 41 | 232 | 228 | 324 | 5261 | 276 | 372 |
| 42 | 236 | 236 | 332 | 5525 | 256 | 352 |
| 43 | 244 | 240 | 340 | 5789 | 300 | 400 |
| 44 | 248 | 248 | 348 | 6077 | 272 | 372 |
| 45 | 256 | 252 | 356 | 6361 | 260 | 364 |
| 46 | 260 | 260 | 364 | 6625 | 288 | 392 |
| 47 | 264 | 264 | 372 | 6921 | 288 | 396 |
| 48 | 272 | 268 | 380 | 7213 | 324 | 436 |
| 49 | 276 | 276 | 388 | 7525 | 320 | 432 |
| 50 | 284 | 280 | 396 | 7845 | 316 | 432 |
| 51 | 288 | 288 | 404 | 8173 | 288 | 404 |
| 52 | 296 | 292 | 412 | 8497 | 292 | 412 |
| 53 | 300 | 296 | 420 | 8809 | 348 | 472 |
| 54 | 304 | 304 | 428 | 9145 | 336 | 460 |
| 55 | 312 | 308 | 436 | 9477 | 356 | 484 |
| 56 | 316 | 316 | 444 | 9845 | 320 | 448 |
| 57 | 324 | 320 | 452 | 10189 | 348 | 480 |
| 58 | 328 | 328 | 460 | 10557 | 352 | 484 |
| 59 | 332 | 332 | 468 | 10913 | 352 | 488 |
| 60 | 340 | 336 | 476 | 11289 | 412 | 552 |
| 61 | 344 | 344 | 484 | 11681 | 368 | 508 |
| 62 | 352 | 348 | 492 | 12061 | 388 | 532 |
| 63 | 356 | 356 | 500 | 12453 | 368 | 512 |
| 64 | 364 | 360 | 508 | 12853 | 364 | 512 |
Download the data and reproduce the results
Download all seven files into one folder. With Node.js 20 or later, run node reproduce.mjs --check to compare the generated CSV and JSON with the downloaded bytes. Run without --check to regenerate them. No additional packages are required.
- Summary results · CSV
- Complete pixel masks and traces · JSON
- Methods and source notes · JSON
- Scope and limitations · JSON
- Circle algorithms · JavaScript
- Reproduction script · Node.js
- File sizes and SHA-256 checksums · JSON
The JSON stores each mask as inclusive column ranges for every row. For example, [2, 4] means columns 2, 3 and 4. Both column and row indices start at zero. The CSV summarizes counts and differences; the manifest records each other file’s byte size and SHA-256 checksum.
What we checked
All 64 midpoint masks were checked against a separate calculation that rounds the circle equation’s square-root result to the nearest integer in one octant. We also exhaustively checked disk membership, both neighbor predicates, row totals, reflections, transposition symmetry and set differences. The independent check passed 640 assertion groups. This is a computational check, with no claim of external peer review.
Original code and generated data are released under CC0 1.0. Cited sources retain their own rights. To identify a result, cite this page’s version, radius, method and the linked data file.
Scope, corrections and use for block builds
This reference covers integer radii and integer centers on binary grids. It does not test antialiasing, even-width center-gap layouts, half-integer radii, ellipses, 3D shapes, running time or which outline looks best.
The Minecraft circle generator uses a different size convention: its diameter D uses radius D/2. An 11-block plan therefore uses radius 5.5; the 11-cell research grid above uses radius 5. Do not substitute this example’s rows for the generator’s blueprint just because the widths match. For construction, use the generator’s own row instructions or the circle chart.
This study is published by the operator of the circle tool. The cited authors have not endorsed it. Version 1 files stay fixed; corrections will receive a new version and a dated note. Report a correction with the radius, method and coordinate so it can be reproduced.