# Perform intersection between a ray and a triangle

This topic is 2781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Here is another problem that has showed up in short time. I am trying to find where a rline is intersecting a triangle side that is a part of the 3D prism in XNA that I have mentioned about in previous threads. I am using this algorithm which I found in a blog, since the previous intersecting algorithm I used before might not worked correctly:

http://dzindzinovic.blogspot.com/2010/05/xna-ray-intersect-triangle.html

This is how I use the RayIntersectTriangle-function during the update call:

curr3DPos += 0.005f * line3DDir;
pointPreList.SetValue(new VertexPositionColor(line3DStartPos + curr3DPos, Color.Brown), 0);
pointPreList.SetValue(new VertexPositionColor(line3DEndPos + curr3DPos, Color.Brown), 1);

if (RayIntersectTriangle(line3DEndPos + curr3DPos, line3DDir, prismData[0].Position,
prismData[1].Position, prismData[2].Position, ref pickDistance,
ref barycentricU, ref barycentricV))
{
Console.WriteLine("Intersected");
}

where line3DEndPos + curr3DPos is the current end position of the line, line3DDir is the ray direction and prismData[0,1,2].Position are the positions of the triangle sides vertices. The problem is that it won´t detect the intersection when the end of the line is hitting the triangle.

• 16
• 11
• 11
• 9
• 49
• ### Forum Statistics

• Total Topics
631394
• Total Posts
2999749
×