Using Geometry.DistanceTo within sublists

Hi everyone,

In my script I have two lists, consisting of sublists, which I want to compare with the Geometry.DistanceTo node. My first list contains sublists of points and my second list contains sublists of lines.
I would like to compare each point from sublist 0 against each line in sublist 0 to measure it’s distance, and also for each other list only the other corresponding sublist:

I’ve managed to get the desired results I want by first flatting the list with all my lines and then compare each point against each line (so 6 comparisons instead of 2 for each point).

At this scale with only 12 points and 6 lines it doesn’t really matter, but in my main script I can easily have over 50.000 points and 1000 lines so I would really like to only compare sublists.

I would really appreciate it if you guys could see if you can manage to only do the comparison within the respective sublists :smiley: .

GeometryDistanceTo within Sublists Test.DYN (77.9 KB)

You usually can’t combine list levels and lacing like this unless a node is already built for specific list inputs (not just recursion). Whenever list structure gets specific like this your best bet is always to match list length and structure. Duplicate each line by the number of points in the respective sublist and do the same to points. That way you end up with a one-to-one comparison of points and lines.

I’m not sure if understood correctly but if I did, I think replication guide would do the trick.

Autodesk.Geometry.DistanceTo(pts<1>,lines<1><1>);

image

3 Likes

I’m not sure if understood correctly but if I did, I think replication guide would do the trick.

Use extra list levels is think you get the solution you want. (without flatten)
What is your use case?

image

Hi guys, thanks for the input!
The code block from @EdsonMatt works great with this edit:
Autodesk.Geometry.DistanceTo(pts<1><1>,lines<1>);

1 Like