Path: news.mathworks.com!not-for-mail
From: "Mahdieh" <mahdieh.emrani@capitalhealth.ca>
Newsgroups: comp.soft-sys.matlab
Subject: Re: sorting, 2D vector, puzzle piece shaped
Date: Fri, 14 Nov 2008 18:40:18 +0000 (UTC)
Organization: Glenrose Research Building
Lines: 41
Message-ID: <gfkgmi$dkj$1@fred.mathworks.com>
References: <gfk6hl$snc$1@fred.mathworks.com> <cfb67021-f6d7-4853-b3bb-52e1211a087a@a3g2000prm.googlegroups.com> <gfkd60$q5a$1@fred.mathworks.com>
Reply-To: "Mahdieh" <mahdieh.emrani@capitalhealth.ca>
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 1226688018 13971 172.30.248.35 (14 Nov 2008 18:40:18 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 14 Nov 2008 18:40:18 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1449772
Xref: news.mathworks.com comp.soft-sys.matlab:500878


"John D'Errico" <woodchips@rochester.rr.com> wrote in message <gfkd60$q5a$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <cfb67021-f6d7-4853-b3bb-52e1211a087a@a3g2000prm.googlegroups.com>...
> > On Nov 14, 10:47=A0am, "Mahdieh" <mahdieh.emr...@capitalhealth.ca>
> > wrote:
> > > I have a nx2 vector, which includes the XY coordinates of the n points.
> > >
> > > When plotted, these points create a shape looking like a puzzle piece.
> > > Now, I need to sort this vector, such that by connecting two consequent p=
> > oints in the vector, I would get the permieter of the shape. i.e. consequen=
> > t points in the vector, correspond to adjacent point in the graph.
> > >
> > > I have tried:
> 
> (Snip)
> 
> > ----------------------------------------------------------
> > Mah:
> > Not sure why you're having such difficulty.  Just add a pair of
> > elements at the end of the array that are the same as the first
> > coordinate of the array (so you'll get a closed curve), and use the
> > plot command.  It's quite capable of plotting a closed curve such as a
> > jigsaw puzzle piece.  Why do you need to do sorting????
> > Regards,
> > ImageAnalyst
> 
> Because, I predict the points are scattered. The OP does
> not have a polygon, only a list of scattered points, in no
> specific order.
> 
> The simplest solution is to use one of the traveling salesman
> codes that Joseph Kirk has posted to the file exchange. In
> fact, he has codes that assume the start and end points
> must be the same, as required for a closed polygon. The
> TSP code will produce a polygon as the OP desires.
> 
> HTH,
> John

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.
Thanks again for the advice, 
-Mah