TLDR: Given a square, a number of circles, a rotation angle, and some spacing factor, how can I determine the largest possible radius of circles arranged on the vertices in a regular polygon such that the circles do not exceed the bounds of the square?
I am trying to determine a formula or algorithm for calculating the radius of circles situated on the vertices of regular polygons with 1 to n sides.
I have tried the following with inconsistent results.
2 * a * tan(π / n) / x
Where x
is a sizing factor and a
is the apothem. For example say I wanted the spacing between circles to be such that you could fit another circle on the midpoint of the side, x
could be 4
. Or if I wanted the circles to be touching x
could be 1
. But for n = 3
the results look quite different than say for 6
in that the spacing between the circles is too small/big respectively.
As for the apothem, it's not clear how I would calculate that.
For n = 1
or 2
I would have to handle it differently. For 1
I'd just want a circle in the centre of the available space, and for 2
they would be arranged in a line. Is there a more general formula I could use?
Something like the circles on the vertices of the hexagon in the image below, where I could adjust the radius of the circles as needed.
Further complication is that I calculate the coordinates of the vertices based on a given square and an angle to offset the resulting vertices, but I reduce the size of the resulting polygon based on the radius of the circles to make sure the resulting circles do not exceed the bounds of the square.
Here's a few imperfect drawings I made for 1–3:
The circles don't have to fill the square necessarily; I want to be able to adjust the spacing between them by reducing the radius.
I'm a bit stuck on a circular dependency (no pun intended) since I think I need the positions of the vertices to calculate the circle radius, but I need the circle radius to determine the positions of the vertices so that the circles do not exceed the size of the square.