0

Let's say I have 9 points on a plane and following image shows the sequence by which I put lines (vertices) on those points.

5/9 points connected

and I keep track of points and lines both separately in a vector. And now I put another line (that can be anywhere) but following is what plain looks like now

6th point connected

How can I find out that 6th vertex (or recently added vertex) makes four sided box (doesn't have to be just square, as long as they make enclosed box—that's it).

I understand finding the distance between two lines/vertices can be a good start, but can someone please explain how is this going to be?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
abumusamq
  • 780
  • 1
  • 10
  • 29

1 Answers1

1

Label the points:

a b c
d e f
g h i

So line 1 connects (a-d), line 2 connects (d-e) and so on. As you add lines, keep lists of connected points. So after you have added line 4, the lists are {a,d,e} and {g,h,i}. Line 5 connects (e-h), so it merges the lists into {a,d,e,g,h,i}. Then line 6 connects (d-g), two points that are already in one list, so it must form a closed loop.

Beta
  • 96,650
  • 16
  • 149
  • 150
  • It isn't clear to me if there are additional constraints in play here but, based on the example figures, there might be. If there is a constraint that the box be 4-sided (rather than n-sided), it might be necessary to add an additional test to verify that constraint. Further, if there is a constraint that the loop contains a non-zero area, it might be necessary to verify that there are no repeated intermediate points (like a-b-c-b-a, which would form a closed loop that contains no area) or that the lines of the figure don't cross at an unlabelled point (e.g. giving an hourglass figure). – Simon Feb 24 '13 at 06:51