From: ImageAnalyst <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: sorting, 2D vector, puzzle piece shaped
Date: Fri, 14 Nov 2008 19:13:45 -0800 (PST)
Lines: 64
Message-ID: <>
References: <gfk6hl$snc$> <> 
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: 1226718826 15418 (15 Nov 2008 03:13:46 GMT)
NNTP-Posting-Date: Sat, 15 Nov 2008 03:13:46 +0000 (UTC)
Injection-Info:; posting-host=; 
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET 
	CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 
Xref: comp.soft-sys.matlab:500942

On Nov 14, 12:40=A0pm, "John D'Errico" <>
> ImageAnalyst <> wrote in message <cfb67021-f6d=>...
> > On Nov 14, 10:47=3DA0am, "Mahdieh" <>
> > wrote:
> > > I have a nx2 vector, which includes the XY coordinates of the n point=
> > > When plotted, these points create a shape looking like a puzzle piece=
> > > Now, I need to sort this vector, such that by connecting two conseque=
nt p=3D
> > oints in the vector, I would get the permieter of the shape. i.e. conse=
> > 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. =A0Just 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. =A0It's quite capable of plotting a closed curve such as =
> > jigsaw puzzle piece. =A0Why 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

John, I think you're right - I didn't think of it that way.  Well for
a random cluster of points there are numerous ways that you could
possibly draw enclosing perimeters.  If each point is not necessarily
required to be on the perimeter, the simplest way (if you have the
image processing toolkit) is to just pass them in to poly2mask or
roipoly, and then pass the result into the convex hull.  Just two
lines.  But the piece is all convex - no bays, nooks, and crannies.
If you want concave as well as convex portions on the perimeter, then
you might take a look at a little known (I think) method called "alpha
shapes."  Google it or go here:
The alpha parameter is how much the perimeter "hugs" the points.
Makes an outline kind of like if you put the points into heat-shrink
wrap or vacuum-pack plastic film.  The alpha is like how much heat or
vacuum you apply to the plastic wrap.  I'm personally not familiar
with the method but the demo images look cool.