Path: news.mathworks.com!not-for-mail
From: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Distance between point and circular segment
Date: Thu, 3 Apr 2008 15:02:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 43
Message-ID: <ft2rhd$pj5$1@fred.mathworks.com>
References: <4a2f4ac1-c21e-4ebf-8530-352f15098a47@41g2000hsc.googlegroups.com> <d122bed7-41d5-446a-8b0a-e786bdb938fb@a22g2000hsc.googlegroups.com> <fsrkeb$os2$1@fred.mathworks.com> <fsrvq5$5cu$1@fred.mathworks.com> <ft2m2v$gf5$1@fred.mathworks.com>
Reply-To: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1207234925 26213 172.30.248.38 (3 Apr 2008 15:02:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 3 Apr 2008 15:02:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:460846


"Chukwuemeka Igwe" <chukigwe@yahoo.com> wrote in message <ft2m2v
$gf5$1@fred.mathworks.com>...
> Roger,
> 
> Does htere exist a similar closed formula for finding the 
> nearest distance to a circle with three points specified 
> or we may have to apeal to the idea of a langragian 
> mulitplier or similar contrivance?
> 
> Sincerely,
> 
> Chuk.
---------
  The main problem there is to find the center and radius of such a circle.  
Once found, the distance you request is merely the absolute difference 
between the distance from the given point to the center and the radius of the 
circle.  There is certainly no need for Lagrange multipliers.

  On the Mathworld website:

 http://mathworld.wolfram.com/Circle.html

there is a solution of the circle problem in equations (28) through (34).

  A method of finding the circle using matlab is the following.  Let p1 = 
(x1,y1), p2 = (x2,y2), and p3 = (x3,y3) be three points in 2D space, each 
represented by a two-element row vector.  Then a circle through these three 
points has its center at the location given by vector c with radius r as given in 
the following:

 t = p2-p1; u = p3-p1; v = p3-p2;
 w = abs(det([t;u]));
 c = p1+(dot(t,t)*dot(u,v)*u-dot(u,u)*dot(t,v)*t)/(2*w^2);
 r = 1/2*norm(t)*norm(u)*norm(v)/w;

Then you can get your required distance as:

 d = abs(norm(P-c)-r);

where P is the given point.

Roger Stafford