MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Sorting complex points


On 4/8/05 at 1:37 AM, montoz at iol.it (OT) wrote:

>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?

Use Arg with Sort, i.e.

First generate some random points on the circle

data = {#,Sqrt[1-#^2]}&/@Table[Random[],{5}];

Then sort the data as follows:

s=Sort[data, OrderedQ at {Arg[#1.{1,I}],Arg[#2.{1,I}]}&]

and finally after loading Graphics`

<<Graphics

DisplayTogether[
   LabeledListPlot[MapIndexed[Join, s], Axes -> None], 
   ParametricPlot[{Cos[x], Sin[x]}, {x, 0, 2*Pi}], 
   PlotRange -> {{-1.1, 1.1}, {-1.1, 1.1}}, 
   AspectRatio -> 1]; 

results in a nice display showing the points are sorted by angle and lie on a unit circle
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Sorting complex points
  • Next by Date: Re: Recommendations for a programming book?
  • Previous by thread: Re: Sorting complex points
  • Next by thread: Re: Sorting complex points