RealDocs

FMath::SegmentIntersection2D

function Core Since 4.0
#include "Math/UnrealMathUtility.h"
Access: public Specifiers: static

Description

Tests whether two 3D segments intersect when projected onto the XY plane and returns the intersection point. Ignores the Z component for the intersection test itself.

Caveats & Gotchas

  • The intersection test is performed in 2D (XY plane only). Two segments that miss each other in XY will return false even if they cross in 3D space. Verify this matches your use case.
  • The Z value of out_IntersectionPoint is computed by linearly interpolating along segment A at the parametric intersection T — it does not represent a 3D intersection height.
  • Parallel or collinear segments always return false regardless of overlap.

Signature

static CORE_API bool SegmentIntersection2D(const FVector& SegmentStartA, const FVector& SegmentEndA, const FVector& SegmentStartB, const FVector& SegmentEndB, FVector& out_IntersectionPoint)

Parameters

Name Type Description Default
SegmentStartA const FVector& Start of the first segment.
SegmentEndA const FVector& End of the first segment.
SegmentStartB const FVector& Start of the second segment.
SegmentEndB const FVector& End of the second segment.
out_IntersectionPoint FVector& Receives the 2D intersection point (Z will be interpolated) if the function returns true.

Return Type

bool

Example

Detect crossing of two navmesh boundary edges on the ground plane C++
FVector CrossPt;
if (FMath::SegmentIntersection2D(EdgeA_Start, EdgeA_End, EdgeB_Start, EdgeB_End, CrossPt))
{
    // CrossPt.XY is the intersection on the ground plane
    DrawDebugPoint(GetWorld(), CrossPt, 8.f, FColor::Red);
}

Tags

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.