UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DistLine3Ray3.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3// Port of 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
35
36
38 {
39 Line = LineIn;
40 Ray = RayIn;
41 }
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(Line.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(Ray.Direction);
69 s1 = a01 * b0 - b1;
70
71 if (s1 >= (Real)0)
72 {
73 // Two interior points are closest, one on Line and one on Ray.
74 Real invDet = ((Real)1) / det;
75 s0 = (a01 * b1 - b0) * invDet;
76 s1 *= invDet;
77 sqrDist = s0 * (s0 + a01 * s1 + ((Real)2) * b0) +
78 s1 * (a01 * s0 + s1 + ((Real)2) * b1) + c;
79 }
80 else
81 {
82 // Origin of Ray and interior point of Line are closest.
83 s0 = -b0;
84 s1 = (Real)0;
85 sqrDist = b0 * s0 + c;
86 }
87 }
88 else
89 {
90 // Lines are parallel, closest pair with one point at Ray origin.
91 s0 = -b0;
92 s1 = (Real)0;
93 sqrDist = b0 * s0 + c;
94 }
95
100
101 // Account for numerical round-off errors.
102 if (sqrDist < (Real)0)
103 {
104 sqrDist = (Real)0;
105 }
107
108 return sqrDist;
109 }
110};
111
114
115} // end namespace UE::Geometry
116} // end namespace UE
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition MathUtil.h:150
Definition DistLine3Ray3.h:22
TVector< Real > LineClosestPoint
Definition DistLine3Ray3.h:31
Real LineParameter
Definition DistLine3Ray3.h:32
TVector< Real > RayClosestPoint
Definition DistLine3Ray3.h:33
Real GetSquared()
Definition DistLine3Ray3.h:47
TLine3< Real > Line
Definition DistLine3Ray3.h:25
Real RayParameter
Definition DistLine3Ray3.h:34
Real DistanceSquared
Definition DistLine3Ray3.h:29
TRay< Real > Ray
Definition DistLine3Ray3.h:26
TDistLine3Ray3(const TLine3< Real > &LineIn, const TRay< Real > &RayIn)
Definition DistLine3Ray3.h:37
Real Get()
Definition DistLine3Ray3.h:43
Real ComputeResult()
Definition DistLine3Ray3.h:52
TDistLine3Ray3< double > FDistLine3Ray3d
Definition DistLine3Ray3.h:113
TDistLine3Ray3< float > FDistLine3Ray3f
Definition DistLine3Ray3.h:112
Definition Sphere.cpp:10
Definition AdvancedWidgetsModule.cpp:13
Definition LineTypes.h:148
TVector< T > Direction
Definition LineTypes.h:153
TVector< T > Origin
Definition LineTypes.h:150
Definition Ray.h:19
TVector< T > Origin
Definition Ray.h:24
TVector< T > Direction
Definition Ray.h:27
Definition Vector.h:51
UE_FORCEINLINE_HINT T Dot(const TVector< T > &V) const
Definition Vector.h:1553