algorithm Largest circle inside a non convex polygon?

An O(n log X) algorithm, where X depends on the precision you want.

At each iteration, for a given radius r, push each edge E, "inward" by R, to get E'. For each edge E', define half-plane H as the set of all points "inside" the the polygon (using E' as the boundary). Now, compute the intersection of all these half-planes E', which could be done in O(n) time. If the intersection is non-empty, then if you draw a circle with radius r using any point in the intersection as the center, it will be inside the given polygon.

Binary search for largest radius R for a circle:

Note

algorithm Largest circle inside a non convex polygon?

• Construct the Voronoi Diagram of the edges in P. This can be done with, for example, Fortunes algorithm.
• Find the node with the maximum distance to edges in P. This node is the centre of the maximum inscribed circle.

@brainjam You are right, thanks for pointing that out.

You want the Voronoi diagram of the edges, not the vertices. See, for example valis.cs.uiuc.edu/~sariel/research/CG/applets/medial_axis/. The edge Voronoi diagram has curved segments, the vertex Voronoi diagram has only straight lines. Another name for what you want is "medial axis". Here's a site that discusses the difference: groups.csail.mit.edu/graphics/classes/6.838/S98/meetings/m25/

Note

algorithm Largest circle inside a non convex polygon?

• Clip and points that are outside the polygon;
• Clip any points that are outside the polygon;
• Define R as a rectilinear region from (xmin,ymin) to (xmax,ymax);
• Divide R into an arbitrary number of points. The paper uses 21 as a heuristic (meaning divide the height and width by 20);
• For the remainder find the point that is furthest from any point on the edge;
• From that point define a new R with smaller intervals and bounds and repeat from step 2 to get to any arbitrary precision answer. The paper reduces R by a factor of the square root of 2.
• From the point define a new R with smaller intervals and bounds and repeat from step 2 to get to any arbitrary precision answer. The paper reduces R by a factor of the square root of 2.
• Furthest from any point on the edges of the polygon.
• Inside the polygon; and
• The point is perpendicular to a point on that edge (within the bounds of the two vertices); or

(2) is easy. The distance to the edge is the minimum of the distances to the two vertices. For (1), the closest point on that edge will be the point that intersects the edge at a 90 degree angle starting from the point you're testing. See Distance of a Point to a Ray or Segment.

@Dialecticus thinking about it, you're correct. Fixed.

Also, as far as testing the distance to any edge there are two cases you need to consider:

I think this algorithm can be modified to find the absolute maximum for sure. The idea is to calcualte two values for each rectangle: a lower limit for the maximum distance from the polygon edge (the maximum distance of the 4 vertices of the rectangle), and an upper limit (by adding 0.5*sqrt(rect_size_x^2 + rect_size_y^2). Then, run a subdividing search which keeps all non-processed candidate rectangles in a priority queue (ordered descending by the upper limit) and throws away every rectangle with an upper limit below the biggest lower limit found so far.

One note, How to test if a point is inside the polygon or not: The simplest solution to this part of the problem is to cast a ray to the right of the point. If it crosses an odd number of edges, it's within the polygon. If it's an even number, it's outside.

One note: testing if a point is inside the polygon or not. The simplest solution to this part of the problem is to cast a ray to the right of the point. If it crosses an odd number of edges, it's within the polygon. If it's an even number, it's outside.

Seems like an algorithm that is fairly straight-forward to implement, which is exactly what I am looking for. According to the article there is no guarantee that the solution found is an absolute maximum however (for my particular case this may not be a problem).

The basic algorithm works like this:

The key to solving this problem is first making an observation: the center of the largest circle that will fit inside an arbitrary polygon is the point that is:

This problem appears in geography and is solved iteratively to any arbitrary precision. Its called the Poles of Inaccessibility problem. See Poles of Inaccessibility: A Calculation Algorithm for the Remotest Places on Earth.

Why? Because every point on the edge of a circle is equidistant from that center. By definition, the largest circle will have the largest radius and will touch the polygon on at least two points so if you find the point inside furthest from the polygon you've found the center of the circle.

Note

algorithm Largest circle inside a non convex polygon?

• Clip any points that are outside the polygon;
• Define R as a rectilinear region from (xmin,ymin) to (xmax,ymax);
• Divide R into an arbitrary number of points. The paper uses 21 as a heuristic (meaning divide the height and width by 20);
• For the remainder find the point that is furthest from any point on the edge;
• From that point define a new R with smaller intervals and bounds and repeat from step 2 to get to any arbitrary precision answer. The paper reduces R by a factor of the square root of 2.
• Furthest from any point on the edges of the polygon.
• Inside the polygon; and
• The point is perpendicular to a point on that edge (within the bounds of the two vertices); or

(2) is easy. The distance to the edge is the minimum of the distances to the two vertices. For (1), the closest point on that edge will be the point that intersects the edge at a 90 degree angle starting from the point you're testing. See Distance of a Point to a Ray or Segment.

@Dialecticus thinking about it, you're correct. Fixed.

Also, as far as testing the distance to any edge there are two cases you need to consider:

I think this algorithm can be modified to find the absolute maximum for sure. The idea is to calcualte two values for each rectangle: a lower limit for the maximum distance from the polygon edge (the maximum distance of the 4 vertices of the rectangle), and an upper limit (by adding 0.5*sqrt(rect_size_x^2 + rect_size_y^2). Then, run a subdividing search which keeps all non-processed candidate rectangles in a priority queue (ordered descending by the upper limit) and throws away every rectangle with an upper limit below the biggest lower limit found so far.

One note, How to test if a point is inside the polygon or not: The simplest solution to this part of the problem is to cast a ray to the right of the point. If it crosses an odd number of edges, it's within the polygon. If it's an even number, it's outside.

Seems like an algorithm that is fairly straight-forward to implement, which is exactly what I am looking for. According to the article there is no guarantee that the solution found is an absolute maximum however (for my particular case this may not be a problem).

The basic algorithm works like this:

The key to solving this problem is first making an observation: the center of the largest circle that will fit inside an arbitrary polygon is the point that is:

This problem appears in geography and is solved iteratively to any arbitrary precision. Its called the Poles of Inaccessibility problem. See Poles of Inaccessibility: A Calculation Algorithm for the Remotest Places on Earth.

Why? Because every point on the edge of a circle is equidistant from that center. By definition, the largest circle will have the largest radius and will touch the polygon on at least two points so if you find the point inside furthest from the polygon you've found the center of the circle.

Note

algorithm Largest circle inside a non convex polygon?

• Construct the Voronoi Diagram of the edges in P. This can be done with, for example, Fortunes algorithm.
• Find the node with the maximum distance to edges in P. This node is the centre of the maximum inscribed circle.

@brainjam You are right, thanks for pointing that out.

You want the Voronoi diagram of the edges, not the vertices. See, for example valis.cs.uiuc.edu/~sariel/research/CG/applets/medial_axis/. The edge Voronoi diagram has curved segments, the vertex Voronoi diagram has only straight lines. Another name for what you want is "medial axis". Here's a site that discusses the difference: groups.csail.mit.edu/graphics/classes/6.838/S98/meetings/m25/

Note

algorithm Largest circle inside a non convex polygon?

An O(n log X) algorithm, where X depends on the precision you want.

At each iteration, for a given radius r, push each edge E, "inward" by R, to get E'. For each edge E', define half-plane H as the set of all points "inside" the the polygon (using E' as the boundary). Now, compute the intersection of all these half-planes E', which could be done in O(n) time. If the intersection is non-empty, then if you draw a circle with radius r using any point in the intersection as the center, it will be inside the given polygon.

Binary search for largest radius R for a circle:

Note

algorithm Largest circle inside a non convex polygon?

An O(n log X) algorithm, where X depends on the precision you want.

At each iteration, for a given radius r, push each edge E, "inward" by R, to get E'. For each edge E', define half-plane H as the set of all points "inside" the the polygon (using E' as the boundary). Now, compute the intersection of all these half-planes E', which could be done in O(n) time. If the intersection is non-empty, then if you draw a circle with radius r using any point in the intersection as the center, it will be inside the given polygon.

Binary search for largest radius R for a circle:

Note