UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
IntrLine2Line2.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3// Port of geometry3Sharp IntrLine2Line2
4
5#pragma once
6
7#include "VectorTypes.h"
8#include "LineTypes.h"
9#include "VectorUtil.h" // for EIntersectionType
10
11namespace UE
12{
13namespace Geometry
14{
15
16using namespace UE::Math;
17
21template<typename RealType>
23{
24protected:
25 // input data
30
31public:
32 // result data
36 int Quantity = 0;
39
40
41
46
47
49 {
50 return Line1;
51 }
52
58
60 {
61 return Line2;
62 }
63
69
70
71 RealType GetDotThreshold() const
72 {
73 return dotThresh;
74 }
75
76 RealType GetDistThreshold() const
77 {
78 return DistThresh;
79 }
80
81 void SetDotThreshold(RealType Value)
82 {
83 dotThresh = FMath::Max(Value, (RealType)0);
85 }
86
87 void SetDistThreshold(RealType Value)
88 {
89 DistThresh = FMath::Max(Value, (RealType)0);
91 }
92
93
98
99
101 {
102 Find();
103 return *this;
104 }
105
106
107 bool Find()
108 {
110 {
112 }
113
114 // if either line direction is not a normalized vector,
115 // results are garbage, so fail query
116 if (IsNormalized(Line1.Direction) == false || IsNormalized(Line2.Direction) == false)
117 {
120 return false;
121 }
122
126
128 {
129 Quantity = 1;
133 }
134 else if (Type == EIntersectionType::Line)
135 {
137 }
138 else
139 {
140 Quantity = 0;
141 }
142
146 }
147
148
149
151 const TVector2<RealType>& P0, const TVector2<RealType>& D0,
152 const TVector2<RealType>& P1, const TVector2<RealType>& D1,
153 RealType DotThreshold, RealType DistThreshold, TVector2<RealType>& s)
154 {
155 // Ensure DotThreshold is nonnegative.
156 DotThreshold = FMath::Max(DotThreshold, (RealType)0);
157
158 // The intersection of two lines is a solution to P0+s0*D0 = P1+s1*D1.
159 // Rewrite this as s0*D0 - s1*D1 = P1 - P0 = Q. If D0.Dot(Perp(D1)) = 0,
160 // the lines are parallel. Additionally, if Q.Dot(Perp(D1)) = 0, the
161 // lines are the same. If D0.Dot(Perp(D1)) is not zero, then
162 // s0 = Q.Dot(Perp(D1))/D0.Dot(Perp(D1))
163 // produces the point of intersection. Also,
164 // s1 = Q.Dot(Perp(D0))/D0.Dot(Perp(D1))
165
166 TVector2<RealType> diff = P1 - P0;
167 RealType D0DotPerpD1 = DotPerp(D0, D1);
168 if (FMath::Abs(D0DotPerpD1) > DotThreshold)
169 {
170 // Lines intersect in a single point.
171 RealType invD0DotPerpD1 = 1.0 / D0DotPerpD1;
172 RealType diffDotPerpD0 = DotPerp(diff, D0);
173 RealType diffDotPerpD1 = DotPerp(diff, D1);
177 }
178
179 // Lines are parallel; check if they are within DistThresh apart
180 RealType diffNDotPerpD1 = DotPerp(diff, D1);
181 if (FMath::Abs(diffNDotPerpD1) <= DistThreshold)
182 {
183 // Lines are collinear.
185 }
186
187 // Lines are parallel, but distinct.
189 }
190
191};
192
195
196} // end namespace UE::Geometry
197} // end namespace UE
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
EIntersectionResult
Definition VectorUtil.h:10
EIntersectionType
Definition VectorUtil.h:18
Definition MathUtil.h:150
Definition IntrLine2Line2.h:23
void SetDotThreshold(RealType Value)
Definition IntrLine2Line2.h:81
void SetLine2(TLine2< RealType > &Value)
Definition IntrLine2Line2.h:64
RealType Segment2Parameter
Definition IntrLine2Line2.h:35
TIntrLine2Line2(const TLine2< RealType > &Line1In, const TLine2< RealType > &Line2In)
Definition IntrLine2Line2.h:42
RealType GetDotThreshold() const
Definition IntrLine2Line2.h:71
EIntersectionType Type
Definition IntrLine2Line2.h:38
const TLine2< RealType > & GetLine1() const
Definition IntrLine2Line2.h:48
TIntrLine2Line2 & Compute()
Definition IntrLine2Line2.h:100
RealType GetDistThreshold() const
Definition IntrLine2Line2.h:76
const TLine2< RealType > & GetLine2() const
Definition IntrLine2Line2.h:59
bool Find()
Definition IntrLine2Line2.h:107
int Quantity
Definition IntrLine2Line2.h:36
RealType dotThresh
Definition IntrLine2Line2.h:28
RealType Segment1Parameter
Definition IntrLine2Line2.h:34
TLine2< RealType > Line2
Definition IntrLine2Line2.h:27
RealType DistThresh
Definition IntrLine2Line2.h:29
static EIntersectionType Classify(const TVector2< RealType > &P0, const TVector2< RealType > &D0, const TVector2< RealType > &P1, const TVector2< RealType > &D1, RealType DotThreshold, RealType DistThreshold, TVector2< RealType > &s)
Definition IntrLine2Line2.h:150
void SetDistThreshold(RealType Value)
Definition IntrLine2Line2.h:87
TVector2< RealType > Point
Definition IntrLine2Line2.h:33
EIntersectionResult Result
Definition IntrLine2Line2.h:37
void SetLine1(const TLine2< RealType > &Value)
Definition IntrLine2Line2.h:53
bool IsSimpleIntersection() const
Definition IntrLine2Line2.h:94
TLine2< RealType > Line1
Definition IntrLine2Line2.h:26
TIntrLine2Line2< float > FIntrLine2Line2f
Definition IntrLine2Line2.h:194
constexpr T DotPerp(const UE::Math::TVector2< T > &V1, const UE::Math::TVector2< T > &V2)
Definition VectorTypes.h:19
TIntrLine2Line2< double > FIntrLine2Line2d
Definition IntrLine2Line2.h:193
constexpr bool IsNormalized(const UE::Math::TVector2< T > &Vector, const T Tolerance=TMathUtil< T >::ZeroTolerance)
Definition VectorTypes.h:40
Definition Sphere.cpp:10
Definition AdvancedWidgetsModule.cpp:13
Definition NumericLimits.h:41
Definition LineTypes.h:23
TVector2< T > Origin
Definition LineTypes.h:25
TVector2< T > Direction
Definition LineTypes.h:28
Definition Vector2D.h:38
T Y
Definition Vector2D.h:52
static TVector2< T > Zero()
Definition Vector2D.h:79
T X
Definition Vector2D.h:49