UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
UE::Geometry::TPolygon2< T > Class Template Reference

#include <Polygon2.h>

Classes

class  SegmentEnumerable
 
class  SegmentIterator
 

Public Member Functions

 TPolygon2 ()
 
 TPolygon2 (const TArray< TVector2< T > > &VertexList)
 
template<typename OtherVertexType >
 TPolygon2 (const TArray< OtherVertexType > &VertexList)
 
 TPolygon2 (TArrayView< const TVector2< T > > VertexArray, TArrayView< const int32 > VertexIndices)
 
const TVector2< T > & operator[] (int Index) const
 
TVector2< T > & operator[] (int Index)
 
const TVector2< T > & Start () const
 
const TArray< TVector2< T > > & GetVertices () const
 
int VertexCount () const
 
void AppendVertex (const TVector2< T > &Position)
 
void AppendVertices (const TArray< TVector2< T > > &NewVertices)
 
void Set (int VertexIndex, const TVector2< T > &Position)
 
void RemoveVertex (int VertexIndex)
 
void SetVertices (const TArray< TVector2< T > > &NewVertices)
 
void Reverse ()
 
TVector2< T > GetTangent (int VertexIndex) const
 
TVector2< T > GetNormal (int VertexIndex) const
 
TVector2< T > GetNormal_FaceAvg (int VertexIndex) const
 
TAxisAlignedBox2< T > Bounds () const
 
SegmentIterator SegmentItr () const
 
SegmentEnumerable Segments () const
 
bool IsClockwise () const
 
SignedArea () const
 
Area () const
 
Perimeter () const
 
void NeighbourPoints (int VertexIdx, TVector2< T > &OutPrevNbr, TVector2< T > &OutNextNbr) const
 
void NeighbourVectors (int VertexIdx, TVector2< T > &OutToPrev, TVector2< T > &OutToNext, bool bNormalize=false) const
 
OpeningAngleDeg (int iVertex) const
 
WindingIntegral (const TVector2< T > &QueryPoint) const
 
bool IsConvex (T RadiansTolerance=TMathUtil< T >::ZeroTolerance, bool bDegenerateIsConvex=true) const
 
bool Contains (const TVector2< T > &QueryPoint) const
 
bool Overlaps (const TPolygon2< T > &OtherPoly) const
 
bool Contains (const TPolygon2< T > &OtherPoly) const
 
bool Contains (const TSegment2< T > &Segment) const
 
void ClipConvex (const TAxisAlignedBox2< T > &Bounds)
 
bool Intersects (const TPolygon2< T > &OtherPoly) const
 
bool Intersects (const TSegment2< T > &Segment) const
 
bool FindIntersections (const TPolygon2< T > &OtherPoly, TArray< TVector2< T > > &OutArray) const
 
TSegment2< T > Segment (int SegmentIndex) const
 
TVector2< T > GetSegmentPoint (int SegmentIndex, T SegmentParam) const
 
TVector2< T > GetSegmentPointUnitParam (int SegmentIndex, T SegmentParam) const
 
TVector2< T > GetNormal (int iSeg, T SegmentParam) const
 
DistanceSquared (const TVector2< T > &QueryPoint, int &NearestSegIndexOut, T &NearestSegParamOut) const
 
DistanceSquared (const TVector2< T > &QueryPoint) const
 
AverageEdgeLength () const
 
TPolygon2< T > & Translate (const TVector2< T > &Translate)
 
TPolygon2< T > & Scale (const TVector2< T > &Scale, const TVector2< T > &Origin)
 
TPolygon2< T > & Transform (const TFunction< TVector2< T >(const TVector2< T > &)> &TransformFunc)
 
void VtxNormalOffset (T OffsetDistance, bool bUseFaceAvg=false)
 
void PolyOffset (T OffsetDistance)
 
void Simplify (T ClusterTolerance=0.0001, T LineDeviationTolerance=0.01)
 
