Python: Solid intersection multiple

It’s kinda difficult to achieve, since you would need complex functions (probably recursive ones) and an expanded knowledge of how booleans work, as well as flawless input geometry, for it to work.

Your basic script logic is right, but it’s missing a lot of stuff!

For instance, in your loop, if i equals j, you are trying to intersect the same brep with itself, which would probably not be desirable.
You could prevent this by simply calling if i != j: before trying to intersect.

You could also try to check for simpler and less costly curve intersections before doing the final boolean ones:

if rs.IntersectBreps(brep1, brep2) != None:
    # continue with boolean intersection

Furthermore, you would need a recursive way to do the intersections, meaning sort of a chain reaction that starts with a brep and intersects it with all the other intersecting breps, meaning not only all of the breps that intersect with the first brep, but all other breps that intersect with breps that intersect with the first brep, but not forcibly with the first brep themselves.

1st recursion:

  • 1 intersects with 2, 3, 4, 6, 7, 8, 9

2nd recursion level (intersecting children of brep 1):

  • 2 intersects with 3, 5, (1), 8, 9;
  • 3 intersects with (2), 4, 5, (1), 8, 9;
  • 4 intersects with (3), 5, (1), 9, 8
  • 5 intersects with (2), (3), (4), 6
  • 6 intersects with (5), (1), 8, 9
    … and so fourth

Also, you would have to implement a way to keep track of what has already been intersected, so you don’t produce duplicate geometry. Above the breps between parenthesis should not be intersected again, since they already had an intersection with the brep! This could be done with lists, list of lists or even dictionaries where you could save the information.

As already mentioned above a node based approach would be a lot simpler.
What geometry do you start with? How do you generate the breps?
Why do you even need the intersections?

1 Like