Rendering a triangle in 3D

Dear All,

Generally this forum have persons with great expertise.

See the following link in Section " Intersection of a Ray/Segment with a Triangle"

I am having problems putting work the rendering of a triangle with the algorithm written (with similar code to the one provided at the end). I test the points of a cuboid (that includes the triangle) if are from the triangle. Testing that s>=0, t >=0, s+t <= 1 for all points of the cuboid.

Then I think I understood that:

u=V1-V0 must be unitary
v=V2-V0 must be unitary
Not certain
u and v must be normal (???)

How can be generalized the algorithm for general size of u and v? And not normal? (???)


Luís Gonçalves

The two vectors don’t have to be unitary or normal. It’s a general algorithm, and a very nice one. But really, this is not a VTK question.

Thanks for the reply. Then I have to see what is happening.

Solved. The algorithm not works alone. Must be tested before if the point is in the plane of the three vertices. And then apply the algorithm to those points that are in the plane.

The algorithm is designed to project a ray onto the triangle. If you add a check that the point is already in the plane, then you can simplify it by removing the “projection” part, which is the first half of the algorithm.

Yes, my error was that at first I omitted the first part of the algorithm (I now saw better the code in the bottom of the page. At first I only saw the text). I only computed u,v,s,t and tested.
But I found this solution. As I test all the points of a cuboid, I find only one plane for the triangle and test if the points are in the plane is faster than the original algorithm.