<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242581</link>
    <title>MATLAB Central Newsreader - Deciding which side a numerically generated line you are on</title>
    <description>Feed for thread: Deciding which side a numerically generated line you are on</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 16 Jan 2009 23:41:02 -0500</pubDate>
      <title>Deciding which side a numerically generated line you are on</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242581#622203</link>
      <author>Dale </author>
      <description>I am looking at a number of functions of two variables (say x and y), and I am restricting my attention to x \in [-pi/2, pi/2] and y \in [-pi, pi].  Call this set S \subset R^2.  The problem is such that I really only want to look at some of the data in this subset of the plane.  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 I need to be able to decide if an arbitrary point in S is on one side or the other side of the numerically generated curve.  I have the points on the curve as a 2xn array, each column of which is a point (x,y) on the curve.  &lt;br&gt;
&lt;br&gt;
Here is a link to what the boundary curves look like:&lt;br&gt;
&lt;a href=&quot;http://www.dlpeterson.com/feasible_lean_steer.pdf&quot;&gt;http://www.dlpeterson.com/feasible_lean_steer.pdf&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
The reason for why I need to do this is because on one side of my curve I can't compute a number of the quantities and if I try, I run into a slew of other numerical non-convergence issues due to the inherent infeasibility of points on that side of the line.&lt;br&gt;
&lt;br&gt;
Any ideas?&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
Luke</description>
    </item>
    <item>
      <pubDate>Sat, 17 Jan 2009 00:09:01 -0500</pubDate>
      <title>Re: Deciding which side a numerically generated line you are on</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242581#622205</link>
      <author>Sadik </author>
      <description>&quot;Dale&quot; &amp;lt;hazelREMOVETHISnusse@gmail.com&amp;gt; wrote in message &amp;lt;gkr5ue$8b5$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I am looking at a number of functions of two variables (say x and y), and I am restricting my attention to x \in [-pi/2, pi/2] and y \in [-pi, pi].  Call this set S \subset R^2.  The problem is such that I really only want to look at some of the data in this subset of the plane.  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 I need to be able to decide if an arbitrary point in S is on one side or the other side of the numerically generated curve.  I have the points on the curve as a 2xn array, each column of which is a point (x,y) on the curve.  &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Here is a link to what the boundary curves look like:&lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.dlpeterson.com/feasible_lean_steer.pdf&quot;&gt;http://www.dlpeterson.com/feasible_lean_steer.pdf&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The reason for why I need to do this is because on one side of my curve I can't compute a number of the quantities and if I try, I run into a slew of other numerical non-convergence issues due to the inherent infeasibility of points on that side of the line.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Any ideas?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt; Luke&lt;br&gt;
&lt;br&gt;
Hello Luke,&lt;br&gt;
&lt;br&gt;
Just for brainstorming purposes.&lt;br&gt;
&lt;br&gt;
You know that the power of a point inside a circle is negative. It is zero if it is on the boundary and it is positive if it is outside. This power is given by:&lt;br&gt;
&lt;br&gt;
F(x,y) = (x-xc)^2 + (y-yc)^2 - r^2&lt;br&gt;
&lt;br&gt;
for a circle of radius r centered at (xc,yc).&lt;br&gt;
&lt;br&gt;
Looking at the curves you have given, if you could use their equations in a similar manner, you could define the power of a point with respect to a given curve. Heuristically, I would expect to see negative power values in the upper right infeasible region with respect to the again upper right curve because the points are in the &quot;interior&quot; region of that curve.&lt;br&gt;
&lt;br&gt;
Just an idea. Hope it helps a bit.&lt;br&gt;
&lt;br&gt;
Thanks.</description>
    </item>
    <item>
      <pubDate>Sat, 17 Jan 2009 00:17:01 -0500</pubDate>
      <title>Re: Deciding which side a numerically generated line you are on</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242581#622206</link>
      <author>Sadik </author>
      <description>&quot;Sadik &quot; &amp;lt;sadik.hava@gmail.com&amp;gt; wrote in message &amp;lt;gkr7it$4s4$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Dale&quot; &amp;lt;hazelREMOVETHISnusse@gmail.com&amp;gt; wrote in message &amp;lt;gkr5ue$8b5$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; I am looking at a number of functions of two variables (say x and y), and I am restricting my attention to x \in [-pi/2, pi/2] and y \in [-pi, pi].  Call this set S \subset R^2.  The problem is such that I really only want to look at some of the data in this subset of the plane.  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 I need to be able to decide if an arbitrary point in S is on one side or the other side of the numerically generated curve.  I have the points on the curve as a 2xn array, each column of which is a point (x,y) on the curve.  &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Here is a link to what the boundary curves look like:&lt;br&gt;
