Table of Contents

Struct ConvexPolytope

Namespace
Jitter2.Collision
Assembly
Jitter2.dll

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

Span<ConvexPolytope.Triangle>

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

bool

Methods

AddVertex(in Vertex)

Adds a vertex to the polytope and rebuilds the convex hull.

public bool AddVertex(in MinkowskiDifference.Vertex vertex)

Parameters

vertex MinkowskiDifference.Vertex

The Minkowski difference vertex to add.

Returns

bool

true if the vertex was incorporated; false if 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

ctri ConvexPolytope.Triangle

The triangle from GetClosestTriangle().

pA JVector

The closest point on shape A.

pB JVector

The 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

index int

Returns

MinkowskiDifference.Vertex

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

point JVector

The center point of the initial tetrahedron.