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


Line and Triangle Intersection

Recommended Posts

AyaKoshigaya    122
Hi, does anyone know how I can find out if a Line interects a Triangle??? I''ve found the code on, and it worked very well, but it''s very very slow... so, does anyone know how I can test if a Triangle and Line intersection can be, before I use the slow method to find it out exactly??? I''ve thougt on something like using BoundingBoxes or something.. any idea? Au''revoir, Aya~

Share this post

Link to post
Share on other sites
Sunray    188

bool NPhysics::LineFaceIntersectionTest(const NMath::Vector3f &_rLineStartPoint,const NMath::Vector3f &_rLineEndPoint,const NMath::Vector3f _aVertices[],const NMath::Vector3f &_rNormal)
float OriginDistance = -NMath::DotProduct(_aVertices[0],_rNormal);

if ((NMath::DotProduct(_rNormal,_rLineStartPoint) + OriginDistance) * (NMath::DotProduct(_rNormal,_rLineEndPoint) + OriginDistance) >= 0)
return false;

NMath::Vector3f Point;
NMath::Vector3f LineDirection = _rLineEndPoint - _rLineStartPoint;


float Numerator = -NMath::DotProduct(_rNormal,_rLineStartPoint) - OriginDistance;
float Denominator = NMath::DotProduct(_rNormal,LineDirection);

Denominator == 0.0f ? Point = _rLineStartPoint : Point = _rLineStartPoint + LineDirection * (Numerator / Denominator);

if (!PointInsideTriangle(Point,_aVertices))
return false;

return true;

Heh, thats mine.. based on the one found at =(

Share this post

Link to post
Share on other sites