UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SDFCalculationUtils.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Math/MathFwd.h"
6#include "Math/Vector.h"
7#include "VectorTypes.h"
8
9namespace UE
10{
11namespace Geometry
12{
13 using namespace UE::Math;
14
15 // These are utility functions shared by the various SDF calculation implementations
16 // (CachingMeshSDF, SweepignMeshSDF, SparseNarrowBandMeshSDF)
17
18
20
22
23
24 GEOMETRYCORE_API bool PointInTriangle2d(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3, double& A, double& B, double& C);
25
26 // find distance x0 is from segment x1-x2
27 template<typename RealType>
29 {
30 TVector<RealType> DX = x2 - x1;
31 RealType m2 = DX.SquaredLength();
32 // find parameter value of closest point on segment
33 RealType s12 = (DX.Dot(x2 - x0) / m2);
34 if (s12 < 0)
35 {
36 s12 = 0;
37 }
38 else if (s12 > 1)
39 {
40 s12 = 1;
41 }
42 // and find the distance
43 return Distance(x0, s12*x1 + (1.0 - s12)*x2);
44 }
45
46
47 // calculate twice signed area of triangle (0,0)-(X1,Y1)-(X2,Y2)
48 // return an SOS-determined sign (-1, +1, or 0 only if it's a truly degenerate triangle)
49 template<typename RealType>
50 int Orientation(RealType X1, RealType Y1, RealType X2, RealType Y2, RealType& TwiceSignedArea)
51 {
52 TwiceSignedArea = Y1 * X2 - X1 * Y2;
53 if (TwiceSignedArea > 0) return 1;
54 else if (TwiceSignedArea < 0) return -1;
55 else if (Y2 > Y1) return 1;
56 else if (Y2 < Y1) return -1;
57 else if (X1 > X2) return 1;
58 else if (X1 < X2) return -1;
59 else return 0; // only true when X1==X2 and Y1==Y2
60 }
61
62
63
64
65}
66}
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
GEOMETRYCORE_API bool PointInTriangle2d(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3, double &A, double &B, double &C)
Definition SDFCalculationUtils.cpp:84
GEOMETRYCORE_API double PointTriangleDistance(const FVector3d &x0, const FVector3d &x1, const FVector3d &x2, const FVector3d &x3)
Definition SDFCalculationUtils.cpp:9
RealType PointSegmentDistance(const TVector< RealType > &x0, const TVector< RealType > &x1, const TVector< RealType > &x2)
Definition SDFCalculationUtils.h:28
Definition Sphere.cpp:10
Definition AdvancedWidgetsModule.cpp:13
T SquaredLength() const
Definition Vector.h:1734
UE_FORCEINLINE_HINT T Dot(const TVector< T > &V) const
Definition Vector.h:1553