UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
LineTypes.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3// line types ported from WildMagic and geometry3Sharp
4
5#pragma once
6
7#include "Math/UnrealMath.h"
8#include "VectorTypes.h"
9
10namespace UE
11{
12namespace Geometry
13{
14
15using namespace UE::Math;
16
21template<typename T>
22struct TLine2
23{
26
29
38
46
47
51 static TLine2<T> FromPoints(const TVector2<T>& Point0, const TVector2<T>& Point1)
52 {
53 return TLine2<T>(Point0, Normalized(Point1 - Point0) );
54 }
55
56
60 inline TVector2<T> PointAt(T LineParameter) const
61 {
62 return Origin + LineParameter * Direction;
63 }
64
65
69 inline T Project(const TVector2<T>& QueryPoint) const
70 {
71 return (QueryPoint - Origin).Dot(Direction);
72 }
73
83
92
93
97 inline int WhichSide(const TVector2<T>& QueryPoint, T OnLineTolerance = 0) const
98 {
99 T x0 = QueryPoint.X - Origin.X;
100 T y0 = QueryPoint.Y - Origin.Y;
101 T x1 = Direction.X;
102 T y1 = Direction.Y;
103 T det = x0 * y1 - x1 * y0;
104 return (det > OnLineTolerance ? +1 : (det < -OnLineTolerance ? -1 : 0));
105 }
106
107
116 {
117 // see IntrTLine2TLine2 for more detailed explanation
118 TVector2<T> diff = OtherLine.Origin - Origin;
119 T D0DotPerpD1 = DotPerp(Direction, OtherLine.Direction);
120 if (TMathUtil<T>::Abs(D0DotPerpD1) > ParallelDotTolerance) // TLines intersect in a single point.
121 {
122 T invD0DotPerpD1 = ((T)1) / D0DotPerpD1;
123 T diffDotPerpD1 = DotPerp(diff, OtherLine.Direction);
126 return true;
127 }
128 // TLines are parallel.
129 return false;
130 }
131};
132
133
136
137
138
139
140
141
146template<typename T>
147struct TLine3
148{
151
154
163
171
172
176 static TLine3<T> FromPoints(const TVector<T>& Point0, const TVector<T>& Point1)
177 {
178 return TLine3<T>(Point0, Normalized(Point1 - Point0) );
179 }
180
181
185 inline TVector<T> PointAt(T LineParameter) const
186 {
187 return Origin + LineParameter * Direction;
188 }
189
190
194 inline T Project(const TVector<T>& QueryPoint) const
195 {
196 return (QueryPoint - Origin).Dot(Direction);
197 }
198
202 inline T DistanceSquared(const TVector<T>& QueryPoint) const
203 {
204 T t = (QueryPoint - Origin).Dot(Direction);
206 return (proj - QueryPoint).SquaredLength();
207 }
208
213 {
215 return Origin + ParameterT * Direction;
216 }
217
218
219};
220
223
224} // end namespace UE::Geometry
225} // end namespace UE
226
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition MathUtil.h:150
TLine2< double > FLine2d
Definition LineTypes.h:134
TLine3< float > FLine3f
Definition LineTypes.h:222
TLine2< float > FLine2f
Definition LineTypes.h:135
constexpr T DotPerp(const UE::Math::TVector2< T > &V1, const UE::Math::TVector2< T > &V2)
Definition VectorTypes.h:19
TLine3< double > FLine3d
Definition LineTypes.h:221
Definition Sphere.cpp:10
Definition AdvancedWidgetsModule.cpp:13
Definition LineTypes.h:23
T DistanceSquared(const TVector2< T > &QueryPoint) const
Definition LineTypes.h:77
static TLine2< T > FromPoints(const TVector2< T > &Point0, const TVector2< T > &Point1)
Definition LineTypes.h:51
TVector2< T > NearestPoint(const TVector2< T > &QueryPoint) const
Definition LineTypes.h:87
int WhichSide(const TVector2< T > &QueryPoint, T OnLineTolerance=0) const
Definition LineTypes.h:97
bool IntersectionPoint(const TLine2< T > &OtherLine, TVector2< T > &IntersectionPointOut, T ParallelDotTolerance=TMathUtil< T >::ZeroTolerance) const
Definition LineTypes.h:115
TVector2< T > Origin
Definition LineTypes.h:25
TVector2< T > Direction
Definition LineTypes.h:28
TLine2()
Definition LineTypes.h:33
TLine2(const TVector2< T > &OriginIn, const TVector2< T > &DirectionIn)
Definition LineTypes.h:42
T Project(const TVector2< T > &QueryPoint) const
Definition LineTypes.h:69
TVector2< T > PointAt(T LineParameter) const
Definition LineTypes.h:60
Definition LineTypes.h:148
TLine3()
Definition LineTypes.h:158
TVector< T > Direction
Definition LineTypes.h:153
TVector< T > PointAt(T LineParameter) const
Definition LineTypes.h:185
T DistanceSquared(const TVector< T > &QueryPoint) const
Definition LineTypes.h:202
static TLine3< T > FromPoints(const TVector< T > &Point0, const TVector< T > &Point1)
Definition LineTypes.h:176
TVector< T > NearestPoint(const TVector< T > &QueryPoint) const
Definition LineTypes.h:212
TVector< T > Origin
Definition LineTypes.h:150
TLine3(const TVector< T > &OriginIn, const TVector< T > &DirectionIn)
Definition LineTypes.h:167
T Project(const TVector< T > &QueryPoint) const
Definition LineTypes.h:194
Definition Vector2D.h:38
static TVector2< T > UnitX()
Definition Vector2D.h:81
UE_FORCEINLINE_HINT T SquaredLength() const
Definition Vector2D.h:516
static TVector2< T > Zero()
Definition Vector2D.h:79
Definition Vector.h:51
static TVector< T > UnitX()
Definition Vector.h:118
static TVector< T > Zero()
Definition Vector.h:112