Given a 2D array in which there is a polygon represented by '*' that touches all the edges, what is the best way to determine whether a point is inside the polygon or not? The coordinates of each vertex are given, but the algorithm should be able to handle any shape/size.
I've tried implementing the ray casting algorithm, but I'm having trouble dealing with cases where the ray would go through the tip of a vertex, or along a horizontal edge as pictured:
o-*------->
* *
* o-****->
* *
*********
Right now, I'm just counting the amount of stars that are intersected, but both of these cases would give the incorrect result (odd intersections being inside and even being outside).
Is there a way to make this work? Or is there a much more efficient solution that I'm not thinking of?