Build 10 games and learn game development along the way in this fast paced game development course

Get the source code of 12 commercial games, loaded 50+ million times, and learn the secrets of game design

Learn how to make a successful Flash game from a real world example. Fully commented source code

Create realistic Flash physics games from scratch with advanced features, from Angry Birds to Crush the Castle

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.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 5.00 out of 5)
Loading ... Loading ...
Learn how to make a successful commercial Flash game from a real world example: get the fully commented source code of Globez, a Flash game played millions of times which generated a four figure income. Limited copies available.

Get it now
Be my fan on Facebook and follow me on Twitter! Exclusive content for my Facebook fans and Twitter followers

This post has 7 comments

  1. Carlos Ribeiro

    on July 3, 2013 at 8:17 pm

    Great Work Feronato!

  2. Rahyar

    on July 6, 2013 at 5:02 pm

    Hi Emmanuel
    It was wonderful as always.
    Thank you

  3. Jeff Ibacache

    on July 9, 2013 at 11:50 pm

    Great!, inspiring me since primary school :)

  4. MC

    on July 14, 2013 at 3:10 am

    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?

  5. fmaxx

    on August 28, 2013 at 7:43 pm

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

  6. fmaxx

    on August 29, 2013 at 3:12 pm

    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 :(

  7. Emanuele Feronato

    on August 30, 2013 at 4:34 pm

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

Thank you for the download!!

I hope you will find it useful and make something interesting out of it

To keep up to date with the blog, why don't you like my Facebook page and follow me on Twitter?

Want to learn more? Don't miss this:

Learn how to make a successful commercial Flash game from a real world example: get the fully commented source code of Globez, a Flash game played millions of times which generated a four figure income. Limited copies available.

Get it now

×