2D Polygon-ray intersections
Equation of the line through the edge connecting vertices vi and vi+1:
If the quantity on the right-hand side is positive, then the point (x,y) is to the right of the edge, assuming we are looking from vi to vi+1.
Algorithm: if for each edge the quantity above is nonnegative for x = qx, y = qy then the point q is in the polygon. Otherwise, it is not.
In the formulas x and y should be replaced by x and z if y coord. was dropped, or by y and z if x was dropped.