A* Pathfinding Project  4.1.23
The A* Pathfinding Project for Unity 3D
Polygon Class Reference

Utility functions for working with polygons, lines, and other vector math. More...

Detailed Description

Utility functions for working with polygons, lines, and other vector math.

All functions which accepts Vector3s but work in 2D space uses the XZ space if nothing else is said.

Version
A lot of functions in this class have been moved to the VectorMath class the names have changed slightly and everything now consistently assumes a left handed coordinate system now instead of sometimes using a left handed one and sometimes using a right handed one. This is why the 'Left' methods redirect to methods named 'Right'. The functionality is exactly the same.

Static Public Member Functions

static Vector2 ClosestPointOnTriangle (Vector2 a, Vector2 b, Vector2 c, Vector2 p)
 Closest point on the triangle abc to the point p. More...
 
static Vector3 ClosestPointOnTriangle (Vector3 a, Vector3 b, Vector3 c, Vector3 p)
 Closest point on the triangle abc to the point p. More...
 
static Vector3 ClosestPointOnTriangleXZ (Vector3 a, Vector3 b, Vector3 c, Vector3 p)
 Closest point on the triangle abc to the point p when seen from above. More...
 
static void CompressMesh (List< Int3 > vertices, List< int > triangles, out Int3[] outVertices, out int[] outTriangles)
 Compress the mesh by removing duplicate vertices. More...
 
static bool ContainsPoint (Int2 a, Int2 b, Int2 c, Int2 p)
 Returns if the triangle ABC contains the point p. More...
 
static bool ContainsPoint (Vector2[] polyPoints, Vector2 p)
 Checks if p is inside the polygon. More...
 
static bool ContainsPointXZ (Vector3 a, Vector3 b, Vector3 c, Vector3 p)
 Returns if the triangle ABC contains the point p in XZ space. More...
 
static bool ContainsPointXZ (Int3 a, Int3 b, Int3 c, Int3 p)
 Returns if the triangle ABC contains the point p. More...
 
static bool ContainsPointXZ (Vector3[] polyPoints, Vector3 p)
 Checks if p is inside the polygon (XZ space). More...
 
static Vector3 [] ConvexHullXZ (Vector3[] points)
 Calculates convex hull in XZ space for the points. More...
 
static int SampleYCoordinateInTriangle (Int3 p1, Int3 p2, Int3 p3, Int3 p)
 Sample Y coordinate of the triangle (p1, p2, p3) at the point p in XZ space. More...
 
static void Subdivide (List< Vector3 > points, List< Vector3 > result, int subSegments)
 Divides each segment in the list into subSegments segments and fills the result list with the new points. More...
 
static void TraceContours (Dictionary< int, int > outline, HashSet< int > hasInEdge, System.Action< List< int >, bool > results)
 Given a set of edges between vertices, follows those edges and returns them as chains and cycles. More...
 

Static Private Attributes

static readonly Dictionary< Int3, int > cached_Int3_int_dict = new Dictionary<Int3, int>()
 Cached dictionary to avoid excessive allocations. More...
 

Member Function Documentation

◆ ClosestPointOnTriangle() [1/2]

static Vector2 ClosestPointOnTriangle ( Vector2  a,
Vector2  b,
Vector2  c,
Vector2  p 
)
static

Closest point on the triangle abc to the point p.

See also
'Real Time Collision Detection' by Christer Ericson, chapter 5.1, page 141

◆ ClosestPointOnTriangle() [2/2]

static Vector3 ClosestPointOnTriangle ( Vector3  a,
Vector3  b,
Vector3  c,
Vector3  p 
)
static

Closest point on the triangle abc to the point p.

See also
'Real Time Collision Detection' by Christer Ericson, chapter 5.1, page 141

◆ ClosestPointOnTriangleXZ()

static Vector3 ClosestPointOnTriangleXZ ( Vector3  a,
Vector3  b,
Vector3  c,
Vector3  p 
)
static

