Using Barycentric coordinates to check whether a point lies within a Degenerate triangle

938 Views Asked by At

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.

1

There are 1 best solutions below

1
On BEST ANSWER

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:

  1. Let $M$ be the maximum of distances $|AB|$, $|BC|$, $|AC|$. Also note a pair of points realizing this maximum.
  2. Let $S$ the sum of distances from given point $P$ to the two points noted at step 1.
  3. If $M\ge S$, the point $P$ is within the degenerate triangle; otherwise it is not.