void Chamfer (T ChamferDist, T MinConvexAngleDeg=30, T MinConcaveAngleDeg=30)
 

Static Public Member Functions

static TPolygon2< T > MakeRectangle (const TVector2< T > &Center, T Width, T Height)
 
static TPolygon2< T > MakeRoundedRectangle (const TVector2< T > &Center, T Width, T Height, T Corner, int CornerSteps)
 
static TPolygon2< T > MakeCircle (T Radius, int Steps, T AngleShiftRadians=0)
 

Protected Attributes

TArray< TVector2< T > > Vertices
 

Friends

class SegmentIterator
 

Detailed Description

template<typename T>
class UE::Geometry::TPolygon2< T >

TPolygon2 is a 2D polygon represented as a list of Vertices.

Constructor & Destructor Documentation

◆ TPolygon2() [1/4]

template<typename T >
UE::Geometry::TPolygon2< T >::TPolygon2 ( )
inline

◆ TPolygon2() [2/4]

template<typename T >
UE::Geometry::TPolygon2< T >::TPolygon2 ( const TArray< TVector2< T > > &  VertexList)
inline

Construct polygon with given list of vertices

◆ TPolygon2() [3/4]

template<typename T >
UE::Geometry::TPolygon2< T >::TPolygon2 ( const TArray< OtherVertexType > &  VertexList)
inline

◆ TPolygon2() [4/4]

template<typename T >
UE::Geometry::TPolygon2< T >::TPolygon2 ( TArrayView< const TVector2< T > >  VertexArray,
TArrayView< const int32 VertexIndices 
)
inline

Construct polygon with given indices into a vertex array

Member Function Documentation

◆ AppendVertex()

template<typename T >
void UE::Geometry::TPolygon2< T >::AppendVertex ( const TVector2< T > &  Position)
inline

Add a vertex to the Polygon

◆ AppendVertices()

template<typename T >
void UE::Geometry::TPolygon2< T >::AppendVertices ( const TArray< TVector2< T > > &  NewVertices)
inline

Add a list of Vertices to the Polygon

◆ Area()

template<typename T >
T UE::Geometry::TPolygon2< T >::Area ( ) const
inline
Returns
the unsigned area of the Polygon

◆ AverageEdgeLength()

template<typename T >
T UE::Geometry::TPolygon2< T >::AverageEdgeLength ( ) const
inline
Returns
average edge length of all the edges of the Polygon

◆ Bounds()

template<typename T >
TAxisAlignedBox2< T > UE::Geometry::TPolygon2< T >::Bounds ( ) const
inline
Returns
the bounding box of the Polygon Vertices

◆ Chamfer()

template<typename T >
void UE::Geometry::TPolygon2< T >::Chamfer ( ChamferDist,
MinConvexAngleDeg = 30,
MinConcaveAngleDeg = 30 
)
inline

Chamfer each vertex corner of the Polygon

Parameters
ChamferDistoffset distance from corner that we cut at

◆ ClipConvex()

template<typename T >
void UE::Geometry::TPolygon2< T >::ClipConvex ( const TAxisAlignedBox2< T > &  Bounds)
inline

Clip polygon to the given bounds. Note that if the polygon is not convex, it may have overlapping edges at the bounds.

◆ Contains() [1/3]

template<typename T >
bool UE::Geometry::TPolygon2< T >::Contains ( const TPolygon2< T > &  OtherPoly) const
inline
Returns
true if the Polygon fully contains the OtherPolygon

◆ Contains() [2/3]

template<typename T >
bool UE::Geometry::TPolygon2< T >::Contains ( const TSegment2< T > &  Segment) const
inline
Returns
true if the Segment is fully contained inside the Polygon

◆ Contains() [3/3]

template<typename T >
bool UE::Geometry::TPolygon2< T >::Contains ( const TVector2< T > &  QueryPoint) const
inline
Returns
true if the given query point is inside the Polygon, based on the winding integral

◆ DistanceSquared() [1/2]

