UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
IntrTriangle2AxisAlignedBox2.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "VectorTypes.h"
6#include "TriangleTypes.h"
7#include "BoxTypes.h"
8#include "VectorUtil.h"
9
10namespace UE
11{
12namespace Geometry
13{
14
15using namespace UE::Math;
16
20template <typename Real>
22{
23protected:
24 // Input
28
29public:
30 // Output
31 // TODO: Unlike other TIntrPrim2Prim2 classes, this only computes the Boolean yes/no Test()
32 // But in the future we should add the option to Compute() the intersection polygon as well (e.g. refer to IntrTriangle2Triangle.h)
33
40
42 {
43 return Triangle;
44 }
45 bool IsTriangleOriented() const
46 {
48 }
50 {
51 return Box;
52 }
54 {
55 // TODO: Reset any result variable(s), once support for computing full intersection result is added
57 }
63 {
64 // TODO: Reset any result variable(s), once support for computing full intersection result is added
65 Box = BoxIn;
66 }
67
68
69 bool Test()
70 {
72 TriBox.Contain(Triangle.V[1]);
73 TriBox.Contain(Triangle.V[2]);
74
75 if (!TriBox.Intersects(Box))
76 {
77 // iff we're separated by a bounding box axis, the bounds don't intersect
78 return false;
79 }
80
81 Real OrientationSign = 1;
82 Real SignedArea = Triangle.SignedArea();
83 if (SignedArea < 0)
84 {
86 {
87 // if we're using oriented triangles and this one is inverted, it can't intersect
88 return false;
89 }
90 OrientationSign = -1;
91 }
92
93 // test if a box is entirely in the half-plane starting at EdgeVertex, going in the EdgePerp direction
95 {
96 for (int32 CornerIdx = 0; CornerIdx < 4; CornerIdx++)
97 {
98 bool bOutside = EdgePerp.Dot(Box.GetCorner(CornerIdx) - EdgeVertex) > 0;
99 if (!bOutside)
100 {
101 return false;
102 }
103 }
104 return true;
105 };
106
107 // Test triangle edges for separation
108 for (int32 LeadVert = 0, PrevVert = 2; LeadVert < 3; PrevVert = LeadVert++)
109 {
113 {
114 continue;
115 }
116
118 {
119 // separated by a triangle edge
120 return false;
121 }
122 }
123
124 // no separating axis found
125 return true;
126 }
127
128
129};
130
133
134} // end namespace UE::Geometry
135} // end namespace UE
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition MathUtil.h:150
Definition IntrTriangle2AxisAlignedBox2.h:22
TTriangle2< Real > GetBox() const
Definition IntrTriangle2AxisAlignedBox2.h:49
TAxisAlignedBox2< Real > Box
Definition IntrTriangle2AxisAlignedBox2.h:26
void SetTriangle(const TTriangle2< Real > &TriangleIn)
Definition IntrTriangle2AxisAlignedBox2.h:53
void SetBox(const TAxisAlignedBox2< Real > &BoxIn)
Definition IntrTriangle2AxisAlignedBox2.h:62
TTriangle2< Real > GetTriangle() const
Definition IntrTriangle2AxisAlignedBox2.h:41
bool Test()
Definition IntrTriangle2AxisAlignedBox2.h:69
bool bTriangleIsOriented
Definition IntrTriangle2AxisAlignedBox2.h:27
TIntrTriangle2AxisAlignedBox2(TTriangle2< Real > Triangle, TAxisAlignedBox2< Real > Box, bool bTriangleIsOriented=true)
Definition IntrTriangle2AxisAlignedBox2.h:36
void SetTriangleOriented(const bool bIsOrientedIn)
Definition IntrTriangle2AxisAlignedBox2.h:58
TIntrTriangle2AxisAlignedBox2()
Definition IntrTriangle2AxisAlignedBox2.h:34
TTriangle2< Real > Triangle
Definition IntrTriangle2AxisAlignedBox2.h:25
bool IsTriangleOriented() const
Definition IntrTriangle2AxisAlignedBox2.h:45
constexpr UE::Math::TVector2< T > PerpCW(const UE::Math::TVector2< T > &V)
Definition VectorTypes.h:26
TIntrTriangle2AxisAlignedBox2< float > FIntrTriangle2AxisAlignedBox2f
Definition IntrTriangle2AxisAlignedBox2.h:131
TIntrTriangle2AxisAlignedBox2< double > FIntrTriangle2AxisAlignedBox2d
Definition IntrTriangle2AxisAlignedBox2.h:132
Definition Sphere.cpp:10
Definition AdvancedWidgetsModule.cpp:13
Definition BoxTypes.h:637
TVector2< RealType > GetCorner(int Index) const
Definition BoxTypes.h:730
Definition TriangleTypes.h:39
TVector2< RealType > V[3]
Definition TriangleTypes.h:40
static RealType SignedArea(const TVector2< RealType > &A, const TVector2< RealType > &B, const TVector2< RealType > &C)
Definition TriangleTypes.h:79
Definition Vector2D.h:38
UE_FORCEINLINE_HINT T SquaredLength() const
Definition Vector2D.h:516