Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Deciding which side a numerically generated line you are on
Date: Sat, 17 Jan 2009 07:59:06 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 22
Message-ID: <gks34a$q1q$1@fred.mathworks.com>
References: <gkr5ue$8b5$1@fred.mathworks.com> <gkrcu6$sh6$1@fred.mathworks.com> <gkrkbl$21h$1@fred.mathworks.com> <gkrp96$8rn$1@fred.mathworks.com>
Reply-To: <HIDDEN>
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 1232179146 26682 172.30.248.38 (17 Jan 2009 07:59:06 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 17 Jan 2009 07:59:06 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:512191


"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gkrp96$8rn$1@fred.mathworks.com>...
> ......
>   Finally I will give you my version of implementing the procedure I described earlier.  Let X and Y be column vectors of the coordinates of successive vertices of a closed polygon which is to be one of your boundary curves.  Let x and y be scalar coordinates of a test point P = (x,y).
> 
>  x1 = [X(end);X}; y1 =  [Y(end);Y};
>  x2 = [X;X(1)];  y2 = [Y;Y(1)];
>  a = sum(atan2((x-x1).*(y-y2)-(y-y1).*(x-x2), ...
>                (x-x1).*(x-x2)+(y-y1).*(y-y2)));
> 
> The value of angle 'a' then shows whether (x,y) is inside or outside.

  I wish to amend that code I sent you, Dale.  One of the segments was repeated and this would give an error.  It should read as follows.

  Let X and Y be column vectors of the coordinates of successive vertices of a closed polygon which is to be one of your boundary curves.  Let x and y be scalar coordinates of a test point P = (x,y).

 X1 = X([2:end,1]); Y1 = Y([2:end,1]);
 a = sum(atan2((x-X).*(y-Y1)-(y-Y).*(x-X1), ...
               (x-X).*(x-X1)+(y-Y).*(y-Y1)));

Roger Stafford