graphicslinear-algebraintersectionraytracing

Determine if point is inside triangle in 3D


I am looking for acknowledgement on my perception of a method regarding determining whether a point is located inside a triangle or not in 3D.

Given a ray in the form R(t) = e + td and a set of three points T = {V0, V1, V2} that forms a triangle in three dimensions, I know how to find the parametic equation for the plane that the three points form and how to determine if the ray intersects this plane or not. Lastly, if it intersects, I want to know if the intersection point actually is within the bounds of the triangles edges.

Please see my picture below.

enter image description here

What I am thinking is that I can calculate the dot product between each edge vector and the vector that goes from the first edge in the edge vector towards the point and check if they are all positive. Like this:

enter image description here

If that is the case, the point should be inside the triangle. Right? Isn't this kind of the same method used for determining backfaces in computer graphics?


Solution

  • In graphics, people usually use barycentric coordinates. In your case, P can be described as P = aV0 + bV1 + cV2, where a + b + c = 1 . P is inside if and only if 0 <= a, b, c <= 1.

    If the triangles formed by v1, P, v2 has the area S1, the triangle formed by P, v0, v2 has the area of S2, and P, V0, V1 has the area of S3. Then a = S1/S, b = S2/S and c = S3/S, where S is the area of triangle V0, V1, V2.

    To find the area of S = 1/2||(V0-V1)creosspdoruct(V0-V2)||.

    You can check out the tutorial that I put on my website.