+3  A: 

Summary: It is not trivial. So it is very unlikely that it will not get messy. But there are some lecture slides which you may find useful.

Source: http://www.eggheadcafe.com/software/aspnet/30304481/finding-the-maximum-inscribed-circle-in-c.aspx

Your problem is not trivial, and there is no C# code that does this straight out of the box. You will have to write your own. I found the problem intriguing, and did some research, so here are a few clues that may help.

First, here's an answer in "plain English" from mathforum.org:

http://mathforum.org/library/drmath/view/67030.html

The answer references Voronoi Diagrams as a methodology for making the process more efficient. In researching Voronoi diagrams, in conjunction with the "maximum empty circle" problem (same problem, different name), I came across this informative paper:

http://www.cosy.sbg.ac.at/~held/teaching/compgeo/slides/vd_slides.pdf

It was written by Martin Held, a Computational Geometry professor at the University of Salzberg in Austria. Further investigation of Dr. Held's writings yielded a couple of good articles:

http://www.cosy.sbg.ac.at/~held/projects/vroni/vroni.html http://www.cosy.sbg.ac.at/~held/projects/triang/triang.html

Further research into Vornoi Diagrams yielded the following site:

http://www.voronoi.com/

This site has lots of information, code in various languages, and links to other resources.

Finally, here is the URL to the Mathematics and Computational Sciences Division of the National Institute of Standards and Technology (U.S.), a wealth of information and links regarding mathematics of all sorts:

http://math.nist.gov/mcsd/

-- HTH,

Kevin Spencer Microsoft MVP

Ashish
This bulk of this reply text from Kevin Spencer refers to the problem involving concave or convex polygons. The problem might be much easier in the convex case.
Josephine
@Josephine: *Might* be. I haven't gone through in detail, but *might* be. Perhaps you have something on your mind?
Ashish
After commenting here, I also posted an answer. My ideas are there.
Josephine
The problem is definitely easier when the polygon is convex. The problem becomes a linear program. I posted an answer, too.
Steve
+4  A: 
Pavel Shved
A: 

The largest inscribed circle (I'm assuming it's unique) will intersect some of the faces tangentially, and may fail to intersect others. Let's call a face "relevant" if the largest inscribed circle intersects it, and "irrelevant" otherwise.

If your convex polygon is in fact a triangle, then the problem can be solved by calculating the triangle's incenter, by intersecting angle bisectors. This may seem a trivial case, but even when your convex polygon is complicated, the inscribed circle will always be tangent to at least three faces (proof? seems geometrically obvious), and so its center can be calculated as the incenter of three relevant faces (extended outwards to make a triangle which circumscribes the original polygon). Here we assume that no two such faces are parallel. If two are parallel, we have to interpret the "angle bisector" of two parallel lines to mean that third parallel line between them.

This immediately suggests a rather terrible algorithm: Consider all n-choose-3 subsets of faces, find the incenters of all triangles as above, and test each circle for containment in the original polygon. Maximize among those that are legal. But this is cubic in n and we can do much better.

But it's possible instead to identify faces that are irrelevant upfront: If a face is tangent to some inscribed circle, then there is a region of points bounded by that face and by the two angle bisectors at its endpoints, wherein the circle's center must lie. If even the circle whose center lies at the farthest tip of that triangular region is "legal" (entirely contained in the polygon), then the face itself is irrelevant, and can be removed. The two faces touching it should be extended beyond it so that they meet.

By iteratively removing faces which are irrelevant in this sense, you should be able to reduce the polygon to a triangle, or perhaps a trapezoid, at which point the problem will be easily solved, and its solution will still lie within the original polygon.

Josephine
What about a rectangle? What about a modified rectangle which has it's smaller sides slightly convexed out as two sides of a triangle, each? `...but even when your convex polygon is complicated, the inscribed circle will always be tangent to at least three faces (proof? seems geometrically obvious)` doesn't seem to hold.
Ashish
In both cases you describe, "the" largest inscribed circle is not unique, but among all largest inscribed circles, at least one intersects three sides.
Josephine
@Josephine: even if it was only for such cases, you need to somehow know if the largest inscribed circle is not unique.
Ashish
+3  A: 

Yes. The Chebyshev center, x*, of a set C is the center of the largest ball that lies inside C. [Boyd, p. 416] When C is a convex set, then this problem is a convex optimization problem.

Better yet, when C is a polyhedron, then this problem becomes a linear program.

Suppose the m-sided polyhedron C is defined by a set of linear inequalities: ai^T x <= bi, for i in {1, 2, ..., m}. Then the problem becomes

maximize  R
such that ai^T x + R||a|| <= bi,  i in {1, 2, ..., m}
          R >= 0

where the variables of minimization are R and x, and ||a|| is the Euclidean norm of a.

Steve