Posts Tagged ‘convex’
Making Convex Polygons from Concave Ones: Ear Clipping
Thursday, June 19th, 2008We’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.
Then I stumbled upon a great post on the Box2D forums “Concave Polygon Decomposition in Flash“. Someone had converted an Ear Clipping example in Processsing to a JSFL tool. Sweet!
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.
Have fun!
Tags: AS3, concave, convex, physics, polygons
Posted in Flash | 7 Comments »