# Find the nearest regular polygon, given a side length and an approximate radius

I want to create a regular polygon with a given side length, s, and an maximum radius, r1.

The radius value needs to be decreased (or increased if it simplifies things) to the closest length, r2, that will create a regular polygon, i.e. with the given side length s, and any integer number of sides, n.

So from s and r1 you need to calculate a new, nearby r2 and the associated n.

Is this possible? It seems like something that should be straight forward, but I'm not sure where to start.

The circumradius $r$ of a regular polygon is $$r=\frac{s}{2\sin(\frac{\pi}{n})}$$
Solve for $n$ and calculate the value with the given $r$ and $s$. Remove the fractional part of $n$ (floor). This is your $n$. Then calculate the new $r$.