       Re: Sorting complex points

• To: mathgroup at smc.vnet.net
• Subject: [mg55881] Re: Sorting complex points
• From: "news.online.de" <petsie at arcor.de>
• Date: Sat, 9 Apr 2005 03:55:16 -0400 (EDT)
• Organization: 1&1 Internet AG
• References: <d356km\$ovn\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```OT wrote:
> Hi all,
>
> I'm trying to sort lists of random complex points on the unit circle
> using their angles as criterion to sort them: I mean, if
> z=Cos[a]+I*Sin[a] and w=Cos[b]+I*Sin[b]( 0<=a,b<2*Pi ),
> I want z<w if a<b;
>
> how can i do that?
>
> I tried to define Angle[z] as a piecewise funztion, but I still don't
> understand how to use it with Sort...
>
> Thanks,
>
> andrea
>
Have a look at the help for Sort[list,p]. p is a function which takes
two arguments and returns True or False. This relation defines the
order. You want to compare the Arg[] of two complex numbers, so the
following should do what you want:

(*lookAt[] visualizes the list of complex numbers*)
lookAt[lst_]:=ListPlot[{Re@#,Im@#}&/@lst,PlotJoined->True];
lookAt@(data=Table[Random[Complex,{-1-I,1+I}],{50}]);

and now use Sort[] to get an open star-shaped plot

lookAt@Sort[data,Arg[#1]<Arg[#2]&];

--
Peter Pein
Berlin

```

• Prev by Date: Re: Sorting complex points
• Next by Date: Re: Re: spiral cipher
• Previous by thread: Re: Sorting complex points
• Next by thread: Re: Sorting complex points