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 line segment
Date: Tue, 19 Feb 2008 05:53:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 17
Message-ID: <fpdqru$8lg$1@fred.mathworks.com>
References: <4a2f4ac1-c21e-4ebf-8530-352f15098a47@41g2000hsc.googlegroups.com>
Reply-To: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1203400382 8880 172.30.248.37 (19 Feb 2008 05:53:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 19 Feb 2008 05:53:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:452283


Steve <srjm72499@gmail.com> wrote in message <4a2f4ac1-
c21e-4ebf-8530-352f15098a47@41g2000hsc.googlegroups.com>...
> Is there a simple way to find the distance between a line segment and
> a point?  I'm looking for the 2D case specifically, but the more
> general 3D case would also be nice to know...
> Thanks.
> -Steve
-------
  Let Q1 and Q2 be endpoints (or any two distinct points) of the line segment 
and P the point in question, then

 d = abs(cross(Q2-Q1,P-Q1))/abs(Q2-Q1);

will give the requested orthogonal distance.

Roger Stafford