Grasshopper

generative modeling for Rhino

I'm looking for a way to sort a list points, built up from series of x and y values, by the y-values first and then, by x-values:

 

Current List: Output from Point XYZ Component

 

(0.0, 0.0, 0.0)

(1.0, 0.0, 0.0)

(2.0, 0.0, 0.0)

(3.0, 0.0, 0.0)

(0.0, 1.0, 0.0)

(1.0, 1.0, 0.0)

(2.0, 1.0, 0.0)

(3.0, 1.0, 0.0)

(0.0, 2.0, 0.0)

(1.0, 2.0, 0.0)

(2.0, 2.0, 0.0)

(3.0, 2.0, 0.0)

 

Desired List:

(0.0, 0.0, 0.0)

(0.0, 1.0, 0.0)

(0.0, 2.0, 0.0)

(0.0, 3.0, 0.0)

(1.0, 0.0, 0.0)

(1.0, 1.0, 0.0)

(1.0, 2.0, 0.0)

(1.0, 3.0, 0.0)

(2.0, 0.0, 0.0)

(2.0, 1.0, 0.0)

(2.0, 2.0, 0.0)

(2.0, 3.0, 0.0)

 

 

I was unable to make the Sort List Component work successfully:

 

 

 

Thanks,

 

Amanda

Views: 716

Reply to This

Replies to This Discussion

Hi Amanda,

Sort only works on numbers. One number can be smaller or larger than another, but one point cannot really be smaller or larger than another point.

What you need to do is convert your points into numbers. Since you want to sort first by x, then by y (if x is identical), then by z (if x and y are identical), you need to somehow munge these three coordinates into a single number.

Now, if you can be certain that the coordinates are not excessively large or small numbers, then you can do something like the following:

sortkey = 10,000 * x + 100 * y + z

Then you Sort the list of sortkeys while synchronously sorting your original pointlist:


--
David Rutten
david@mcneel.com
Poprad, Slovakia
Thank you for your quick reply. Problem solved. :)

RSS

Translate

Search Grasshopper

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2013   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service