FMath::SegmentTriangleIntersection
#include "Math/UnrealMathUtility.h"
Access: public
Specifiers: static
Description
Tests whether a line segment intersects a triangle and returns both the intersection point and the triangle's face normal. Returns false if the segment misses or is parallel to the triangle.
Caveats & Gotchas
- • The test is one-sided — the segment must approach from the front face (defined by counter-clockwise winding of A, B, C). A segment hitting the back face returns false. Reverse the winding or reverse the segment if you need back-face intersection.
- • OutIntersectPoint and OutTriangleNormal are only valid on a true return.
- • This is an exact geometric test, not a physics-engine query. For general mesh intersection queries use UWorld::LineTraceSingleByChannel instead — it leverages acceleration structures.
Signature
static CORE_API bool SegmentTriangleIntersection(const FVector& StartPoint, const FVector& EndPoint, const FVector& A, const FVector& B, const FVector& C, FVector& OutIntersectPoint, FVector& OutTriangleNormal) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| StartPoint | const FVector& | Start of the segment. | — |
| EndPoint | const FVector& | End of the segment. | — |
| A | const FVector& | First vertex of the triangle. | — |
| B | const FVector& | Second vertex of the triangle. | — |
| C | const FVector& | Third vertex of the triangle. | — |
| OutIntersectPoint | FVector& | Receives the intersection point on the triangle if the function returns true. | — |
| OutTriangleNormal | FVector& | Receives the triangle's face normal if the function returns true. | — |
Return Type
bool Example
Test a custom ray against a manually-specified triangle C++
FVector HitPoint, HitNormal;
if (FMath::SegmentTriangleIntersection(
RayStart, RayEnd,
TriVerts[0], TriVerts[1], TriVerts[2],
HitPoint, HitNormal))
{
UE_LOG(LogTemp, Log, TEXT("Hit at %s, normal %s"),
*HitPoint.ToString(), *HitNormal.ToString());
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?