Example http://xthlegion.co.uk/images/dividerectangle.png Example http://xthlegion.co.uk/images/dividerectangle2.png

If you consider the images above, you can see they are comprised of a single large rectangle broken down into smaller rectangles by pairs of user defined coordinates (each pair in the example images are identified with a different color).

What I'm trying to do is obtain the co-ordinates of those rectangles by only defining the joins. Edges are treated as explicit joins. Order doesn't matter.

Does anyone know the name of the algorithm that does this (I'm sure there's one with a fancy name!) or have some example C# code? I've been struggling trying to do this myself for a while now but am having little success. Yet another total math fail!

Update:
Just thought I'd quickly update this question based on the comments I've received.

  1. Lines must be straight, so each pair of co-ordinates will align on one axis
  2. Co-ordinates must start from either an edge, or the intersection of another pair. The second co-ordinate must end in a similar fashion. Any "orphan" co-ordinates which don't start/end one another join are illegal and I should ignore them for now, snapping should be possible once I finally get my head in gear.
  3. Although in this example all the pairs more or less neatly divide the rectangle, this will not be the case in practice and there could be many lines creating rectangles of many sizes.

2nd Update - it works :)
Example http://xthlegion.co.uk/images/dividerectangle3.png

Edit
Report