# Sets question

Hello
This problem about combine sets or tree branches which have similar numbers, @DavidRutten Already solved it years ago with c#
And i think loop can do the same thing as the script but is there a method to do that with components or Python

sets.gh (6.4 KB)

1 Like

I’m not quite sure I follow, but the Python set class has methods such `union`, `intersection`, and `difference` (and more) that might help get you started.

Thanks, All these are available as components but how to resolve it this is the problem.

Just giving a try with geometrical approach…

1 Like

In this specific case, @Jakinta, you have final set restults that doesn’t overlap.
Region union is not good in this matter.
Replace 11 with 3 and 3 with 11 on first panels and you’ll understand.

You can do something similar but with meshes, see here: Sort intersected curves

Also, I believe @seghierkhaled is searching for a pure math (with sets) solution, without going geometric.

2 Likes

Hi @Jakinta, As @maje90 this will not work for case like this

This is a solution based on @maje90 idea in the thread mentionned

Yes you are right , sometimes the solutions are very simple but i can’t find it and sometimes problems looks very simple but they are very complex.

Attached is a replica of David’s C# component in python.
sets py.gh (8.0 KB)

2 Likes

That is correct. As soon as i posted it, realised it was wrong.

1 Like

it’s a step for the right solution but as @maje90 said , the solution don’t work where branches have a single item, maybe will work by using set difference between the original tree and the result

Ehm… indeed… I’ve just updated the other thread in the same way you described.

1 Like

Thank you @djordje, it work fine; and it will help to solve many problems .
I will convert it to a component if you accept

1 Like

Solution of @djordje is the Python solution .
And i still want find another solution with Math components if Grasshopper can do it .

This solution based on ideas of @maje90 and @Jakinta

sets.gh (14.0 KB)

2 Likes

Ghpython component , i called it Sets intersection , i don’t know if it is the right term.

Credit to @djordje & @DavidRutten

Sets Intersection.ghpy (24 KB)

1 Like