http://www.blackpawn.com/texts/pointinpoly/
I used this site to learn how to determine whether a point lies within a triangle. However, the site does not say whether or not this method can handle degenerate triangles (triangles where each vertex is co-linear).
The results I get are u,v and w being equal to 0, which would say to me that this method can't handle degenerate triangles.
Does anyone know if it can? Perhaps my implementation or calculations are wrong.
Yes, both methods fail on degenerate triangles. The first one will always say "yes" because one of two cross products is zero, making dot product zero. The second method will throw an exception (division by zero) in the computation of
invDenom.But you can attach a special case for degenerate triangles. Given a triangle $ABC$, compute the cross product $AB\times AC$; if it's nonzero, the triangle is nondegenerate and you deal with it in the usual way. If it's zero, do the following: