From: ImageAnalyst <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: sorting, 2D vector, puzzle piece shaped
Date: Fri, 14 Nov 2008 09:08:22 -0800 (PST)
Lines: 35
Message-ID: <>
References: <gfk6hl$snc$>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: 1226682502 1587 (14 Nov 2008 17:08:22 GMT)
NNTP-Posting-Date: Fri, 14 Nov 2008 17:08:22 +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 
X-HTTP-Via: 1.1 bdci2px (NetCache NetApp/6.0.7)
Bytes: 2700
Xref: comp.soft-sys.matlab:500860

On Nov 14, 10:47=A0am, "Mahdieh" <>
> 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:
> 1- =A0a. 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 vect=
or ...
> 2- a. dividing the shape into 4 quadrants, b. sorting each quadrant based=
 on X or Y c. connecting them together
> none of the methods, accomplish sorting the whole shape ...
> I am out of algorithms,
> any help would be really appreciated ...
> Thanks a lot
> -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????