template<typename T >
T UE::Geometry::TPolygon2< T >::DistanceSquared ( const TVector2< T > &  QueryPoint) const
inline

Calculate the squared distance from a point to the polygon

Parameters
QueryPointthe query point
Returns
squared distance to the polygon

◆ DistanceSquared() [2/2]

template<typename T >
T UE::Geometry::TPolygon2< T >::DistanceSquared ( const TVector2< T > &  QueryPoint,
int &  NearestSegIndexOut,
T &  NearestSegParamOut 
) const
inline

Calculate the squared distance from a point to the polygon

Parameters
QueryPointthe query point
NearestSegIndexOutThe index of the nearest segment
NearestSegParamOutthe parameter value of the nearest point on the segment
Returns
squared distance to the polygon

◆ FindIntersections()

template<typename T >
bool UE::Geometry::TPolygon2< T >::FindIntersections ( const TPolygon2< T > &  OtherPoly,
TArray< TVector2< T > > &  OutArray 
) const
inline

Find all the points where an edge of the Polygon intersects an edge of the OtherPolygon

Parameters
OtherPolypolygon to test against
OutArrayintersection points are stored here
Returns
true if any intersections were found

◆ GetNormal() [1/2]

template<typename T >
TVector2< T > UE::Geometry::TPolygon2< T >::GetNormal ( int  iSeg,
SegmentParam 
) const
inline
Parameters
SegmentIndexindex of first vertex of the edge
SegmentParamparameter in range [0,1] along segment
Returns
interpolated normal to the segment at the given parameter value

◆ GetNormal() [2/2]

template<typename T >
TVector2< T > UE::Geometry::TPolygon2< T >::GetNormal ( int  VertexIndex) const
inline

Get the normal vector at a vertex of the polygon, which is perpendicular to GetTangent() Points "inward" for a Clockwise Polygon, and outward for CounterClockwise

◆ GetNormal_FaceAvg()

template<typename T >
TVector2< T > UE::Geometry::TPolygon2< T >::GetNormal_FaceAvg ( int  VertexIndex) const
inline

Construct a normal at a vertex of the Polygon by averaging the adjacent face normals. This vector is independent of the lengths of the adjacent segments. Points "inward" for a Clockwise Polygon, and outward for CounterClockwise

◆ GetSegmentPoint()

template<typename T >
TVector2< T > UE::Geometry::TPolygon2< T >::GetSegmentPoint ( int  SegmentIndex,
SegmentParam 
) const
inline
Parameters
SegmentIndexindex of first vertex of the edge
SegmentParamparameter in range [-Extent,Extent] along segment
Returns
point on the segment at the given parameter value

◆ GetSegmentPointUnitParam()

template<typename T >
TVector2< T > UE::Geometry::TPolygon2< T >::GetSegmentPointUnitParam ( int  SegmentIndex,
SegmentParam 
) const
inline
Parameters
SegmentIndexindex of first vertex of the edge
SegmentParamparameter in range [0,1] along segment
Returns
point on the segment at the given parameter value

◆ GetTangent()

template<typename T >
TVector2< T > UE::Geometry::TPolygon2< T >::GetTangent ( int  VertexIndex) const
inline

Get the tangent vector at a vertex of the polygon, which is the normalized vector from the previous vertex to the next vertex

◆ GetVertices()

template<typename T >
const TArray< TVector2< T > > & UE::Geometry::TPolygon2< T >::GetVertices ( ) const
inline
Returns
list of Vertices of Polygon

◆ Intersects() [1/2]

template<typename T >
bool UE::Geometry::TPolygon2< T >::Intersects ( const TPolygon2< T > &  OtherPoly) const
inline
Returns
true if at least one edge of the OtherPolygon intersects the Polygon

◆ Intersects() [2/2]

template<typename T >
bool UE::Geometry::TPolygon2< T >::Intersects ( const TSegment2< T > &  Segment) const
inline
Returns
true if the Segment intersects an edge of the Polygon

