Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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|cite|improve this question
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|cite|improve this answer
I will try this. Thanks. – user960567 Jun 13 '12 at 15:59

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|cite|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

Your Answer


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.