Triangulating a Polygon

BlitzMax Forums/BlitzMax Programming/Triangulating a Polygon

Armitage 1982(Posted 2011) [#1]
Hi

I like to attract your attention on a code archived by Warpy and improved by ima747 at this location : http://blitzbasic.com/codearcs/codearcs.php?code=2259

As stated in topic, it's a Polygon triangulation by Substracting ears algorithm.

Unfortunately there is an issue in that version when you try to draw such polygon forms:



This is due to the triangulation algorithm itself.
Nothing to do with the last triangle (since you can reproduce this issue anywhere in the polygon).

The default DrawPoly function from Max2D does not draw concave polygons.

I know there is a tessellation algorithm in OpenGL GLU. The is also a lot of other Algorithm like Seidel or Delaunay...

Here is a working demo of Warpy improved by ima747 code:


And today, I take a moment to port the John W. Ratcliff Flipcode archive to BlitzMax (http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml) :

I include a fake 2D Vector Class named b2Vec2 because I'm using this one in my games. It comes from the Box2D Module ported by Brucey and developed by Erin Catto at http://box2d.org/


Feel free to use this alternative code in whatever you want (I did not thoroughly test it and there is other issues than the one from Warpy and ima747).
I know you can improve this algorithm in many ways (for example with a better counter-clockwise detection, with a Delaunay polygon reduction or by considering polygon holes)

And if you can, I would love to see that :)
That's why I do not put it right now to the code archive forum.

Also:
This function is mainly used in my Draw Textured Polygon function.
Like many, I'm using the Odd2D.mod from David and there is a very nice DrawImagePoly() function for doing that.
Unfortunately, like the DrawPoly function of Max2D it's only working with convex polygon.
I'm wondering if we couldn't add an advancedDrawImagePoly() that would support every platforms out of the box so this function would exist once and for all.

Thanks for reading me :)


Armitage 1982(Posted 2011) [#2]
I also discover this open source alternative called poly2tri:

http://code.google.com/p/poly2tri/




Looking nice and exist for several languages.
I try the C++ version in BlitzMax and everything build so it's probably possible to get a module out of it (never did that before).


Hotshot2005(Posted 2011) [#3]
So Cool!

You must be Math Wizard!!! :)

Last edited 2011