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:
- You need to know all the distances. If you loop over all the hexes, you can calculate
distanceToCornerto 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
Each of the distances in
allDistancesgives 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.