Gilbert–Johnson–Keerthi distance algorithm: Difference between revisions

Content deleted Content added
Reverted to revision 886367898 by WOSlinker (talk): WP:EL (TW)
m Overview: \mathrm, {{mvar}}
Line 11:
GJK relies on two functions:
 
* <math>\mathrm{Support}(\mathrm{shape}, \vec{d})</math>, which returns the point on <{{math>|shape</math>}} which has the highest dot product with <math>\vec{d}</math>.
* <math>\mathrm{NearestSimplex}(s)</math>, which takes a simplex <math>{{mvar|s</math>}} and returns the simplex on <math>{{mvar|s</math>}} closest to the origin, and a direction toward the origin normal to the new simplex. If <math>{{mvar|s</math>}} itself contains the origin, <{{math>|NearestSimplex</math>}} accepts <math>{{mvar|s</math>}} and the two shapes are determined to intersect.
 
The simplices handled by <{{math>|NearestSimplex</math>}} may each be any simplex sub-space of {{math|'''R'''<sup>''n''</sup>}}. For example in 3D, they may be a point, a line segment, a triangle, or a tetrahedron; each defined by 1, 2, 3, or 4 points respectively.
 
=== Pseudocode ===
 
<syntaxhighlight>
function GJK_intersection(shape p, shape q, vector initial_axis):
vector A = Support(p, initial_axis) - Support(q, -initial_axis)
Line 31 ⟶ 30:
if contains_origin:
accept
</syntaxhighlight>
 
== Illustration==