&amp;gt; &amp;gt; &lt;a href=&quot;http://www.dlpeterson.com/feasible_lean_steer.pdf&quot;&gt;http://www.dlpeterson.com/feasible_lean_steer.pdf&lt;/a&gt;&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; The reason for why I need to do this is because on one side of my curve I can't compute a number of the quantities and if I try, I run into a slew of other numerical non-convergence issues due to the inherent infeasibility of points on that side of the line.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Any ideas?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Thanks,&lt;br&gt;
&amp;gt; &amp;gt; Luke&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hello Luke,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Just for brainstorming purposes.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You know that the power of a point inside a circle is negative. It is zero if it is on the boundary and it is positive if it is outside. This power is given by:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; F(x,y) = (x-xc)^2 + (y-yc)^2 - r^2&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; for a circle of radius r centered at (xc,yc).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Looking at the curves you have given, if you could use their equations in a similar manner, you could define the power of a point with respect to a given curve. Heuristically, I would expect to see negative power values in the upper right infeasible region with respect to the again upper right curve because the points are in the &quot;interior&quot; region of that curve.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Just an idea. Hope it helps a bit.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks.&lt;br&gt;
&lt;br&gt;
By the way, you have said that the curves are generated numerically. So if you wish, you could fit a polynomial to obtain such equations.&lt;br&gt;
&lt;br&gt;
If you think of the simplest parabola y = x^2, then the power should be F = x^2-y&lt;br&gt;
so that every point in the interior of the parabola will give negative values. Those on the parabola will give zero and the exterior points will yield positive values.</description>
    </item>
    <item>
      <pubDate>Sat, 17 Jan 2009 01:40:22 -0500</pubDate>
      <title>Re: Deciding which side a numerically generated line you are on</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242581#622211</link>
      <author>Roger Stafford</author>
      <description>&quot;Dale&quot; &amp;lt;hazelREMOVETHISnusse@gmail.com&amp;gt; wrote in message &amp;lt;gkr5ue$8b5$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt;..... I need to be able to decide if an arbitrary point in S is on one side or the other side of the numerically generated curve. ....... &lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Your question only has true significance if the &quot;boundary curves&quot; are closed.  Otherwise you would be able to move a test point continuously from one side of a point on the curve to the other side without ever crossing the curve at any point - there could be no inside or outside.  If the boundary curve consists of a discrete set of vertex points and the segments connecting them, forming a closed polygon, matlab can give a definite answer to this question.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Suppose P = (x,y) is a test point and P1 = (x1,y1) and P2 = (x2,y2) are two successive vertices along the polygon.  Then the angle at P in triangle P1P2P is given by&lt;br&gt;
&lt;br&gt;
&amp;nbsp;a12 = atan2((x-x1)*(y-y2)-(y-y1)*(x-x2),(x-x1)*(x-x2)+(y-y1)*(y-y2));&lt;br&gt;
&lt;br&gt;
where it is understood that a12 will be positive if the path P --&amp;gt; P1 --&amp;gt; P2 --&amp;gt; P is in a counterclockwise direction and negative if clockwise.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;If these angles are summed for all successive line segments of the polygon, and if the point P is interior to the polygon, these angles will have a sum of 2*pi for a counterclockwise direction around the polygon and -2*pi for a clockwise direction.  On the other hand the sum will be zero for all exterior points.  This does not depend on the polygon being convex, though I have assumed that the boundary curve is simple in the sense that it never crosses over itself.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Note that 'atan2 ' can accept vectors as inputs so these calculations can be done in a vectorized manner (without loops) for an entire polygon relative to a point (x,y).&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
    <item>
      <pubDate>Sat, 17 Jan 2009 03:47:01 -0500</pubDate>
      <title>Re: Deciding which side a numerically generated line you are on</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242581#622219</link>
      <author>Dale </author>
      <description>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 :)&lt;br&gt;
