How to check if a polygon is completely inside another polygon

Emanuele Feronato Actionscript 3, Flash

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.

From null to full HTML5 cross platform game

I will take you by hand from the bare bones of JavaScript programming through the creation of a full cross platform HTML5 game, with detailed explainations and source code.

If you don't know where to start, then From null to full HTML5 cross platform game is the book for you.

Comments 7

  1. 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?

    1. Post

Leave a Reply

Your email address will not be published. Required fields are marked *