Class Polygon
Public
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.
Public Static Methods
Vector3
ClosestPointOnTriangle
(
)
Closest point on the triangle abc to the point p.
See
'Real Time Collision Detection' by Christer Ericson, chapter 5.1, page 141
Vector2
ClosestPointOnTriangle
(
)
Closest point on the triangle abc to the point p.
See
'Real Time Collision Detection' by Christer Ericson, chapter 5.1, page 141
Vector3
ClosestPointOnTriangleXZ
(
)
Closest point on the triangle abc to the point p when seen from above.
See
'Real Time Collision Detection' by Christer Ericson, chapter 5.1, page 141
void
CompressMesh
(
List<Int3> | vertices | Vertices of the input mesh |
List<int> | triangles | Triangles of the input mesh |
outInt3[] | outVertices | Vertices of the output mesh. |
out int [] | outTriangles | Triangles of the output mesh. |
)
Compress the mesh by removing duplicate vertices.
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.
bool
ContainsPoint
(
)
Checks if p is inside the polygon.
bool
ContainsPoint
(
)
Returns if the triangle ABC contains the point p.
The triangle vertices are assumed to be laid out in clockwise order.
bool
ContainsPointXZ
(
)
Checks if p is inside the polygon (XZ space).
bool
ContainsPointXZ
(
)
Returns if the triangle ABC contains the point p.
The triangle vertices are assumed to be laid out in clockwise order.
bool
ContainsPointXZ
(
)
Returns if the triangle ABC contains the point p in XZ space.
The triangle vertices are assumed to be laid out in clockwise order.
Vector3 []
ConvexHullXZ
(
)
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.
int
SampleYCoordinateInTriangle
(
)
Sample Y coordinate of the triangle (p1, p2, p3) at the point p in XZ space.
The y coordinate of p is ignored.
Return
The interpolated y coordinate unless the triangle is degenerate in which case a DivisionByZeroException will be thrown
void
Subdivide
(
)
Divides each segment in the list into subSegments segments and fills the result list with the new points.
void
TraceContours
(
Dictionary<int, int> | outline | outline[a] = b if there is an edge from a to b. |
HashSet<int> | hasInEdge | hasInEdge should contain b if outline[a] = b for any key a. |
System.Action<List<int >, bool> | results | Will 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). |
)
Given a set of edges between vertices, follows those edges and returns them as chains and cycles.
Private/Protected Members
Dictionary<Int3, int>
cached_Int3_int_dict = new Dictionary<Int3, int>()
Cached dictionary to avoid excessive allocations.