5
$\begingroup$

Let's say I have two polygons. I know the co-ordinates of both polygons. Now, I need to check whether the first Polygon is completely inside of second polygon? IN this figure only 1 polygon is completely inside of red polygon.

enter image description here

$\endgroup$
4
$\begingroup$

One way would be to compile a list of all edge pairs, and check whether any edges cross each other. If none do, you can choose any point inside one of the polygons, and check weather it is is the second polygon by using the following theorem:

A point is inside a polygon if a ray from this point crosses the polygon's edges an odd number of times.

If the point is inside both, then one of the polygons is inside the other.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ I will try this. Thanks. $\endgroup$ – user960567 Jun 13 '12 at 15:59
3
$\begingroup$

In order for polygon $A$ to be inside polygon $B$, all of the vertices of $A$ must be inside $B$, and all of the vertices of $B$ must be outside $A$. The second condition does not need to be checked if $B$ is known to be convex.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ This is not true. Just try to visulize yourself. $\endgroup$ – user960567 Jun 13 '12 at 15:59
  • $\begingroup$ @mjqxxxx - This is not true if the the polygons intersect. Just imagine a pentagon intersecting a pentagram. $\endgroup$ – nbubis Jun 13 '12 at 17:15
  • $\begingroup$ @nbubis: what polygon do you mean by "pentagram"? can you give a clear counterexample? $\endgroup$ – mjqxxxx Jun 15 '12 at 1:42
  • $\begingroup$ @mjqxxxx - I apologize, you are correct. $\endgroup$ – nbubis Jun 15 '12 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.