◆ IsClockwise()

template<typename T >
bool UE::Geometry::TPolygon2< T >::IsClockwise ( ) const
inline
Returns
true if the Polygon Vertices have Clockwise winding order / orientation (signed area is negative)

◆ IsConvex()

template<typename T >
bool UE::Geometry::TPolygon2< T >::IsConvex ( RadiansTolerance = TMathUtil<T>::ZeroTolerance,
bool  bDegenerateIsConvex = true 
) const
inline
Parameters
RadiansToleranceMaximum turn in the 'wrong' direction that will still be considered convex (in radians)
bDegenerateIsConvexWhat to return for degenerate input (less than 3 points or equivalent due to repeated points)
Returns
true if polygon is convex

◆ MakeCircle()

template<typename T >
static TPolygon2< T > UE::Geometry::TPolygon2< T >::MakeCircle ( Radius,
int  Steps,
AngleShiftRadians = 0 
)
inlinestatic

Construct a circular polygon

◆ MakeRectangle()

template<typename T >
static TPolygon2< T > UE::Geometry::TPolygon2< T >::MakeRectangle ( const TVector2< T > &  Center,
Width,
Height 
)
inlinestatic

Construct a four-vertex rectangle polygon

◆ MakeRoundedRectangle()

template<typename T >
static TPolygon2< T > UE::Geometry::TPolygon2< T >::MakeRoundedRectangle ( const TVector2< T > &  Center,
Width,
Height,
Corner,
int  CornerSteps 
)
inlinestatic

Construct a rounded rectangle polygon

◆ NeighbourPoints()

template<typename T >
void UE::Geometry::TPolygon2< T >::NeighbourPoints ( int  VertexIdx,
TVector2< T > &  OutPrevNbr,
TVector2< T > &  OutNextNbr 
) const
inline

Get the previous and next vertex positions for a given vertex of the Polygon

◆ NeighbourVectors()

template<typename T >
void UE::Geometry::TPolygon2< T >::NeighbourVectors ( int  VertexIdx,
TVector2< T > &  OutToPrev,
TVector2< T > &  OutToNext,
bool  bNormalize = false 
) const
inline

Get the vectors from a given vertex to the previous and next Vertices, optionally normalized

◆ OpeningAngleDeg()

template<typename T >
T UE::Geometry::TPolygon2< T >::OpeningAngleDeg ( int  iVertex) const
inline
Returns
the opening angle in degrees at a vertex of the Polygon

◆ operator[]() [1/2]

template<typename T >
TVector2< T > & UE::Geometry::TPolygon2< T >::operator[] ( int  Index)
inline

Get the vertex at a given index

◆ operator[]() [2/2]

template<typename T >
const TVector2< T > & UE::Geometry::TPolygon2< T >::operator[] ( int  Index) const
inline

Get the vertex at a given index

◆ Overlaps()

template<typename T >
bool UE::Geometry::TPolygon2< T >::Overlaps ( const TPolygon2< T > &  OtherPoly) const
inline

Check for polygon overlap, aka solid intersection. (In contrast, note that the "Intersects" method checks for edge intersection)

Returns
true if the Polygon overlaps the OtherPolygon.

◆ Perimeter()

template<typename T >
T UE::Geometry::TPolygon2< T >::Perimeter ( ) const
inline
Returns
the total perimeter length of the Polygon

◆ PolyOffset()

template<typename T >
void UE::Geometry::TPolygon2< T >::PolyOffset ( OffsetDistance)
inline

Offset polygon by fixed distance, by offsetting and intersecting edges. CounterClockWise Polygon offsets "outwards", ClockWise "inwards".

◆ RemoveVertex()

template<typename T >
void UE::Geometry::TPolygon2< T >::RemoveVertex ( int  VertexIndex)
inline

Remove a vertex of the Polygon (existing Vertices are shifted)

◆ Reverse()

template<typename T >
void UE::Geometry::TPolygon2< T >::Reverse ( )
inline

