5.0

5.0 | 2 ratings Rate this file 123 downloads (last 30 days) File Size: 3.21 KB File ID: #24440

incircle.m

by John D'Errico

 

15 Jun 2009 (Updated 17 Jun 2009)

Code covered by BSD License  

In-circle of a convex polygon, or of the convex hull of a set of points in two dimensions

Download Now | Watch this File

File Information
Description

Computation of the in-circle of a convex polygon in two dimensions is done neatly here as an application of linear programming. (LINPROG from the optimization toolbox.) The INCIRCLE code formulates the problem as an LP with slack variables, one each for the distance from the center of the circle to each edge of the convex hull, then one final slack variable to maximize the overall smallest distance among of all of those distances. This mini-max problem generates the in-circle. (A similar scheme could be used to generate an in-sphere in higher dimensions.)

Given a general set of points in no special order, INCIRCLE will compute the convex hull for you, then compute the in-circle for the hull. If the hull is already generated, or if you simply have a known convex polygon, then INCIRCLE can use the data in any form provided.

In this example as the sample size approaches infinity, an asymptotic estimate of the center would lie at [0.5 0.5], with a radius approaching 0.5.

[C,R] = incircle(rand(1000,1),rand(1000,1))

C =
      0.50191 0.49999

R =
      0.49788

Next is an example with normally distributed points. The center is expected to lie roughly at [1,-2.5]. An a-priori estimate of the radius would be on the order of 2 or 3. (Think of the expected radius of a 99% confidence ellipse for a bivariate normal distribution.) I'll compute the convex hull in advance in this example so that I can plot it too.

x = randn(100,1) + 1;
y = randn(100,1) - 2.5;

H = convhull(x,y);

[C,R] = incircle([x,y],H)

C =
      1.0212 -2.3458

R =
      2.1329

Plot the in-circle along with the hull. (Shown as the screenshot for this submission.) As one would expect, the in-circle will be tangent to at least three of the edges of the enclosing polygon.

t = linspace(0,2*pi,200);
xc = R*cos(t) + C(1);
yc = R*sin(t) + C(2);

plot(x(H),y(H),'-r',x,y,'ko')
patch(xc,yc,'g','edgecolor','b','facealpha',0.25)
axis equal
xlabel X
ylabel Y
title 'Convex hull, with polygon in-circle'
grid on

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Minimum Radius Bounding Circle
This submission has inspired the following:
insphere

Required Products Optimization Toolbox
MATLAB release MATLAB 7.5 (R2007b)
Zip File Content  
Other Files incircle.m,
license.txt
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
15 Jun 2009 Bruno Luong

The maximal inner circle problem is nicely formulated into LP problem. I only wish to extend the possibility to pass a list of edges with non-duplicated first/end points.

24 Jun 2009 Óscar J. Rubio Martín

Working fine and fast. Thank you!

Please login to add a comment or rating.
Updates
17 Jun 2009

Fix to wrap the hull polygon in case the first point was not also the last. Thanks to Bruno for catching this.

Tag Activity for this File
Tag Applied By Date/Time
computational geometry John D'Errico 15 Jun 2009 11:29:43
incircle John D'Errico 15 Jun 2009 11:29:43
circle John D'Errico 15 Jun 2009 11:29:43
polygon John D'Errico 15 Jun 2009 11:29:43
circumcircle John D'Errico 15 Jun 2009 11:29:43
inscribed circle John D'Errico 15 Jun 2009 11:29:43
convex hull John D'Errico 15 Jun 2009 11:29:43
computational geometry Ali Tiner 29 Jul 2009 05:48:10
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com