CSE 381 – Advanced Game Programming GJK
GJK Gilbert – Johnson – Keerthi distance algorithm Used to determine the minimum distance between convex sets Why? –to see if they are colliding –to see where they are colliding
What’s a convex set? What does convex mean? Convex Test: –For all the shape’s vertices: Make a line between each pair Is entire line inside object? –If yes, it is convex –If no, it is not (i.e., has dent)
Convex Set vs. Hull Convex Set –a set of points representing a convex shape Convex Hull –a minimal convex set –minimally snugly fits points (rubber band analogy)
Minkowski Sum What’s that? –A mathematical operation performed on 2 shapes A B = All Points in A + All Points in B How many points do we end up with? –A * B
Visualizing Minkowski Sums Results in swept shapes A B A B
Minkowski Difference The Opposite of a Minkowski Sum A B = All Points in A – All Points in B How many points do we end up with? –A * B
Visualizing Minkowski Differences Results in swept shapes A B A B
An Interesting Detail For Minkowski Difference A B If A and B are intersecting, A B contains origin A B A B
Now Let’s Get Back To GJK Assume we have two shapes, A & B We want to know if A & B intersect
GJK for A & B Collision Test 1.Calculate Minkowski Difference 2.Select any Minkowski Difference point 3.Start at that point, and try to get to origin by visiting other points. –remember, this is a convex set 4.Build polytope using 4 points –iteratively update to find next one 5.If any polytope along way contains origin, no collision 6.If polytope never contains origin, no collision
Visualizing GJK Miss (no collision) Note: I’ve simplified things a bit for rendering
Visualizing GJK Hit (collision)