Reverse the order of the Vertices in the Polygon (ie switch between Clockwise and CounterClockwise)

◆ Scale()

template<typename T >
TPolygon2< T > & UE::Geometry::TPolygon2< T >::Scale ( const TVector2< T > &  Scale,
const TVector2< T > &  Origin 
)
inline

Scale the Polygon relative to a given point

Returns
the Polygon, so that you can chain calls like Translate().Scale()

◆ Segment()

template<typename T >
TSegment2< T > UE::Geometry::TPolygon2< T >::Segment ( int  SegmentIndex) const
inline
Returns
edge of the polygon starting at vertex SegmentIndex

◆ SegmentItr()

template<typename T >
SegmentIterator UE::Geometry::TPolygon2< T >::SegmentItr ( ) const
inline

◆ Segments()

template<typename T >
SegmentEnumerable UE::Geometry::TPolygon2< T >::Segments ( ) const
inline
Returns
an object that can be used in a range-based for loop to iterate over the Segments of the Polygon

◆ Set()

template<typename T >
void UE::Geometry::TPolygon2< T >::Set ( int  VertexIndex,
const TVector2< T > &  Position 
)
inline

Set vertex at given index to a new Position

◆ SetVertices()

template<typename T >
void UE::Geometry::TPolygon2< T >::SetVertices ( const TArray< TVector2< T > > &  NewVertices)
inline

Replace the list of Vertices with a new list

◆ SignedArea()

template<typename T >
T UE::Geometry::TPolygon2< T >::SignedArea ( ) const
inline
Returns
the signed area of the Polygon

◆ Simplify()

template<typename T >
void UE::Geometry::TPolygon2< T >::Simplify ( ClusterTolerance = 0.0001,
LineDeviationTolerance = 0.01 
)
inline

Simplify the Polygon to reduce the vertex count

Parameters
ClusterToleranceVertices closer than this distance will be merged into a single vertex
LineDeviationToleranceVertices are allowed to deviate this much from the input polygon lines

◆ Start()

template<typename T >
const TVector2< T > & UE::Geometry::TPolygon2< T >::Start ( ) const
inline
Returns
first vertex of Polygon

◆ Transform()

template<typename T >
TPolygon2< T > & UE::Geometry::TPolygon2< T >::Transform ( const TFunction< TVector2< T >(const TVector2< T > &)> &  TransformFunc)
inline

Apply an arbitrary transformation to the Polygon

Returns
the Polygon, so that you can chain calls like Translate().Scale()

◆ Translate()

template<typename T >
TPolygon2< T > & UE::Geometry::TPolygon2< T >::Translate ( const TVector2< T > &  Translate)
inline

Translate the polygon

Returns
the Polygon, so that you can chain calls like Translate().Scale()

◆ VertexCount()

template<typename T >
int UE::Geometry::TPolygon2< T >::VertexCount ( ) const
inline
Returns
number of Vertices in Polygon

◆ VtxNormalOffset()

template<typename T >
void UE::Geometry::TPolygon2< T >::VtxNormalOffset ( OffsetDistance,
bool  bUseFaceAvg = false 
)
inline

Offset each point by the given Distance along vertex "normal" direction

Parameters
OffsetDistancethe distance to offset
bUseFaceAvgif true, we offset by the average-face normal instead of the perpendicular-tangent normal

◆ WindingIntegral()

template<typename T >
T UE::Geometry::TPolygon2< T >::WindingIntegral ( const TVector2< T > &  QueryPoint) const
inline
Returns
analytic winding integral for this Polygon at an arbitrary point

Friends And Related Symbol Documentation

◆ SegmentIterator

template<typename T >
friend class SegmentIterator
friend

Member Data Documentation

◆ Vertices

template<typename T >
TArray<TVector2<T> > UE::Geometry::TPolygon2< T >::Vertices
protected

The list of vertices/corners of the polygon


The documentation for this class was generated from the following files: