Hexagons In Circle

 from Red Blob Games
26 Jun 2022

A reader asked how to find all the hexagon shapes that fit inside a circle. I implemented this diagram with a slider. Red circles are integer distances and black circles are other distances.

Brute force solution:

  1. You need a distance function. For each hex you need to know the distance from 0,0 to to the furthest corner. I have a javascript version of this in hexagons-in-circle.js (distanceToCorner).
  2. You need to know all the distances. If you loop over all the hexes, you can calculate distanceToCorner to each. Then get all the unique distances form this list. Sort them. Little glitch: sometimes two values are very very close together and we probably want to lump them together, so in this code I lumped together values that were the same down to 4 digits. See the calculation of allDistances in hexagons-in-circle.js.
  3. Each of the distances in allDistances gives you a diagram, with hexes with distanceToCorner(hex) < distance. Little glitch: because I'm using 4 digits, sometimes there are rounding errors, and I had to use distanceToCorner(hex) < distance + 0.00005

    I could not find a closed form formula to find the distances, but I didn't try very hard. I think brute force worked just fine here.

Email me , or tweet @redblobgames, or comment: