This is a webpage to test if a point is inside of a polygon or not using triangle fan method.
I thought I was the first one to find it, since not a lot of people know it. It turns out that this is discovered earlyer and named "triangle fan method".
operation
Left click on the screen to draw a polygon, just like drawing one in mspaint.exe.
Right click to remove the closest point.
Move you mouse to judge the point of your cursor is inside of the polygon or not. If it is inside, the text in the upper left corner will become red. Otherwise it will be green. The triangles for judging will be drawn as blue frames.
algorithm
summary
Suppose we want to judge if a point A is inside of a polygon p0,p1,p2 .. pn, randomly select a point pi from the polygon. Then, find all line segments that does not include pi. Construct triangles for each line segment with pi. Then count how many triangles A is inside of. If the count is even, then A is outside of the polygon. If the count is odd, A is inside of the polygon.
my video illustration
extension
I believe this method works for higher dimension. (Still, I cannot prove it) For example in 3D, you want to judge if point A is inside of a polyhedron made from triangle faces. You then choose a point pi on the polyhedron, and iterate all other triangle faces which does not include pi, and count how many tetrahedrons made by these face and pi contains point A. If the number is odd then the point is inside of the 3D shape.
If you goes to 4D, then choose point pi and iterate all tetrahedron, then construct "5-cell" for each tetrahedron with pi, then count how many "5-cell"s does A belong to.