#### Archived

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

# Line and Triangle Intersection

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

## Recommended Posts

Hi, does anyone know how I can find out if a Line interects a Triangle??? I''ve found the code on Gametutorials.com, 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 on other sites
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;	LineDirection.Normalize();	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 gametutorials.com =(

##### Share on other sites
You could try this

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 103
• 11
• ### Forum Statistics

• Total Topics
632976
• Total Posts
3009672
• ### Who's Online (See full list)

There are no registered users currently online

×