My program has a List<Vector3>
of unique points (A, B, C, ...) which are created each time a user draws a unique line (1, 2, 3, ...). Lines are stored in a List<int>
where every two ints are the indices of each point to form a single line. No two lines can have the same two points, no points can occupy the same position, and stray lines are allowed.
Points: {A, B, C, D, E} //Each letter represents a 2d or 3d position
Sides: {0,1,1,2,1,3,3,4,4,2} //(Each int is an index in Points, every pair is a side)
I am trying to find an efficient way of determining when a new line (Green, 5) closes a polygon with any number of sides. I have a way of doing this: iterating through each line connected to each side of the new line(and all subsequent lines) until they share a point (D).
My only problem here is that the more sides a polygon has, I need to do exponentially more checks (Every two additional sides on the polygon causes me to check one layer deeper on all attached sides).
Is there a way to reduce the number of checks I need to do in order to close the polygon?
Not exactly the same as Cycles in an Undirected Graph. This knows that at least one cycle is present and connected to a given side, and is looking for only the smallest cycle possible connected to that side. Other sides are irrelevant and it should avoid them.