4

i have an assignment in which the user can draw lines on a form. As soon as the user creates a line, the line is pushed into the list containing all the lines previously entered by user. The lines are then drawn on to the the frame so that the user can see it in yellow colour. My task is that when ever a user tries to make a connected object using lines, that object must turn green instead of yellow. So i have the two coordinates of every line segment, how can i determine that a closed object is being formed by a set of lines. Is there any algorithm that i can follow? enter image description here

1 Answers1

2

For each segment, find the intersection point with the other segments (if exists). When you find an intersection point, link it with the two related segments.

You now have an "undirected graph" with intersection points as vertices and segments as edges.

All that's left to do is to find cycles in your graph. Each cycle is a closed object.

Community
  • 1
  • 1
Nicolas Repiquet
  • 9,097
  • 2
  • 31
  • 53
  • Link to solution is not provide cycle, it just provide EXISTS or NOT EXISTS. Also required shape created polygon. – Толя Jan 15 '13 at 11:38