Original Post
Hey guys,
I have come across a nice computer science problem.
I have a bunch of 2d polygons and I know they don't intersect each other, but they can be contained inside each other.
Think of a box contained in a box contained in a box. I have a method IsContained(p1,p2) that tests whether polygon p1 is inside polygon p2.
I know want to reconstruct the tree structure of the containment of the polygons.
For instance, if box b1 is contained in box b2 and b2 is contained in b3, IsContained(b1, b2) == true and IsContained(b2, b3) == true,
but also IsContained(b1, b3) == true. I'd like to have a tree that tells me that the parent of b1 is b2, not b3, and that b3 is the root.
There could possibly be many roots, so strictly speaking I want to get a list of trees.
I already have a fairly brute-force method doing that, but I'd like to know if there's a clever way of doing that. Some sort of Dijkstra algorithm maybe?
Thanks,
- Lutz
I have come across a nice computer science problem.
I have a bunch of 2d polygons and I know they don't intersect each other, but they can be contained inside each other.
Think of a box contained in a box contained in a box. I have a method IsContained(p1,p2) that tests whether polygon p1 is inside polygon p2.
I know want to reconstruct the tree structure of the containment of the polygons.
For instance, if box b1 is contained in box b2 and b2 is contained in b3, IsContained(b1, b2) == true and IsContained(b2, b3) == true,
but also IsContained(b1, b3) == true. I'd like to have a tree that tells me that the parent of b1 is b2, not b3, and that b3 is the root.
There could possibly be many roots, so strictly speaking I want to get a list of trees.
I already have a fairly brute-force method doing that, but I'd like to know if there's a clever way of doing that. Some sort of Dijkstra algorithm maybe?
Thanks,
- Lutz