bonk-docs/content/narrow_phase/EPA2D.md

908 B

title date weight
EPA2D 2019-09-14T22:54:35-07:00 20

If an overlap has occurred, sometimes we wish to determine the penetration vector, which is the shortest possible vector by which one of the shapes could be moved in order for them to stop overlapping. For this purpose, Bonk implements the Expanding Polytope Algorithm.

To use this feature, you must pass the shapes and transforms as well as the simplex that is returned from the NarrowPhase.FindCollisionSimplex method.

var squareA = new Rectangle(-1, -1, 1, 1);
var transformA = Transform2D.DefaultTransform;
var squareB = new Rectangle(-1, -1, 1, 1);
var transformB = new Transform2D(new Vector2(1.5f, 0));

var (result, simplex) = NarrowPhase.FindCollisionSimplex(squareA, transformA, squareB, transformB);

if (result)
{
    var intersection = NarrowPhase.Intersect(squareA, transformA, squareB, transformB, simplex);
}