Thanks,&lt;br&gt;
~Luke&lt;br&gt;
&lt;br&gt;
&quot;Roger Stafford&quot; &amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt; wrote in message &amp;lt;gkrcu6$sh6$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Dale&quot; &amp;lt;hazelREMOVETHISnusse@gmail.com&amp;gt; wrote in message &amp;lt;gkr5ue$8b5$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt;..... I need to be able to decide if an arbitrary point in S is on one side or the other side of the numerically generated curve. ....... &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   Your question only has true significance if the &quot;boundary curves&quot; are closed.  Otherwise you would be able to move a test point continuously from one side of a point on the curve to the other side without ever crossing the curve at any point - there could be no inside or outside.  If the boundary curve consists of a discrete set of vertex points and the segments connecting them, forming a closed polygon, matlab can give a definite answer to this question.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   Suppose P = (x,y) is a test point and P1 = (x1,y1) and P2 = (x2,y2) are two successive vertices along the polygon.  Then the angle at P in triangle P1P2P is given by&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;  a12 = atan2((x-x1)*(y-y2)-(y-y1)*(x-x2),(x-x1)*(x-x2)+(y-y1)*(y-y2));&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; where it is understood that a12 will be positive if the path P --&amp;gt; P1 --&amp;gt; P2 --&amp;gt; P is in a counterclockwise direction and negative if clockwise.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   If these angles are summed for all successive line segments of the polygon, and if the point P is interior to the polygon, these angles will have a sum of 2*pi for a counterclockwise direction around the polygon and -2*pi for a clockwise direction.  On the other hand the sum will be zero for all exterior points.  This does not depend on the polygon being convex, though I have assumed that the boundary curve is simple in the sense that it never crosses over itself.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   Note that 'atan2 ' can accept vectors as inputs so these calculations can be done in a vectorized manner (without loops) for an entire polygon relative to a point (x,y).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Roger Stafford</description>
    </item>
    <item>
      <pubDate>Sat, 17 Jan 2009 05:11:02 -0500</pubDate>
      <title>Re: Deciding which side a numerically generated line you are on</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242581#622225</link>
      <author>Roger Stafford</author>
      <description>&quot;Dale&quot; &amp;lt;hazelREMOVETHISnusse@gmail.com&amp;gt; wrote in message &amp;lt;gkrkbl$21h$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; 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 :)&lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt; ~Luke&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;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.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Second, you said &quot;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)&quot; and also &quot;on one side of my curve I can't compute a number of the quantities.&quot;  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.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;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).&lt;br&gt;
&lt;br&gt;
&amp;nbsp;x1 = [X(end);X}; y1 =  [Y(end);Y};&lt;br&gt;
&amp;nbsp;x2 = [X;X(1)];  y2 = [Y;Y(1)];&lt;br&gt;
&amp;nbsp;a = sum(atan2((x-x1).*(y-y2)-(y-y1).*(x-x2), ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(x-x1).*(x-x2)+(y-y1).*(y-y2)));&lt;br&gt;
&lt;br&gt;
The value of angle 'a' then shows whether (x,y) is inside or outside.&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
    <item>
      <pubDate>Sat, 17 Jan 2009 07:59:06 -0500</pubDate>
      <title>Re: Deciding which side a numerically generated line you are on</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242581#622235</link>
      <author>Roger Stafford</author>
      <description>&quot;Roger Stafford&quot; &amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt; wrote in message &amp;lt;gkrp96$8rn$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; ......&lt;br&gt;
