UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
GeomUtils.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
7#include "Math/Vector.h"
8#include "Math/Vector2D.h"
9
10namespace UE::AI
11{
13 inline FVector::FReal Cross2D(const FVector& A, const FVector& B)
14 {
15 return A.X * B.Y - A.Y * B.X;
16 }
17
20 {
21 return A.X * B.Y - A.Y * B.X;
22 }
23
25 inline FVector::FReal TriArea2D(const FVector& A, const FVector& B, const FVector& C)
26 {
27 const FVector AB = B - A;
28 const FVector AC = C - A;
29 return (AC.X * AB.Y - AB.X * AC.Y) * 0.5;
30 }
31
33 inline FVector2D::FReal TriArea2D(const FVector2D& A, const FVector2D& B, const FVector2D& C)
34 {
35 const FVector2D AB = B - A;
36 const FVector2D AC = C - A;
37 return (AC.X * AB.Y - AB.X * AC.Y) * 0.5;
38 }
39
42 {
43 using FReal = FVector::FReal;
44
45 const FVector2D Seg(End - Start);
46 const FVector2D Dir(Point - Start);
47 const FReal D = Seg.SquaredLength();
48 const FReal T = FVector2D::DotProduct(Seg, Dir);
49
50 if (T < 0.0)
51 {
52 return 0.0;
53 }
54 else if (T > D)
55 {
56 return 1.0;
57 }
58
59 return D > UE_KINDA_SMALL_NUMBER ? (T / D) : 0.0;
60 }
61
64 {
65 using FReal = FVector::FReal;
66
67 const FVector2D Seg(End - Start);
68 const FVector2D Dir(Point - Start);
69 const FReal D = Seg.SquaredLength();
70 const FReal T = FVector2D::DotProduct(Seg, Dir);
71 return D > UE_KINDA_SMALL_NUMBER ? (T / D) : 0.0;
72 }
73
76 {
77 using FReal = FVector::FReal;
78
79 const FVector2D Seg(End - Start);
80 const FVector2D Dir(Point - Start);
81 const FReal Nom = Cross2D(Seg, Dir);
82 const FReal Den = Seg.SquaredLength();
83 const FReal Dist = Den > UE_KINDA_SMALL_NUMBER ? (Nom / FMath::Sqrt(Den)) : 0.0;
84 return Dist;
85 }
86
98 {
99 using FReal = FVector::FReal;
100
101 const FVector U = EndA - StartA;
102 const FVector V = EndB - StartB;
103 const FVector W = StartA - StartB;
104
105 const FReal D = Cross2D(U, V);
106 if (FMath::Abs(D) < UE_KINDA_SMALL_NUMBER)
107 {
108 OutTA = 0.0;
109 OutTB = 0.0;
110 return false;
111 }
112
113 OutTA = Cross2D(V, W) / D;
114 OutTB = Cross2D(U, W) / D;
115
116 return true;
117 }
118
132
143 {
144 const FVector AB = FMath::Lerp(VertexA, VertexB, UV.X);
145 const FVector CD = FMath::Lerp(VertexD, VertexC, UV.X);
146 return FMath::Lerp(AB, CD, UV.Y);
147 }
148
159
174
175}; // UE::AI
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UE_KINDA_SMALL_NUMBER
Definition UnrealMathUtility.h:131
Definition AIHelpers.cpp:82
bool IntersectSegmentPoly2D(const FVector &Start, const FVector &End, TConstArrayView< FVector > Poly, FVector2D::FReal &OutTMin, FVector2D::FReal &OutTMax, int32 &OutSegMin, int32 &OutSegMax)
Definition GeomUtils.cpp:8
FVector2D InvBilinear2D(const FVector Point, const FVector VertexA, const FVector VertexB, const FVector VertexC, const FVector VertexD)
Definition GeomUtils.cpp:80
FVector2D InvBilinear2DClamped(const FVector Point, const FVector VertexA, const FVector VertexB, const FVector VertexC, const FVector VertexD)
Definition GeomUtils.h:170
FVector::FReal Cross2D(const FVector &A, const FVector &B)
Definition GeomUtils.h:13
FVector::FReal SignedDistancePointLine2D(const FVector Point, const FVector Start, const FVector End)
Definition GeomUtils.h:75
FVector::FReal ProjectPointOnLine2D(const FVector Point, const FVector Start, const FVector End)
Definition GeomUtils.h:63
FVector2D::FReal ProjectPointOnSegment2D(const FVector Point, const FVector Start, const FVector End)
Definition GeomUtils.h:41
FVector::FReal TriArea2D(const FVector &A, const FVector &B, const FVector &C)
Definition GeomUtils.h:25
bool IntersectLineLine2D(const FVector &StartA, const FVector &EndA, const FVector &StartB, const FVector &EndB, FVector2D::FReal &OutTA, FVector2D::FReal &OutTB)
Definition GeomUtils.h:97
static constexpr UE_FORCEINLINE_HINT T Lerp(const T &A, const T &B, const U &Alpha)
Definition UnrealMathUtility.h:1116
static UE_FORCEINLINE_HINT double DotProduct(const TVector2< double > &A, const TVector2< double > &B)
Definition Vector2D.h:929
T FReal
Definition Vector2D.h:42
T Y
Definition Vector2D.h:52
TVector2< T > ClampAxes(T MinAxisVal, T MaxAxisVal) const
Definition Vector2D.h:1249
T X
Definition Vector2D.h:49
T Y
Definition Vector.h:65
double FReal
Definition Vector.h:55
T X
Definition Vector.h:62