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 05:11:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 21
Message-ID: <gkrp96$8rn$1@fred.mathworks.com>
References: <gkr5ue$8b5$1@fred.mathworks.com> <gkrcu6$sh6$1@fred.mathworks.com> <gkrkbl$21h$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1232169062 9079 172.30.248.35 (17 Jan 2009 05:11:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 17 Jan 2009 05:11:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:512181


"Dale" <hazelREMOVETHISnusse@gmail.com> wrote in message <gkrkbl$21h$1@fred.mathworks.com>...
> This makes perfect sense, thank you!  I'll let you know once I implement it, hopefully it should be as straightforward as you made it sound :)
> Thanks,
> ~Luke

  Dale, I have read your original question more carefully and realize that my remarks really apply to situations without bounds.  In your case of being confined to a rectangular region, when and if your boundary curve (polygon) meets a bound of the rectangular region, you would want to continue the polygon on around one side or the other of the rectangle so as to be closed.  Then the procedure I described could be applied.

  Second, you said "I numerically generate some boundary curves that separate feasible (x,y) coordinates from infeasible ones (by solving a system of two equations in two unknowns)" and also "on one side of my curve I can't compute a number of the quantities."  You probably meant one equation in two unknowns here so as to generate a one-dimensional curve.  I take it that your presumably single equation is such that for many points it makes no sense to attempt to evaluate the expressions on the two side of it.  Otherwise, a direct evaluation of these expressions would seem to be the most efficient way of determining which side of the curve a given point (x,y) lies on, by the simple expedient of which expression is the greater.

  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.

Roger Stafford