I have a list of solids that I’ve created and now want to check to see if they intersect with each other. Need some pointers on how to iterate this list so that the 1st solid checks for intersection against the rest, the 2nd against the 3rd through the remainder, 4th against 5th through remainder, etc.
Is the question ‘does this solid intersect any other solid’, or is the question ‘which solids intersect this solid’?
If the former:
- Use a List.DropItems to remove a range of
1..List.Count(solids);
. The result of the List.DropItems node should be a series of sublists for all the solids. - Union each of the sublists of solids into single solids. This will represent ‘all the solids you haven’t tested against the solid at the same index’. You may have to proceed this with a List.Clean node to remove the last sublist (which would otherwise be empty).
- Use a Geometry.DoesIntersect node to check if each of the original solids intersects the combined solid. Any ‘true’ result means the solid at that index intersects something else and is an issue.
2 Likes
That’s it!!! Thanks so much for your help!
1 Like
Or given this list
solids = [1, 2, 3, 4, 5, 6]
pairs = []
for i in range(len(solids)):
for j in range(i + 1, len(solids)):
pairs.append((solids[i], solids[j]))
OUT = pairs
Then check each pair. Not sure if one system is faster than another. If you could load itertools you could use combinations.
pairs = list(combinations(solids, 2))
That is N*(N-1) checks though, rather than N checks. Result of which will usually be more time consuming, though the way memory is managed in Python you might be OK with that.
Think it is only N(N-1)/2, but still more than N. Would depend on the overhead of the union operations vs just intersection checks.
1 Like
Ah yeah you’re right on the count. You could add a ‘stop’ to the iteration of a piece intersects another…