<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239257</link>
    <title>MATLAB Central Newsreader - sorting, 2D vector, puzzle piece shaped</title>
    <description>Feed for thread: sorting, 2D vector, puzzle piece shaped</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, 14 Nov 2008 15:47:01 -0500</pubDate>
      <title>sorting, 2D vector, puzzle piece shaped</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239257#610928</link>
      <author>Mahdieh </author>
      <description>I have a nx2 vector, which includes the XY coordinates of the n points. &lt;br&gt;
&lt;br&gt;
When plotted, these points create a shape looking like a puzzle piece. &lt;br&gt;
Now, I need to sort this vector, such that by connecting two consequent points in the vector, I would get the permieter of the shape. i.e. consequent points in the vector, correspond to adjacent point in the graph. &lt;br&gt;
&lt;br&gt;
I have tried:&lt;br&gt;
1-  a. calculating the centroid, b. choosing one point in the vector c. sorting based on the angle between two lines, one passing through centroid and b.point, other line passing through centroid and any point on the vector ...&lt;br&gt;
&lt;br&gt;
2- a. dividing the shape into 4 quadrants, b. sorting each quadrant based on X or Y c. connecting them together &lt;br&gt;
&lt;br&gt;
none of the methods, accomplish sorting the whole shape ...&lt;br&gt;
&lt;br&gt;
I am out of algorithms, &lt;br&gt;
any help would be really appreciated ...&lt;br&gt;
&lt;br&gt;
Thanks a lot&lt;br&gt;
-Mah</description>
    </item>
    <item>
      <pubDate>Fri, 14 Nov 2008 17:08:22 -0500</pubDate>
      <title>Re: sorting, 2D vector, puzzle piece shaped</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239257#610936</link>
      <author>ImageAnalyst</author>
      <description>On Nov 14, 10:47=A0am, &quot;Mahdieh&quot; &amp;lt;mahdieh.emr...@capitalhealth.ca&amp;gt;&lt;br&gt;
wrote:&lt;br&gt;
&amp;gt; I have a nx2 vector, which includes the XY coordinates of the n points.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; When plotted, these points create a shape looking like a puzzle piece.&lt;br&gt;
&amp;gt; Now, I need to sort this vector, such that by connecting two consequent p=&lt;br&gt;
oints in the vector, I would get the permieter of the shape. i.e. consequen=&lt;br&gt;
t points in the vector, correspond to adjacent point in the graph.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I have tried:&lt;br&gt;
&amp;gt; 1- =A0a. calculating the centroid, b. choosing one point in the vector c.=&lt;br&gt;
&amp;nbsp;sorting based on the angle between two lines, one passing through centroid=&lt;br&gt;
&amp;nbsp;and b.point, other line passing through centroid and any point on the vect=&lt;br&gt;
or ...&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; 2- a. dividing the shape into 4 quadrants, b. sorting each quadrant based=&lt;br&gt;
&amp;nbsp;on X or Y c. connecting them together&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; none of the methods, accomplish sorting the whole shape ...&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I am out of algorithms,&lt;br&gt;
&amp;gt; any help would be really appreciated ...&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Thanks a lot&lt;br&gt;
&amp;gt; -Mah&lt;br&gt;
&lt;br&gt;
----------------------------------------------------------&lt;br&gt;
Mah:&lt;br&gt;
Not sure why you're having such difficulty.  Just add a pair of&lt;br&gt;
elements at the end of the array that are the same as the first&lt;br&gt;
coordinate of the array (so you'll get a closed curve), and use the&lt;br&gt;
plot command.  It's quite capable of plotting a closed curve such as a&lt;br&gt;
jigsaw puzzle piece.  Why do you need to do sorting????&lt;br&gt;
Regards,&lt;br&gt;
ImageAnalyst</description>
    </item>
    <item>
      <pubDate>Fri, 14 Nov 2008 17:38:54 -0500</pubDate>
      <title>Re: sorting, 2D vector, puzzle piece shaped</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239257#610940</link>
      <author>Walter Roberson</author>
      <description>Mahdieh wrote:&lt;br&gt;
&amp;gt; I have a nx2 vector, which includes the XY coordinates of the n points. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; When plotted, these points create a shape looking like a puzzle piece. &lt;br&gt;
&amp;gt; Now, I need to sort this vector, such that by connecting two consequent points in the&lt;br&gt;
&amp;gt; vector, I would get the permieter of the shape. i.e. consequent points in the vector,&lt;br&gt;
&amp;gt; correspond to adjacent point in the graph. &lt;br&gt;
&lt;br&gt;
In theory, this should work:&lt;br&gt;
&lt;br&gt;
xm = mean(XY,1); ym = mean(XY,2);&lt;br&gt;
t = complex(xm, ym) + sort(complex(XY(:,1) - xm, XY(:,2) - ym)));&lt;br&gt;
plot(real(t[1:end 1]), imag(t[1:end 1]))&lt;br&gt;
&lt;br&gt;
This is just another way of expressing a centroid method like you mentioned.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
.signature note: I am now avoiding replying to unclear or ambiguous postings.&lt;br&gt;
Please review questions before posting them. Be specific. Use examples of what you mean,&lt;br&gt;
of what you don't mean. Specify boundary conditions, and data classes and value&lt;br&gt;
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?</description>
    </item>
    <item>
      <pubDate>Fri, 14 Nov 2008 17:40:17 -0500</pubDate>
      <title>Re: sorting, 2D vector, puzzle piece shaped</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239257#610941</link>
      <author>John D'Errico</author>
      <description>ImageAnalyst &amp;lt;imageanalyst@mailinator.com&amp;gt; wrote in message &amp;lt;cfb67021-f6d7-4853-b3bb-52e1211a087a@a3g2000prm.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; On Nov 14, 10:47=A0am, &quot;Mahdieh&quot; &amp;lt;mahdieh.emr...@capitalhealth.ca&amp;gt;&lt;br&gt;
