I've been trying to find an algorithm to generate polygons with integer coordinates bounding a circle from the inside and outside. I searched everywhere and couldn't find anything like this. For example in the picture below we have the red circle with a given radius, and ask for polygons with 8 points, and then the algorithm should generate the blue and green polygons.
These polygons aren't exactly regular, and I don't think these polygons are uniquely defined either as there are probably different ways to "best" fit the circle. I'm not really looking for the absolute best solution for example I could try to minimize the maximum error, but that might make the problem much more complicated. Actually I tried expressing this as an integer programming problem with quadratic Diophantine inequalities but that seems to be overkill.
Is this a problem that has been already studied/solved before? Am I missing a simple method?





The following provides a simple brute-force answer. It is based on thinking about the Midpoint Circle Algorithm but does not require it. To summarize:
For the inside polygon, find all the integer points that are inside the circle, then take their convex hull.
For the outside polygon, generate a set of integer points that are outside the circle such that their convex hull is guaranteed to also be outside the circle.
I will demonstrate the answer with MATLAB code (version R2016a, no toolboxes). First set up a figure with the circle.
Now set up a mesh with of integer points $(X,Y)$
Inside polygon: Convex hull of the enclosed integer points.
Outside polygon: It is nice to use convex hulls, but we have to ensure that when we obtain the convex hull that we don't clip the circle. The solution here can be imagined as follows - in the first octant, put pins into the circle wherever it crosses a line $x=k$ for integer $k$. Then push those pins up until they reach an integer line for $y$. The convex hull around those points will be guaranteed to stay outside the circle. Finally, duplicate the octant up into a full set of points around the circle.
Looking at the results, it is evident that the outer polygon is conservative.
As a refinement for removing points (that I haven't explored): Note that for any three successive points $(x_1,y_1)$, $(x_2,y_2)$, $(x_3,y_3)$ in the outer polygon, the middle point could be removed if $\bigl(t x_3 + (1-t)x_1, t y_3 + (1-t)y_1 \bigr)$ is outside the circle for all $0 \leq t \leq 1$. Moreover this will be true if and only if $$ \bigl( t x_3 + (1-t)x_1 \bigr)^2 + \bigl( t y_3 + (1-t)y_1 \bigr)^2 \geq r^2 $$ for all $0 \leq t \leq 1$. Try to solve for equality (quadratic equation) and remove the point if no solution exists.