# Problem computing GJK support points

This topic is 1895 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm trying to implement the GJK algorithm but am having difficulty calculating the support points. For my test case I am using equally size boxes stacked on top of each other, with box 2 at the origin and box 1 translated 10 units on the Y axis.

[CODE]
____
| 1 |
|____|
| 2 |
|____|
[/CODE]

I start with a search direction of ( 0, 1 ) which finds the support points:
Box 1 - ( 5, 15 )
Box 2 - ( 5, -5 )

This yields the GJK support point of ( 5, 15 ) - ( 5, -5 ) == ( 0, 20 ). The Y term is correct but the X term is obviously wrong; the correct point on the Minkowski difference is ( 20, 20 ). This is found if Box 2's vertex at ( -5, -5 ) is used, but because both ( 5, -5 ) and ( -5, -5 ) meet the max( -DtBj ) requirement it depends which vertex was added to the hull first.

Question is how to guarantee the correct vertex is found to calculate the difference? Bonus points for a solution which works in 3 dimensions as that is the world the algorithm lives in. Edited by chandlerp

##### Share on other sites
Maybe I'm missing something, but what is wrong with (0, 20)? Although it is not one of the vertices, it [i]is[/i] on the bounds of the minkowski difference. My understanding of the GJK algorithm is that it should still work correctly.

##### Share on other sites
[quote name='greggles' timestamp='1352084345' post='4997410']
Maybe I'm missing something, but what is wrong with (0, 20)? Although it is not one of the vertices, it [i]is[/i] on the bounds of the minkowski difference. My understanding of the GJK algorithm is that it should still work correctly.
[/quote]

Ah, yep. I think I've been staring at code and formulas too long. Thank you!

##### Share on other sites
[quote name='greggles' timestamp='1352084345' post='4997410']
Maybe I'm missing something, but what is wrong with (0, 20)? Although it is not one of the vertices, it [i]is[/i] on the bounds of the minkowski difference. My understanding of the GJK algorithm is that it should still work correctly.
[/quote]
Greggles maybe I'm misunderstanding you, what you say is correct but the vertex (0,20) or any support point is indeed one of the vertices... if you mean the vertices of the Minkowski difference.

##### Share on other sites
[quote name='BobXIV' timestamp='1352385937' post='4998874']
[quote name='greggles' timestamp='1352084345' post='4997410']
Maybe I'm missing something, but what is wrong with (0, 20)? Although it is not one of the vertices, it [i]is[/i] on the bounds of the minkowski difference. My understanding of the GJK algorithm is that it should still work correctly.
[/quote]
Greggles maybe I'm misunderstanding you, what you say is correct but the vertex (0,20) or any support point is indeed one of the vertices... if you mean the vertices of the Minkowski difference.
[/quote]
I think you may have misunderstood me. Let me clarify the calculations:

The original shapes are define by vertices
(-5, 5), (5, 5), (5, 15), (-5, 15)
and
(-5, -5), (5, -5), (5, 5), (-5, 5)

We know (intuitively, but this can be determined algorithmically with more calculation) that the resultant diffence will be a square, so finding the four vertices of the difference:
(-5, 5) - (5, 5) = (-10, 0)
(5, 5) - (-5, 5) = (10, 0)
(5, 15) - (-5, -5) = (10, 20)
(-5, 15) - (5, -5) = (-10, 20)
So there is an edge from (10, 20) to (-10, 20).

(0, 20) lies in the middle of this edge instead of one of its endpoints; thus it is not a vertex.

##### Share on other sites

This topic is 1895 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.