Grasshopper

generative modeling for Rhino

# Sorting Points by x- and y- values

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

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

by stefano

• View All