Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

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.

share|improve this answer
    
I will try this. Thanks. –  user960567 Jun 13 '12 at 15:59
add comment

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.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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