I'm trying to work on a game mechanic in c# that involves connecting vertices and forming polygons.
There can be any number of 5 - 30 vertices. Each vertice can be connected with a straight line(The lines cannot intersect). When the line closes a polygon the inside of the polygon is colored in a specific color. (You cannot close a polygon if there would be a point inside it during the closing)
For example two pictures below cannot happen:
However, this can:
What i am having trouble with is how to discern the polygon i have just closed and remembering it (in case i close a polygon that shares an edge with it). I can have multiple closed polygons until all lines that can be drawn from each vertice without breaching the intersect rule can be drawn.
I tried remembering lines that were drawn AB, ED, CD, CA etc.. and looking for a cycle, but when i close multiple polygons i need more information to know which polygon has already been closed. But I'm having difficulty figuring out how to do so.
For example (picture below), if the line n was drawn i want to find the polygon that was just made.
Does anyone have any idea how i might achieve this? Any idea, help, insight would be helpfull.
n
will be new... I think at least :P – Theo Walton