UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DistLine3Line3.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3// derived from geometry3Sharp DistLine3Ray3
4
5#pragma once
6
7#include "VectorTypes.h"
8#include "LineTypes.h"
9
10namespace UE
11{
12namespace Geometry
13{
14
15using namespace UE::Math;
16
20template <typename Real>
22{
23public:
24 // Input
27
28 // Results
29 Real DistanceSquared = -1.0;
30
31 bool bIsParallel = false;
36
42
43 Real Get()
44 {
45 return (Real)sqrt(ComputeResult());
46 }
48 {
49 return ComputeResult();
50 }
51
53 {
54 if (DistanceSquared >= 0)
55 {
56 return DistanceSquared;
57 }
58
61 Real b0 = kDiff.Dot(Line1.Direction);
62 Real c = kDiff.SquaredLength();
63 Real det = FMath::Abs((Real)1 - a01 * a01);
64 Real b1, s0, s1, sqrDist;
65
67 {
68 b1 = -kDiff.Dot(Line2.Direction);
69 s1 = a01 * b0 - b1;
70
71 // Two interior points are closest.
72 Real invDet = ((Real)1) / det;
73 s0 = (a01 * b1 - b0) * invDet;
74 s1 *= invDet;
75 sqrDist = s0 * (s0 + a01 * s1 + ((Real)2) * b0) +
76 s1 * (a01 * s0 + s1 + ((Real)2) * b1) + c;
77
82
83 bIsParallel = false;
84 }
85 else
86 {
87 // Lines are parallel, closest pair at line1 origin
88 Line1Parameter = (Real)0;
93
94 bIsParallel = true;
95 }
96
97 // Account for numerical round-off errors.
98 DistanceSquared = (sqrDist < (Real)0) ? (Real)0 : sqrDist;
99 return DistanceSquared;
100 }
101};
102
105
106} // end namespace UE::Geometry
107} // end namespace UE
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition MathUtil.h:150
Definition DistLine3Line3.h:22
TVector< Real > Line1ClosestPoint
Definition DistLine3Line3.h:32
Real Get()
Definition DistLine3Line3.h:43
Real Line1Parameter
Definition DistLine3Line3.h:33
Real GetSquared()
Definition DistLine3Line3.h:47
TLine3< Real > Line2
Definition DistLine3Line3.h:26
Real ComputeResult()
Definition DistLine3Line3.h:52
TVector< Real > Line2ClosestPoint
Definition DistLine3Line3.h:34
TLine3< Real > Line1
Definition DistLine3Line3.h:25
TDistLine3Line3(const TLine3< Real > &Line1In, const TLine3< Real > &Line2In)
Definition DistLine3Line3.h:37
Real Line2Parameter
Definition DistLine3Line3.h:35
bool bIsParallel
Definition DistLine3Line3.h:31
Real DistanceSquared
Definition DistLine3Line3.h:29
TDistLine3Line3< float > FDistLine3Line3f
Definition DistLine3Line3.h:103
TDistLine3Line3< double > FDistLine3Line3d
Definition DistLine3Line3.h:104
Definition Sphere.cpp:10
Definition AdvancedWidgetsModule.cpp:13
Definition LineTypes.h:148
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
TVector< T > Origin
Definition LineTypes.h:150
T Project(const TVector< T > &QueryPoint) const
Definition LineTypes.h:194
Definition Vector.h:51
UE_FORCEINLINE_HINT T Dot(const TVector< T > &V) const
Definition Vector.h:1553