How to check if a polygon is completely inside another polygon

Checking if a polygon is completely inside another polygon is a very common problem in geometry, and most solutions you can find in the web aren’t that easy, especially when you are dealing with irregular polygons.

Today I want to show you a quick solution based on the PolygonClipper AS3 class.

Basically we can say a polygon called A is completely inside another polygon called B when the intersection between these two polygons returns the same polygon A.

So, mixing the concepts seen in understanding polygon clipping and introducing PolygonClipper AS3 class and AS3 code snippet: draw a star and determine its area I was able to do this prototype in a few minutes:

Use the mouse to move the small star and watch what happens when it’s inside the big star.

This is the commented source code:

Checking if a polygon is inside another polygon is the last theoretical step before creating real physics destructible terrain, so download the source code and wait for the final prototype.

• Carlos Ribeiro

Great Work Feronato!

• Hi Emmanuel
It was wonderful as always.
Thank you

• Great!, inspiring me since primary school :)

• MC

To create the destructible terrain from this,
I suppose the blue zone is the terrain, the small star is the explosion range, and the green (intersected) will be the zone to remove, but since box2d can’t remove zones like that, you created a new box2d polygon with the intersected vertex from the green zone and the blue zone, am i right?

• Emmanuele, thanx for sharing! Good job, it helped me.

• Hi, [getArea] function is works wrong with the shape http://my.jetscreenshot.com/3084/20130829-oopy-4kb, in my tests getArea() = 0 in this case :(

• Emanuele Feronato

It should be a perfect polygon, that is a polygon with no intersecting vertices