Challenge with sort component - grasshopper

I have a grid and 3 points that act as attractors. After evaluating all the distances between the attractors and the grid, I want to select the 1st X cells closest to all 3. Instead, I am getting the first x cells for each individual attractor. For example, let’s say I need the closest 9 cells to the attractors, how can I sort the list according to all the distances computed?

What am I doing wrong?

You’re not posting the GH code for others to play with.

Hi Joseph, here is the code. Hope my question makes sense… Essentially I want to distribute the X closest along all attractors. I can tweak what I have with division, but this method is not precise.

Cull points into equal groups by attractors.gh (14.1 KB)

You need to internalize your Pt param.

They are, just not in the file I sent you.

You need to right-click the Pt param and choose “Internalize data” before saving the file.

Oh. I see what you mean. Ok. I can’t get into the file atm (someone else is using the Rhino license). You can place any 3 random points on the grid if you want…

closest.gh (9.1 KB)


i think i might of mis-read what you’re after…

when you say you want 3 closest points, do you mean you want only 3 points and they’re closest to all three attractors as if the attractors are one?

like-- find an average point of the three attractors… then find the nearest 3 cells to that average point?


idk

2 Likes


Cull_points_2018Jan29a.gh (17.4 KB)

@jeff_hammond, our results appear to be a bit different using the same attractor points? I was a little confused by the wording too. “The first X cells closest to each attractor point” is how I interpreted it.

Later… @jeff_hammond, never mind! I figured out why they were different; your HexGrid dimensions were different from mine. Well done!

1 Like

here it is with your random attractor generator plugged in:

closest_random.gh (13.8 KB)

(i too forgot to internalize the attractor points in my first upload :wink: …the populate thing does the trick though)

Thanks everyone for your efforts. It seems we are all achieving the same results. I can get x number of cells to populate along each “attractor” easily. The challenge is that I have a limited number of x to distribute to ALL the attractors.

So I’m trying to get the algorithm to go 1st closest to each point, then 2nd closest, then 3rd closest until the run stops when we’ve done this x times… I hope this is clearer…?

I was thinking one way to do this would be to grab all the distances betwen each attractor point and each cell and re-sort them based on distance lengths. Then let’s say, grab the first x in the sorted set and reparametrise somehow so that only those 1st x (or range) are picked. That’s where I’m stumped.

sorry… i’m still not clear.

like this?

closest2.gh (12.3 KB)

though doing it like that means some states will have 3 points around one attractor and maybe only one around another…


For example, let’s say I need the closest 9 cells to the attractors

I think you mean something like this where all attractors are essentially treated as one overall attractor? So x points closest to the attractors as a collective, not x points per attractor?

ClosestPoint.gh (12.4 KB)

Michael Pryor, that is exactly it! Apologies to everyone for the confused wording. I feel this was more of a mathematical problem than a gh implementation. Thank you everyone for your kind efforts!

What is the difference between the distance output in “closest component” and the distance output in the “distance” component?

Also, how can I expand your method to select the next “n” number of around the first set? That’s the last part of this challenge.

pull point (and the other pull components) has a different algorithm that when set in closest mode only returns the distance to the closest pulling geometry. So if you have 3 attractors, it measures distance of each grid point to each attractor and returns only the closest distance, rather than all 3 distances.

I’m not sure exactly what this means, can you elaborate further?

Michael,

that is very useful to know! In this case, we are giving x 1st cells to the attractors. This works just as intended. In the 2nd round, we want to give another x cells around the attractors. Essentially, I am trying to give certain categories around the attractors where the numbers are already predefined. I have x y z of each category a b c. A will be the closest, then B, then C. Again, I think this is more of a math challenge than implementation…I’m trying to think this through here. Thanks for your help on this!

I am using sub lists and …I think it’s working (?) Am doing more testing… I think the pull point vs distance is very useful difference to know.