• Advertisement


This topic is now archived and is closed to further replies.

Line - Triangle Intersection Tests

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''ve been working on a lightmap generator for my game engine, and I need to ray-trace from a light to a pixel to detect any shadows... So I have a line, in 3D, defined by O[X,Y,Z] and P[X,Y,Z] and a list of triangles defined by their vertices P[0-2] I''ve been trying to use the fairly standard equation as shown in the "Game Programming Gems 1" collision detection gem: aX+bY+cZ+d=0 a=Normal.x b=Normal.y c=Normal.z d=-DotProduct(Normal,Vertex[0]) t=-(A*P.X + B*P.Y + C*P.Z + D) / (A*(O.X-P.X) + B*(O.Y-P.Y) + C*(O.Z-P.Z)) point of intersection = O + t(P-O) BUT, I seem to be getting some rather wacky results - the point of intersection comes out as being a point not on the triangle, and not on the plane - fairly randomly along the line instead... CAN someone check the above formulae, and/or point me to some tutorial/article that covers an alternative? Many thanks in advance Jack;

Share this post

Link to post
Share on other sites
the formula is correct...
try this

px0 is the first point of the vector
s is the direction of the vector
Po,P1,P2 the point of the triangle and R is a vector holding the result

void RayPlaneIntr( fVect Px0,fVect S,
fVect P0 ,
fVect P1,
fVect P2,
fVect R )

fVect N,N1;
qVect Q;
float t,d;
Q[0]= N[1]*N1[2]-N1[1]*N[2];
Q[1]= N[2]*N1[0]- N[0]*N1[2];
Q[2]=N1[1]*N[0] - N[1]*N1[0];
if ( d==0 ) d+=(float)EPSILON;

Share this post

Link to post
Share on other sites
Thanks for that - I shall have a good look at it later.

However, what is "EPSILON" - I assume it''s a mathematical constant of some kind; but what? sorry if it''s a stupid question, but just wanted to check =)


Share this post

Link to post
Share on other sites
Ah yes, EPSILON is a very small number sort of 0.0000001

Share this post

Link to post
Share on other sites

  • Advertisement