Making Convex Polygons from Concave Ones: Ear Clipping
We’ve recently been playing around with a physics engines in Flash, including a little romance with Glaze, a slight flirting with PhysaXe and now seeming to settle for Box2D … (the dependable old dog)
All these engines work only with convex polygons, and in no way support concave polygons. They do however support more than one shape (or polygon) in each of their rigid bodies. This gives us the change to fake concave shapes by making multiple convex ones. But how do we convert from concave to convex?
I did a bit of a search around and heard about such things as Ear Clipping and Minimum Convex Decomposition. The second I could even find code for (http://www.cs.ubc.ca/spider/snoeyink/demos/convdecomp/MCDDemo.html) which was awesome, and in Java none the less. But alas, even with the help of this awesome Java to AS3 converter, I failed at getting it to work.
So between the two example I managed to cobble together some not too shabby AS3 classes, and an example app. I’m hoping to add this to our Box2D wrapper (more on that later) so we can easily draw concave polygons ASAP.
This entry was posted on Thursday, June 19th, 2008 at 2:02 am and is filed under Flash. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
February 25th, 2009 at 3:52 am
[...] was already a nice port here : http://blog.touchmypixel.com/archives/17 unfortunately, first I found it too late, second I was not clever enough to understand clearly what [...]
February 27th, 2009 at 1:57 am
[...] évidemment, il y a déja des gens qui l’ont porté:http://blog.touchmypixel.com/archives/17 mais je suis juste trop con et j’ai pas compris. donc j’ai repris à la base en [...]
October 25th, 2009 at 12:59 am
[...] som digging I found this post at Touch My Pixel’s blog, featuring a few awsome AS3 classes for doing this trick. After [...]