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?

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.

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…

@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!

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.

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?

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!

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.

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!