Sort lists by proximity

Hello community,

We need to do an exercise and I wonder if you have come across this before:

We have two lists of points:

List A has X,Y and Z Coordinates
List B has X,Y Coordinates

Points in List B are close to points on A, let’s say in radius<500mm

The goal is to copy the Z Coordinates from List A into List B, but we need to put both lists in the same order based on their X and Y coordinates proximity.

Our first try was to generate a mesh from list A and create lines with start points from list B and the distance from 0 to the mesh will give us the Z coordinates of these points, but when I try geometry.intersect Dynamo crashes.

Image attached of our current approach.

Any other approach???

Many thanks!!!

Can you explain your overall goal here? How do you know which Z coordinate to use? Is it based off the closest point in any direction? Closest point in the Z direction? Could you use ProjectInputOnto? How are the points being sorted? X first then Y? We need more information to give you a solid answer.

1 Like

Hi Nick,
I think I got what I needed from this post:

I need to copy z coordinates from a list to another list based on the shortest distance.

The logic seems to be right but the outcome isn’t.

The node Geometry.Distance to calculate the distance between all the points
List.MinimumItem give me the smallest distance per sublist
Index of give me the index of the shortest distance within the sublist
This way I can feed the second list with the right values from the first list
Everything seems to be working fine but the output is not!!!
I think the problem is on the calculation of distances, anyone know how this node works???

Attached Graph and data sets.Home.dyn (20.4 KB)
points data_.xls (84 KB)
text data.xls (169.5 KB)

I think you need to switch your Geometry.DistanceTo inputs. You’re finding the shortest distance in the bottom list then pulling the item from the first list.

Hello Nick,

Thanks for your prompt answer,

Can you explain me a bit what you mean please?

The index you’re getting is the index for the closest item in the bottom list. But you’re using it to select the item in the top list. You need to flip the inputs so that you’re getting the closest item in the top list and therefore pulling the correct item from that same list.

you mean to swap the inputs in the Geometry.DistanceTo?
Geom to other
other to geom???


Thanks soooooo muuuuuuch!!!