Closest point on the triangle abc to the point p when seen from above.

See also
'Real Time Collision Detection' by Christer Ericson, chapter 5.1, page 141

◆ CompressMesh()

static void CompressMesh ( List< Int3 vertices,
List< int >  triangles,
out Int3 []  outVertices,
out int []  outTriangles 
)
static

Compress the mesh by removing duplicate vertices.

Parameters
verticesVertices of the input mesh
trianglesTriangles of the input mesh
outVerticesVertices of the output mesh.
outTrianglesTriangles of the output mesh.

Vertices that differ by only 1 along the y coordinate will also be merged together.

Warning
This function is not threadsafe. It uses some cached structures to reduce allocations.

◆ ContainsPoint() [1/2]

static bool ContainsPoint ( Int2  a,
Int2  b,
Int2  c,
Int2  p 
)
static

Returns if the triangle ABC contains the point p.

The triangle vertices are assumed to be laid out in clockwise order.

◆ ContainsPoint() [2/2]

static bool ContainsPoint ( Vector2 []  polyPoints,
Vector2  p 
)
static

Checks if p is inside the polygon.

Author
http://unifycommunity.com/wiki/index.php?title=PolyContainsPoint (Eric5h5)

◆ ContainsPointXZ() [1/3]

static bool ContainsPointXZ ( Vector3  a,
Vector3  b,
Vector3  c,
Vector3  p 
)
static

Returns if the triangle ABC contains the point p in XZ space.

The triangle vertices are assumed to be laid out in clockwise order.

◆ ContainsPointXZ() [2/3]

static bool ContainsPointXZ ( Int3  a,
Int3  b,
Int3  c,
Int3  p 
)
static

Returns if the triangle ABC contains the point p.

The triangle vertices are assumed to be laid out in clockwise order.

◆ ContainsPointXZ() [3/3]

static bool ContainsPointXZ ( Vector3 []  polyPoints,
Vector3  p 
)
static

Checks if p is inside the polygon (XZ space).

Author
http://unifycommunity.com/wiki/index.php?title=PolyContainsPoint (Eric5h5)

◆ ConvexHullXZ()

static Vector3 [] ConvexHullXZ ( Vector3 []  points)
static

Calculates convex hull in XZ space for the points.

Implemented using the very simple Gift Wrapping Algorithm which has a complexity of O(nh) where n is the number of points and h is the number of points on the hull, so it is in the worst case quadratic.

◆ SampleYCoordinateInTriangle()

static int SampleYCoordinateInTriangle ( Int3  p1,
Int3  p2,
Int3  p3,
Int3  p 
)
static

Sample Y coordinate of the triangle (p1, p2, p3) at the point p in XZ space.

The y coordinate of p is ignored.

Returns
The interpolated y coordinate unless the triangle is degenerate in which case a DivisionByZeroException will be thrown
See also
https://en.wikipedia.org/wiki/Barycentric_coordinate_system

◆ Subdivide()

static void Subdivide ( List< Vector3 >  points,
List< Vector3 >  result,
int  subSegments 
)
static

Divides each segment in the list into subSegments segments and fills the result list with the new points.

◆ TraceContours()

static void TraceContours ( Dictionary< int, int >  outline,
HashSet< int >  hasInEdge,
System.Action< List< int >, bool >  results 
)
static

Given a set of edges between vertices, follows those edges and returns them as chains and cycles.

Parameters
outlineoutline[a] = b if there is an edge from a to b.
hasInEdgehasInEdge should contain b if outline[a] = b for any key a.
resultsWill be called once for each contour with the contour as a parameter as well as a boolean indicating if the contour is a cycle or a chain (see image).

Member Data Documentation

◆ cached_Int3_int_dict

readonly Dictionary<Int3, int> cached_Int3_int_dict = new Dictionary<Int3, int>()
staticprivate

Cached dictionary to avoid excessive allocations.


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