&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; I have a nx2 vector, which includes the XY coordinates of the n points.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; When plotted, these points create a shape looking like a puzzle piece.&lt;br&gt;
&amp;gt; &amp;gt; Now, I need to sort this vector, such that by connecting two consequent p=&lt;br&gt;
&amp;gt; oints in the vector, I would get the permieter of the shape. i.e. consequen=&lt;br&gt;
&amp;gt; t points in the vector, correspond to adjacent point in the graph.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I have tried:&lt;br&gt;
&lt;br&gt;
(Snip)&lt;br&gt;
&lt;br&gt;
&amp;gt; ----------------------------------------------------------&lt;br&gt;
&amp;gt; Mah:&lt;br&gt;
&amp;gt; Not sure why you're having such difficulty.  Just add a pair of&lt;br&gt;
&amp;gt; elements at the end of the array that are the same as the first&lt;br&gt;
&amp;gt; coordinate of the array (so you'll get a closed curve), and use the&lt;br&gt;
&amp;gt; plot command.  It's quite capable of plotting a closed curve such as a&lt;br&gt;
&amp;gt; jigsaw puzzle piece.  Why do you need to do sorting????&lt;br&gt;
&amp;gt; Regards,&lt;br&gt;
&amp;gt; ImageAnalyst&lt;br&gt;
&lt;br&gt;
Because, I predict the points are scattered. The OP does&lt;br&gt;
not have a polygon, only a list of scattered points, in no&lt;br&gt;
specific order.&lt;br&gt;
&lt;br&gt;
The simplest solution is to use one of the traveling salesman&lt;br&gt;
codes that Joseph Kirk has posted to the file exchange. In&lt;br&gt;
fact, he has codes that assume the start and end points&lt;br&gt;
must be the same, as required for a closed polygon. The&lt;br&gt;
TSP code will produce a polygon as the OP desires.&lt;br&gt;
&lt;br&gt;
HTH,&lt;br&gt;
John</description>
    </item>
    <item>
      <pubDate>Fri, 14 Nov 2008 18:22:02 -0500</pubDate>
      <title>Re: sorting, 2D vector, puzzle piece shaped</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239257#610952</link>
      <author>Mahdieh </author>
      <description>ImageAnalyst &amp;lt;imageanalyst@mailinator.com&amp;gt; wrote in message &amp;lt;cfb67021-f6d7-4853-b3bb-52e1211a087a@a3g2000prm.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; On Nov 14, 10:47=A0am, &quot;Mahdieh&quot; &amp;lt;mahdieh.emr...@capitalhealth.ca&amp;gt;&lt;br&gt;
&amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; I have a nx2 vector, which includes the XY coordinates of the n points.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; When plotted, these points create a shape looking like a puzzle piece.&lt;br&gt;
&amp;gt; &amp;gt; Now, I need to sort this vector, such that by connecting two consequent p=&lt;br&gt;
&amp;gt; oints in the vector, I would get the permieter of the shape. i.e. consequen=&lt;br&gt;
&amp;gt; t points in the vector, correspond to adjacent point in the graph.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I have tried:&lt;br&gt;
&amp;gt; &amp;gt; 1- =A0a. calculating the centroid, b. choosing one point in the vector c.=&lt;br&gt;
&amp;gt;  sorting based on the angle between two lines, one passing through centroid=&lt;br&gt;
&amp;gt;  and b.point, other line passing through centroid and any point on the vect=&lt;br&gt;
&amp;gt; or ...&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; 2- a. dividing the shape into 4 quadrants, b. sorting each quadrant based=&lt;br&gt;
&amp;gt;  on X or Y c. connecting them together&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; none of the methods, accomplish sorting the whole shape ...&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; I am out of algorithms,&lt;br&gt;
&amp;gt; &amp;gt; any help would be really appreciated ...&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Thanks a lot&lt;br&gt;
&amp;gt; &amp;gt; -Mah&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ----------------------------------------------------------&lt;br&gt;
&amp;gt; Mah:&lt;br&gt;
&amp;gt; Not sure why you're having such difficulty.  Just add a pair of&lt;br&gt;
&amp;gt; elements at the end of the array that are the same as the first&lt;br&gt;
&amp;gt; coordinate of the array (so you'll get a closed curve), and use the&lt;br&gt;
&amp;gt; plot command.  It's quite capable of plotting a closed curve such as a&lt;br&gt;
&amp;gt; jigsaw puzzle piece.  Why do you need to do sorting????&lt;br&gt;
&amp;gt; Regards,&lt;br&gt;
&amp;gt; ImageAnalyst&lt;br&gt;
&lt;br&gt;
well, I need them sorted for my further analysis. I know that I get a perfect plot by just using the plot function. but what I need , is that the vector is sorted, in such way that the 1st and 2nd elements correspond to 2 consequent points on the graph ... and so on for the rest of my vector ... &lt;br&gt;
&lt;br&gt;
any help is really appreciated.&lt;br&gt;
Thanks, </description>
    </item>
    <item>
      <pubDate>Fri, 14 Nov 2008 18:25:04 -0500</pubDate>
      <title>Re: sorting, 2D vector, puzzle piece shaped</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239257#610953</link>
      <author>Mahdieh </author>
      <description>&quot;Mahdieh&quot; &amp;lt;mahdieh.emrani@capitalhealth.ca&amp;gt; wrote in message &amp;lt;gfk6hl$snc$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I have a nx2 vector, which includes the XY coordinates of the n points. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; When plotted, these points create a shape looking like a puzzle piece. &lt;br&gt;
&amp;gt; Now, I need to sort this vector, such that by connecting two consequent points in the vector, I would get the permieter of the shape. i.e. consequent points in the vector, correspond to adjacent point in the graph. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have tried:&lt;br&gt;
&amp;gt; 1-  a. calculating the centroid, b. choosing one point in the vector c. sorting based on the angle between two lines, one passing through centroid and b.point, other line passing through centroid and any point on the vector ...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 2- a. dividing the shape into 4 quadrants, b. sorting each quadrant based on X or Y c. connecting them together &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; none of the methods, accomplish sorting the whole shape ...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I am out of algorithms, &lt;br&gt;
&amp;gt; any help would be really appreciated ...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks a lot&lt;br&gt;
&amp;gt; -Mah&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
one important note, is that when plotted (used plot function) these points create a shape which looks like the &quot;outline&quot; of a puzzle piece, so it is sort of a curvature .... </description>
    </item>
    <item>
      <pubDate>Fri, 14 Nov 2008 18:40:18 -0500</pubDate>
      <title>Re: sorting, 2D vector, puzzle piece shaped</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239257#610954</link>
      <author>Mahdieh </author>
      <description>&quot;John D'Errico&quot; &amp;lt;woodchips@rochester.rr.com&amp;gt; wrote in message &amp;lt;gfkd60$q5a$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; ImageAnalyst &amp;lt;imageanalyst@mailinator.com&amp;gt; wrote in message &amp;lt;cfb67021-f6d7-4853-b3bb-52e1211a087a@a3g2000prm.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; On Nov 14, 10:47=A0am, &quot;Mahdieh&quot; &amp;lt;mahdieh.emr...@capitalhealth.ca&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; I have a nx2 vector, which includes the XY coordinates of the n points.&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; When plotted, these points create a shape looking like a puzzle piece.&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Now, I need to sort this vector, such that by connecting two consequent p=&lt;br&gt;
&amp;gt; &amp;gt; oints in the vector, I would get the permieter of the shape. i.e. consequen=&lt;br&gt;
&amp;gt; &amp;gt; t points in the vector, correspond to adjacent point in the graph.&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; I have tried:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; (Snip)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; ----------------------------------------------------------&lt;br&gt;
&amp;gt; &amp;gt; Mah:&lt;br&gt;
&amp;gt; &amp;gt; Not sure why you're having such difficulty.  Just add a pair of&lt;br&gt;
&amp;gt; &amp;gt; elements at the end of the array that are the same as the first&lt;br&gt;
&amp;gt; &amp;gt; coordinate of the array (so you'll get a closed curve), and use the&lt;br&gt;
&amp;gt; &amp;gt; plot command.  It's quite capable of plotting a closed curve such as a&lt;br&gt;
&amp;gt; &amp;gt; jigsaw puzzle piece.  Why do you need to do sorting????&lt;br&gt;
&amp;gt; &amp;gt; Regards,&lt;br&gt;
&amp;gt; &amp;gt; ImageAnalyst&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Because, I predict the points are scattered. The OP does&lt;br&gt;
&amp;gt; not have a polygon, only a list of scattered points, in no&lt;br&gt;
&amp;gt; specific order.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The simplest solution is to use one of the traveling salesman&lt;br&gt;
&amp;gt; codes that Joseph Kirk has posted to the file exchange. In&lt;br&gt;
&amp;gt; fact, he has codes that assume the start and end points&lt;br&gt;
&amp;gt; must be the same, as required for a closed polygon. The&lt;br&gt;
&amp;gt; TSP code will produce a polygon as the OP desires.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; HTH,&lt;br&gt;
&amp;gt; John&lt;br&gt;
&lt;br&gt;
Thanks John, you got it right and the solution seems to be the answer... I have donwloaded the TSP code and from the description it is promising to solve my problem.&lt;br&gt;
Thanks again for the advice, &lt;br&gt;
-Mah</description>
    </item>
    <item>
      <pubDate>Fri, 14 Nov 2008 19:51:02 -0500</pubDate>
      <title>Re: sorting, 2D vector, puzzle piece shaped</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239257#610971</link>
      <author>Roger Stafford</author>
      <description>&quot;Mahdieh&quot; &amp;lt;mahdieh.emrani@capitalhealth.ca&amp;gt; wrote in message &amp;lt;gfk6hl$snc$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; I have a nx2 vector, which includes the XY coordinates of the n points. &lt;br&gt;
&amp;gt; ........ (snip)&lt;br&gt;
&amp;gt; -Mah&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;As John has indicated, this could be considered a &quot;traveling salesman problem&quot; which is known to be NP-hard (that is, takes a truly enormous number of steps for large n.)  For a discussion see, for example,&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&lt;a href=&quot;http://en.wikipedia.org/wiki/Traveling_salesman_problem&quot;&gt;http://en.wikipedia.org/wiki/Traveling_salesman_problem&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;However, in your particular case you presumably have the advantage of knowing that your points probably lie on a reasonably smooth curve.  (I assume the &quot;puzzle piece&quot; outline is reasonably smooth.)  You might try an algorithm that takes advantage of that fact and proceeds along the following lines.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Having once determined that your n_th point is to be A and the n+1_st point be B, choose as the n+2_nd point C one that combines in some manner the closeness of C to B and the smallness of the bend in angle ABC.  That is, it tries to avoid choosing nearby points that are in a backwards direction.  Perhaps that could be as simple as ensuring that C is closer to B than to A.  In other words, you are restricting yourself to triplets of points that are not only close together but do not have excessively sharp bends in their connecting line segments.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Hopefully you could work your way sequentially from some initial point through all the points in the array and back eventually to that same initial point.  This sounds like an algorithm of order n^2 but necessarily combined with some kind of check for final overall validity.  That might cause it to end up order n^3 if you have to keep restarting with different initial points.  (Or it might not work at all!)  There is no denying that you have posed a difficult task here.&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
    <item>
      <pubDate>Fri, 14 Nov 2008 20:44:02 -0500</pubDate>
      <title>Re: sorting, 2D vector, puzzle piece shaped</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239257#610980</link>
      <author>Mahdieh </author>
      <description>&quot;Roger Stafford&quot; &amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt; wrote in message &amp;lt;gfkkr6$a33$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Mahdieh&quot; &amp;lt;mahdieh.emrani@capitalhealth.ca&amp;gt; wrote in message &amp;lt;gfk6hl$snc$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; I have a nx2 vector, which includes the XY coordinates of the n points. &lt;br&gt;
&amp;gt; &amp;gt; ........ (snip)&lt;br&gt;
&amp;gt; &amp;gt; -Mah&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   As John has indicated, this could be considered a &quot;traveling salesman problem&quot; which is known to be NP-hard (that is, takes a truly enormous number of steps for large n.)  For a discussion see, for example,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;  &lt;a href=&quot;http://en.wikipedia.org/wiki/Traveling_salesman_problem&quot;&gt;http://en.wikipedia.org/wiki/Traveling_salesman_problem&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   However, in your particular case you presumably have the advantage of knowing that your points probably lie on a reasonably smooth curve.  (I assume the &quot;puzzle piece&quot; outline is reasonably smooth.)  You might try an algorithm that takes advantage of that fact and proceeds along the following lines.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   Having once determined that your n_th point is to be A and the n+1_st point be B, choose as the n+2_nd point C one that combines in some manner the closeness of C to B and the smallness of the bend in angle ABC.  That is, it tries to avoid choosing nearby points that are in a backwards direction.  Perhaps that could be as simple as ensuring that C is closer to B than to A.  In other words, you are restricting yourself to triplets of points that are not only close together but do not have excessively sharp bends in their connecting line segments.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;   Hopefully you could work your way sequentially from some initial point through all the points in the array and back eventually to that same initial point.  This sounds like an algorithm of order n^2 but necessarily combined with some kind of check for final overall validity.  That might cause it to end up order n^3 if you have to keep restarting with different initial points.  (Or it might not work at all!)  There is no denying that you have posed a difficult task here.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Roger Stafford&lt;br&gt;
&lt;br&gt;
I have tried the TSP code, provided by Joseph Kirk and large data it takes very very long to sort them, as you stated ...&lt;br&gt;
I have 1000 points on each curve and I need to analyze 18 curves at a time ... &lt;br&gt;
So, I will try to combine the simple sorting solutions, such as the angle and centroid, with the TSP problem. i.e. first sort the points with the simple solution, then evaluate the points by some heuristic funny algorithms, and for the parts that the algorithm has failed, I will try to use the TSP code ....&lt;br&gt;
&lt;br&gt;
Meanwhile, if someone come up with something, let me know ...&lt;br&gt;
Thanks, &lt;br&gt;
-Mahdieh&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;nbsp;</description>
    </item>
    <item>
      <pubDate>Fri, 14 Nov 2008 22:26:03 -0500</pubDate>
      <title>Re: sorting, 2D vector, puzzle piece shaped</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239257#610994</link>
      <author>John D'Errico</author>
      <description>&quot;Mahdieh&quot; &amp;lt;mahdieh.emrani@capitalhealth.ca&amp;gt; wrote in message &amp;lt;gfknui$lf9$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&lt;br&gt;
&amp;gt; I have tried the TSP code, provided by Joseph Kirk and large data it takes very very long to sort them, as you stated ...&lt;br&gt;
&amp;gt; I have 1000 points on each curve and I need to analyze 18 curves at a time ... &lt;br&gt;
&amp;gt; So, I will try to combine the simple sorting solutions, such as the angle and centroid, with the TSP problem. i.e. first sort the points with the simple solution, then evaluate the points by some heuristic funny algorithms, and for the parts that the algorithm has failed, I will try to use the TSP code ....&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Meanwhile, if someone come up with something, let me know ...&lt;br&gt;
&lt;br&gt;
Oh. You did not tell us it was that large of a problem.&lt;br&gt;
The TSP is truly nasty for large sets of points.&lt;br&gt;
&lt;br&gt;
However, you might be willing to solve the TSP for say&lt;br&gt;
every 5th point from your set, then add the rest of the&lt;br&gt;
points back in.&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
    <item>
      <pubDate>Sat, 15 Nov 2008 03:13:45 -0500</pubDate>
      <title>Re: sorting, 2D vector, puzzle piece shaped</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239257#611018</link>
      <author>ImageAnalyst</author>
      <description>On Nov 14, 12:40=A0pm, &quot;John D'Errico&quot; &amp;lt;woodch...@rochester.rr.com&amp;gt;&lt;br&gt;
wrote:&lt;br&gt;
&amp;gt; ImageAnalyst &amp;lt;imageanal...@mailinator.com&amp;gt; wrote in message &amp;lt;cfb67021-f6d=&lt;br&gt;
7-4853-b3bb-52e1211a0...@a3g2000prm.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; On Nov 14, 10:47=3DA0am, &quot;Mahdieh&quot; &amp;lt;mahdieh.emr...@capitalhealth.ca&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; wrote:&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; I have a nx2 vector, which includes the XY coordinates of the n point=&lt;br&gt;
s.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; When plotted, these points create a shape looking like a puzzle piece=&lt;br&gt;
.&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Now, I need to sort this vector, such that by connecting two conseque=&lt;br&gt;
nt p=3D&lt;br&gt;
&amp;gt; &amp;gt; oints in the vector, I would get the permieter of the shape. i.e. conse=&lt;br&gt;
quen=3D&lt;br&gt;
&amp;gt; &amp;gt; t points in the vector, correspond to adjacent point in the graph.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; I have tried:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; (Snip)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; ----------------------------------------------------------&lt;br&gt;
&amp;gt; &amp;gt; Mah:&lt;br&gt;
&amp;gt; &amp;gt; Not sure why you're having such difficulty. =A0Just add a pair of&lt;br&gt;
&amp;gt; &amp;gt; elements at the end of the array that are the same as the first&lt;br&gt;
&amp;gt; &amp;gt; coordinate of the array (so you'll get a closed curve), and use the&lt;br&gt;
&amp;gt; &amp;gt; plot command. =A0It's quite capable of plotting a closed curve such as =&lt;br&gt;
a&lt;br&gt;
&amp;gt; &amp;gt; jigsaw puzzle piece. =A0Why do you need to do sorting????&lt;br&gt;
&amp;gt; &amp;gt; Regards,&lt;br&gt;
&amp;gt; &amp;gt; ImageAnalyst&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Because, I predict the points are scattered. The OP does&lt;br&gt;
&amp;gt; not have a polygon, only a list of scattered points, in no&lt;br&gt;
&amp;gt; specific order.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; The simplest solution is to use one of the traveling salesman&lt;br&gt;
&amp;gt; codes that Joseph Kirk has posted to the file exchange. In&lt;br&gt;
&amp;gt; fact, he has codes that assume the start and end points&lt;br&gt;
&amp;gt; must be the same, as required for a closed polygon. The&lt;br&gt;
&amp;gt; TSP code will produce a polygon as the OP desires.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; HTH,&lt;br&gt;
&amp;gt; John&lt;br&gt;
&lt;br&gt;
-----------------------------------------&lt;br&gt;
John, I think you're right - I didn't think of it that way.  Well for&lt;br&gt;
a random cluster of points there are numerous ways that you could&lt;br&gt;
possibly draw enclosing perimeters.  If each point is not necessarily&lt;br&gt;
required to be on the perimeter, the simplest way (if you have the&lt;br&gt;
image processing toolkit) is to just pass them in to poly2mask or&lt;br&gt;
roipoly, and then pass the result into the convex hull.  Just two&lt;br&gt;
lines.  But the piece is all convex - no bays, nooks, and crannies.&lt;br&gt;
If you want concave as well as convex portions on the perimeter, then&lt;br&gt;
you might take a look at a little known (I think) method called &quot;alpha&lt;br&gt;
shapes.&quot;  Google it or go here:&lt;br&gt;
&lt;a href=&quot;http://cgm.cs.mcgill.ca/~godfried/teaching/projects97/belair/alpha.html&quot;&gt;http://cgm.cs.mcgill.ca/~godfried/teaching/projects97/belair/alpha.html&lt;/a&gt;&lt;br&gt;
The alpha parameter is how much the perimeter &quot;hugs&quot; the points.&lt;br&gt;
Makes an outline kind of like if you put the points into heat-shrink&lt;br&gt;
wrap or vacuum-pack plastic film.  The alpha is like how much heat or&lt;br&gt;
vacuum you apply to the plastic wrap.  I'm personally not familiar&lt;br&gt;
with the method but the demo images look cool.&lt;br&gt;
Regards,&lt;br&gt;
ImageAnalyst</description>
    </item>
    <item>
      <pubDate>Sat, 15 Nov 2008 03:33:01 -0500</pubDate>
      <title>Re: sorting, 2D vector, puzzle piece shaped</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239257#611021</link>
      <author>John D'Errico</author>
      <description>ImageAnalyst &amp;lt;imageanalyst@mailinator.com&amp;gt; wrote in message &amp;lt;f6737b12-4c51-4e93-86a0-b54c1fc6887a@i20g2000prf.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; -----------------------------------------&lt;br&gt;
&amp;gt; John, I think you're right - I didn't think of it that way.  Well for&lt;br&gt;
&amp;gt; a random cluster of points there are numerous ways that you could&lt;br&gt;
&amp;gt; possibly draw enclosing perimeters.  If each point is not necessarily&lt;br&gt;
&amp;gt; required to be on the perimeter, the simplest way (if you have the&lt;br&gt;
&amp;gt; image processing toolkit) is to just pass them in to poly2mask or&lt;br&gt;
&amp;gt; roipoly, and then pass the result into the convex hull.  Just two&lt;br&gt;
&amp;gt; lines.  But the piece is all convex - no bays, nooks, and crannies.&lt;br&gt;
&amp;gt; If you want concave as well as convex portions on the perimeter, then&lt;br&gt;
&amp;gt; you might take a look at a little known (I think) method called &quot;alpha&lt;br&gt;
&amp;gt; shapes.&quot;  Google it or go here:&lt;br&gt;
&amp;gt; &lt;a href=&quot;http://cgm.cs.mcgill.ca/~godfried/teaching/projects97/belair/alpha.html&quot;&gt;http://cgm.cs.mcgill.ca/~godfried/teaching/projects97/belair/alpha.html&lt;/a&gt;&lt;br&gt;
&amp;gt; The alpha parameter is how much the perimeter &quot;hugs&quot; the points.&lt;br&gt;
&amp;gt; Makes an outline kind of like if you put the points into heat-shrink&lt;br&gt;
&amp;gt; wrap or vacuum-pack plastic film.  The alpha is like how much heat or&lt;br&gt;
&amp;gt; vacuum you apply to the plastic wrap.  I'm personally not familiar&lt;br&gt;
&amp;gt; with the method but the demo images look cool.&lt;br&gt;
&amp;gt; Regards,&lt;br&gt;
&amp;gt; ImageAnalyst&lt;br&gt;
&lt;br&gt;
You are correct that an alpha shape is an option here.&lt;br&gt;
It can give a triangulation of the &quot;puzzle piece&quot;, then&lt;br&gt;
you would extract the boundary of that triangulation&lt;br&gt;
to yield the circuit of the points. &lt;br&gt;
&lt;br&gt;
Beware - there are subtly different versions of alpha&lt;br&gt;
shape however. Some require the alpha ball to ride&lt;br&gt;
around only on the perimeter of the object, others&lt;br&gt;
allow it to also erode from within. The link posted&lt;br&gt;
above is the latter kind of alpha shape, but you need&lt;br&gt;
the former style of alpha shape.&lt;br&gt;
&lt;br&gt;
Finally, a problem with an alpha shape here is it will&lt;br&gt;
not always yield a circuit of the points, as a TSP will&lt;br&gt;
do. I would often expect to see some subset of the&lt;br&gt;
points that remain inside the interior of the alpha&lt;br&gt;
shape.&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
    <item>
      <pubDate>Mon, 17 Nov 2008 16:36:02 -0500</pubDate>
      <title>Re: sorting, 2D vector, puzzle piece shaped</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239257#611312</link>
      <author>Mahdieh </author>
      <description>&quot;John D'Errico&quot; &amp;lt;woodchips@rochester.rr.com&amp;gt; wrote in message &amp;lt;gflftd$1hf$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; ImageAnalyst &amp;lt;imageanalyst@mailinator.com&amp;gt; wrote in message &amp;lt;f6737b12-4c51-4e93-86a0-b54c1fc6887a@i20g2000prf.googlegroups.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; -----------------------------------------&lt;br&gt;
&amp;gt; &amp;gt; John, I think you're right - I didn't think of it that way.  Well for&lt;br&gt;
&amp;gt; &amp;gt; a random cluster of points there are numerous ways that you could&lt;br&gt;
&amp;gt; &amp;gt; possibly draw enclosing perimeters.  If each point is not necessarily&lt;br&gt;
&amp;gt; &amp;gt; required to be on the perimeter, the simplest way (if you have the&lt;br&gt;
&amp;gt; &amp;gt; image processing toolkit) is to just pass them in to poly2mask or&lt;br&gt;
&amp;gt; &amp;gt; roipoly, and then pass the result into the convex hull.  Just two&lt;br&gt;
&amp;gt; &amp;gt; lines.  But the piece is all convex - no bays, nooks, and crannies.&lt;br&gt;
&amp;gt; &amp;gt; If you want concave as well as convex portions on the perimeter, then&lt;br&gt;
&amp;gt; &amp;gt; you might take a look at a little known (I think) method called &quot;alpha&lt;br&gt;
&amp;gt; &amp;gt; shapes.&quot;  Google it or go here:&lt;br&gt;
&amp;gt; &amp;gt; &lt;a href=&quot;http://cgm.cs.mcgill.ca/~godfried/teaching/projects97/belair/alpha.html&quot;&gt;http://cgm.cs.mcgill.ca/~godfried/teaching/projects97/belair/alpha.html&lt;/a&gt;&lt;br&gt;
&amp;gt; &amp;gt; The alpha parameter is how much the perimeter &quot;hugs&quot; the points.&lt;br&gt;
&amp;gt; &amp;gt; Makes an outline kind of like if you put the points into heat-shrink&lt;br&gt;
&amp;gt; &amp;gt; wrap or vacuum-pack plastic film.  The alpha is like how much heat or&lt;br&gt;
&amp;gt; &amp;gt; vacuum you apply to the plastic wrap.  I'm personally not familiar&lt;br&gt;
&amp;gt; &amp;gt; with the method but the demo images look cool.&lt;br&gt;
&amp;gt; &amp;gt; Regards,&lt;br&gt;
&amp;gt; &amp;gt; ImageAnalyst&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You are correct that an alpha shape is an option here.&lt;br&gt;
&amp;gt; It can give a triangulation of the &quot;puzzle piece&quot;, then&lt;br&gt;
&amp;gt; you would extract the boundary of that triangulation&lt;br&gt;
&amp;gt; to yield the circuit of the points. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Beware - there are subtly different versions of alpha&lt;br&gt;
&amp;gt; shape however. Some require the alpha ball to ride&lt;br&gt;
&amp;gt; around only on the perimeter of the object, others&lt;br&gt;
&amp;gt; allow it to also erode from within. The link posted&lt;br&gt;
&amp;gt; above is the latter kind of alpha shape, but you need&lt;br&gt;
&amp;gt; the former style of alpha shape.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Finally, a problem with an alpha shape here is it will&lt;br&gt;
&amp;gt; not always yield a circuit of the points, as a TSP will&lt;br&gt;
&amp;gt; do. I would often expect to see some subset of the&lt;br&gt;
&amp;gt; points that remain inside the interior of the alpha&lt;br&gt;
&amp;gt; shape.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; John&lt;br&gt;
&lt;br&gt;
It seems that I am getting fairly good results from my combination code, using TSP and the theta ... &lt;br&gt;
However I have looked into the alpha shape a bit. So far I can not work with the Demo ... I will try my best to get that too and compare the results to each other ...&lt;br&gt;
&lt;br&gt;
Thanks a lot to John and Image Analyst :)&lt;br&gt;
-mah</description>
    </item>
    <item>
      <pubDate>Thu, 26 Jan 2012 17:18:10 -0500</pubDate>
      <title>Re: sorting, 2D vector, puzzle piece shaped</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239257#864920</link>
      <author>Bogdan Dzyubak</author>
      <description>I tried this and it seems like there should be a simpler way. The traveling salesman assumes you can go between any two cities, not just along the contour. This means calculation takes a long time and the result doesn't give a closed contour route. A possible solution is to drop a high weight function in the middle of the contour.</description>
    </item>
    <item>
      <pubDate>Thu, 26 Jan 2012 18:18:10 -0500</pubDate>
      <title>Re: sorting, 2D vector, puzzle piece shaped</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/239257#864925</link>
      <author>Matt J </author>
      <description>&quot;Bogdan Dzyubak&quot; &amp;lt;illan7@gmail.com&amp;gt; wrote in message &amp;lt;jfs1si$1tj$1@newscl01ah.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;A possible solution is to drop a high weight function in the middle of the contour.&lt;br&gt;
&lt;br&gt;
Only if the points are approximately the boundary of a convex shape.</description>
    </item>
  </channel>
</rss>

