JFLib

physics/src/gjk.rs#

Source: lib/physics/src/gjk.rs

gjk -- distance, penetration and time of impact between two convex shapes given as support functions

GJK (Gilbert, Johnson, Keerthi) finds the point of the Minkowski difference D = A - B closest to the
origin; the simplex is reduced by the Voronoi regions of its vertices, edges and faces (Ericson,
"Real-Time Collision Detection", 5.1.5 and 9.5).  EPA expands a polytope inside D to find the shallowest
way out when the cores overlap.  The cast is GJK ray casting with conservative advancement (van den
Bergen 2004, as in Box2D's b2ShapeCast): the support plane of D in the direction of the current closest
point bounds the distance at every later time, so the time advances to where that bound meets the target
distance and never beyond the first contact.  The radii of spheres and capsules stay outside GJK as
margins: the cores of two such shapes are apart at contact, which keeps the casts well conditioned.
/// two shapes without radius (boxes, hulls, triangles) stop a cast at this gap (metres): a positive
/// distance keeps the direction of the closest points well defined
CAST_SKIN: f64 = 1e-6
  • fn cast_fallbacks() -> u32 how many casts so far fell back from GJK ray casting to Newton's method on the distance (GJK at one time stalled by rounding, or its iterations ran out); the result is right either way, only slower

Source: docs/API.md in the JFLib repository.