Menu:

¯
RSS  RSS 2.0

Polygon2D

Go get flash player

Polygon2D is a class I wrote to disprove a myth that hit-testing or tesselating concave polygons is something difficult to program. On the right, you can see this class in action. Sources, grab it here.

So, how does it work? Well, for hit-testing one should note that a line segment connecting any point inside the polygon with any other point outside of it has to cross polygon perimeter somewhere at least once or, generally, odd number of times. So, what you do is cast a ray out and count intersections.

For tesselation, I simply walk through vertices, separating every one, that edges it is in form a triangle, that does not intersect polygon edges and does not contain polygon vertices. Simple, huh? As you can see, this is simple, but nowhere near fast or optimal. If you want that, maybe read through this 600K tesselator, and write one yourself :)