Here is the most known method to test if point is inside polygon.
p polygon
n number of vertices in polygon
q point
RightHorizontalRayIntersection(q,u,v) tests if horizontal ray starting from point q (in right direction) intersects a segment (u,v).
Code:
bool IsPointInsidePolygon( P *p,int n,P q ) {
int i,j,c=0;
for (i=0,j=n-1; i<n; j=i++) // Considering all segments (p[i],p[j])
if (RightHorizontalRayIntersection( q,p[i],p[j] )) c++;
return c%2;
}
There is a special cases, ray r intersects a segment in one of it.
Sample:
http://blog.csdn.net/xqls_xqls/archive/2009/07/30/4393369.aspx