Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7617 > unrolled thread

Re: Sorting coefficients

Started byBob Hanlon <hanlonr357@gmail.com>
First post2012-01-07 10:17 +0000
Last post2012-01-07 10:17 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Sorting coefficients Bob Hanlon <hanlonr357@gmail.com> - 2012-01-07 10:17 +0000

#7617 — Re: Sorting coefficients

FromBob Hanlon <hanlonr357@gmail.com>
Date2012-01-07 10:17 +0000
SubjectRe: Sorting coefficients
Message-ID<je9641$is5$1@smc.vnet.net>
pts = Prepend[
   Table[{Re, Im}[E^(k (2 \[Pi])/6 I)] //
     Through, {k, 0, 5}], {0, 0}];

n = 1; Graphics[Text[n++, #] & /@ pts]


To sort by layer and then within layer

order2 = SortBy[pts,
   {N[Last[#]], N[First[#]]} &];

Note that the coordinates need to be converted to Reals for the
canonical order to be the same as numerical order.

n = 1; Graphics[Text[n++, #] & /@ order2]


Sorting from lower left to upper right

order3 = SortBy[pts,
   {Norm[N[#] - order2[[1]]], Last[N[#]]} &];

n = 1; Graphics[Text[n++, #] & /@ order3]


Bob Hanlon


On Fri, Jan 6, 2012 at 4:14 AM, Chris Young <cy56@comcast.net> wrote:
> I'm trying to get my points sorted first by rows first. But I'm having
> trouble figuring out how to do the kind of double sorting I need with
> Sort. SortBy seems very hard to figure out and I'm not sure if it's
> what I need here.
>
> I've just got a hexagonal layout of point coordinates, with another one
> on the origin, and I'm trying to sort everything from lower left to
> upper right. I.e., the usual ordering of going through the bottom row
> from left to right, then through the middle row from left to right, etc.
>
> Any help appreciated.
>
> Chris Young
> cy56@comcast.net
>
>
> In[1043]:= Prepend[
>  Table[{Re, Im}[ E^(k (2 \[Pi])/6 I)] // Through, {k, 0, 5}], {0, 0}]
>
> Out[1043]= {{0, 0}, {1, 0}, {1/2, Sqrt[3]/2}, {-(1/2), Sqrt[3]/
>  2}, {-1, 0}, {-(1/2), -(Sqrt[3]/2)}, {1/2, -(Sqrt[3]/2)}}
>
> In[1046]:= Sort[%1043, #1[[2]] < #2[[2]] &]
>
> Out[1046]= {{1/2, -(Sqrt[3]/2)}, {-(1/2), -(Sqrt[3]/2)}, {-1, 0}, {1,
>  0}, {0, 0}, {-(1/2), Sqrt[3]/2}, {1/2, Sqrt[3]/2}}
>
> In[1073]:= Sort[%1046, #1[[2]] < #2[[2]] &]
>
> Out[1073]= {{-(1/2), -(Sqrt[3]/2)}, {1/2, -(Sqrt[3]/2)}, {0, 0}, {1,
>  0}, {-1, 0}, {1/2, Sqrt[3]/2}, {-(1/2), Sqrt[3]/2}}
>

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web