&amp;gt;   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).&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;  x1 = [X(end);X}; y1 =  [Y(end);Y};&lt;br&gt;
&amp;gt;  x2 = [X;X(1)];  y2 = [Y;Y(1)];&lt;br&gt;
&amp;gt;  a = sum(atan2((x-x1).*(y-y2)-(y-y1).*(x-x2), ...&lt;br&gt;
&amp;gt;                (x-x1).*(x-x2)+(y-y1).*(y-y2)));&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The value of angle 'a' then shows whether (x,y) is inside or outside.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;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.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;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).&lt;br&gt;
&lt;br&gt;
&amp;nbsp;X1 = X([2:end,1]); Y1 = Y([2:end,1]);&lt;br&gt;
&amp;nbsp;a = sum(atan2((x-X).*(y-Y1)-(y-Y).*(x-X1), ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(x-X).*(x-X1)+(y-Y).*(y-Y1)));&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
    <item>
      <pubDate>Sat, 17 Jan 2009 10:54:28 -0500</pubDate>
      <title>Re: Deciding which side a numerically generated line you are on</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242581#622242</link>
      <author>Rune Allnor</author>
      <description>On 17 Jan, 00:41, &quot;Dale&quot; &amp;lt;hazelREMOVETHISnu...@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; I am looking at a number of functions of two variables (say x and y), and=&lt;br&gt;
&amp;nbsp;I am restricting my attention to x \in [-pi/2, pi/2] and y \in [-pi, pi]. =&lt;br&gt;
=A0Call this set S \subset R^2. =A0The problem is such that I really only w=&lt;br&gt;
ant to look at some of the data in this subset of the plane. =A0I numerical=&lt;br&gt;
ly generate some boundary curves that separate feasible (x,y) coordinates f=&lt;br&gt;
rom infeasible ones (by solving a system of two equations in two unknowns),=&lt;br&gt;
&amp;nbsp;and I need to be able to decide if an arbitrary point in S is on one side =&lt;br&gt;
or the other side of the numerically generated curve. =A0I have the points =&lt;br&gt;
on the curve as a 2xn array, each column of which is a point (x,y) on the c=&lt;br&gt;
urve. =A0&lt;br&gt;
&lt;br&gt;
The terminology you use would suggest that this is a constrained&lt;br&gt;
linear programming problem. There are well-known methods to solve&lt;br&gt;
such problems, but they are a bit complicated to learn and&lt;br&gt;
implement. Linear programming tecniques work in any dimension.&lt;br&gt;
&lt;br&gt;
The 2D nature of your curves allows a different approach. You&lt;br&gt;
could view this as a geometric problem. In this case you check&lt;br&gt;
the signs of the vector cross products&lt;br&gt;
&lt;br&gt;
c_n =3D a_n x b_n&lt;br&gt;
&lt;br&gt;
where a_n is the vector from a point P1 on the line to the&lt;br&gt;
point under test P, and b_n is a vector from the point P1&lt;br&gt;
to another point P2 on the line. If all the lines are&lt;br&gt;
directed, the signs of all the cross products c_n will&lt;br&gt;
be the same if P lies inside a convex region bounded&lt;br&gt;
by the lines.&lt;br&gt;
&lt;br&gt;
Rune</description>
    </item>
    <item>
      <pubDate>Sat, 17 Jan 2009 11:59:02 -0500</pubDate>
      <title>Re: Deciding which side a numerically generated line you are on</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/242581#622245</link>
      <author>Bruno Luong</author>
      <description>Rune Allnor &amp;lt;allnor@tele.ntnu.no&amp;gt; wrote in message &amp;lt;6a95faa5-b673-4fa8-804d-dd9ae4da773d@b38g2000prf.googlegroups.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The terminology you use would suggest that this is a constrained&lt;br&gt;
&amp;gt; linear programming problem. &lt;br&gt;
&lt;br&gt;
I don't think it is. The feasible set in LP is convex polygonal. OP shows a non-convex feasible set in his example.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
  </channel>
</rss>

