I was trying this question and found a solution :
Draw a horizontal line to the right of each point and extend it to infinity
1) Count the number of times the line intersects with polygon edges.
2) A point is inside the polygon if either count of intersections is odd or point lies on an edge of polygon. If none of the conditions is true, then point lies outside.
But i think there is a simple solution to this :
for(all sides in same order)
find vector product of the 3 points (given point and end points of each side)
if all products are > or < 0 : point lies inside polygon or on boundary
else outside
isn't my solution better and efficient ?
is there another simpler algorithm than this ?
independent
of concavity or convexity . we just have to see thesign
of cross product . The important thing is to move in same direction (clockwise or counter-clockwise). – Aseem Goyal(x2 - x1)*(y3 - y1)-(y2 - y1)*(x3 - x1)
– Aseem Goyal