Corona SDK Tutorial: Polygon point reduction with curve-fitting

Posted by

Using a variant of the Douglas-Peucker algorithm in conjunction with the curve-fitting algorithm by Philip J. Schneider found in Graphics Gems I, Carlos wrote this in Corona SDK using nothing but the Corona framework to draw, reduce points, and convert the resulting polyline into a series of cubic bezier curve segments.

Sample code coming soon! (you can bug Carlos if you want it immediately, though)

Ready to get started?

Create amazing games and apps for iOS & Android

7 Comments

MagendaDecember 30th, 2010 at 5:31 am

Very nice results, Carlos!
Thanks for this helper function!

Please publish a companion example too, about how we can use such curves to drive the transition of an object along a path. Thanks in advance!

BobDecember 30th, 2010 at 6:59 am

Wow just the line stuff on it’s own is cool and when you add that your doing this on a mobile device with a easy to use API it’s just sweet! Thanks for sharing now get the code out there for us!:)

salim madjdDecember 30th, 2010 at 10:34 am

Great stuff, carlos! Can’t wait to see the sample codes, etc.

Carlos IcazaDecember 30th, 2010 at 3:47 pm

need to clean up the code a bit and above all comment the part that really matters. all the other routines, the reparametization, newtonrapsody leas squares, etc. don’t really need to be documented, but the part where you pass in the points, and the err tolerance has to be neatly documented and I also need a way to pass back an array of handles. which right now works, but is not intuitive. the idea would be you pass in an array of points, and it will return you an array (or in lua lingo a table) with the points to the Bezier Curve. after that, you can do what ever you would like with the points. Draw them, or use them to ‘walk’ an object along the t values. I am also looking at implementing at reparametirizing the resulting segment…

Carlos IcazaJanuary 1st, 2011 at 6:18 pm

On an actual device http://developer.anscamobile.com/assets/curvefitting.mp4

Rodney FoleyMarch 13th, 2011 at 2:04 pm

@Carlos, what is the status of posting this sample code? It has been two and half months, it doesn’t have to be perfect it just needs to work. :)

Carlos IcazaMarch 13th, 2011 at 11:35 pm

@Foley

Point reduction is at
http://developer.anscamobile.com/code/point-reduction-code-0

Curvefitting is being added as part of the framework. That’s why it is taken longer. The C++ code shows a discernible performance increase.

Leave a comment

Your comment