Struct ConvexPolytope
Represents a convex polytope builder used in the Expanding Polytope Algorithm (EPA) for computing penetration depth and contact information.
public struct ConvexPolytope
- Inherited Members
Remarks
The polytope is iteratively expanded by adding vertices from the Minkowski difference until convergence. Call InitHeap() at least once before use to allocate memory for vertices and triangles.
Memory is allocated from the unmanaged heap and reused across EPA iterations.
Properties
HullTriangles
public readonly Span<ConvexPolytope.Triangle> HullTriangles { get; }
Property Value
OriginEnclosed
Indicates whether the origin is enclosed within the polyhedron. Important: This property returns correct values after invoking GetClosestTriangle().
public readonly bool OriginEnclosed { get; }
Property Value
Methods
AddVertex(in Vertex)
Adds a vertex to the polytope and rebuilds the convex hull.
public bool AddVertex(in MinkowskiDifference.Vertex vertex)
Parameters
vertexMinkowskiDifference.VertexThe Minkowski difference vertex to add.
Returns
- bool
trueif the vertex was incorporated;falseif the polytope could not expand.
Remarks
This operation invalidates references from previous GetClosestTriangle() calls.
CalculatePoints(in Triangle, out JVector, out JVector)
Computes the closest points on shapes A and B from a triangle on the polytope.
public void CalculatePoints(in ConvexPolytope.Triangle ctri, out JVector pA, out JVector pB)
Parameters
ctriConvexPolytope.TriangleThe triangle from GetClosestTriangle().
pAJVectorThe closest point on shape A.
pBJVectorThe closest point on shape B.
GetClosestTriangle()
Finds the triangle on the polytope closest to the origin.
public ref ConvexPolytope.Triangle GetClosestTriangle()
Returns
- ConvexPolytope.Triangle
A reference to the closest triangle. Also updates OriginEnclosed.
GetVertex(int)
public ref MinkowskiDifference.Vertex GetVertex(int index)
Parameters
indexint
Returns
InitHeap()
Allocates unmanaged memory for vertices and triangles.
public void InitHeap()
Remarks
Must be called before any other method. Safe to call multiple times; allocation occurs only once.
InitTetrahedron()
Initializes the polytope with a tetrahedron formed from the first four vertices.
public void InitTetrahedron()
Remarks
The first four vertices must be set before calling this method.
InitTetrahedron(in JVector)
Initializes the polytope with a small tetrahedron centered at the specified point.
public void InitTetrahedron(in JVector point)
Parameters
pointJVectorThe center point of the initial tetrahedron.