Pregunta

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?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top