**0**

# GJK Algorithm

Started by Sep 30 2005 09:41 AM

,
4 replies to this topic

###
#1
Members - Reputation: **145**

Posted 30 September 2005 - 09:41 AM

I'm in the process of implementing the GJK algorithm, there are a couple of things that I'm unclear of. I understand that i'm just calculating the points of the minkowski difference on the fly using supporting points two meshes. The objects i'm working with are convex so say I wanted to initialize the algorithm with simplex of 4 points from the minkowski difference of mesh A and B, can I pick a point on mesh A and normalize the vector and then use my supporting point method in the opposite direction of the point on mesh A? Also what is the best way to init a simplex in R3, should I just start with one point and begin the algorithm?
For determining the smallest simplex i need to compare barycentric coords, I don't believe that I need to calculate them because I already know if the point is on a face a vertex or an edge. I can grasp this much better in R2 than R3 so say I had a tetrahedron simplex and i wanted to reduce the simplex when i calculate the closest point to the origin on the tetrahedron, say the point lies on a face of the tetrahedron, would the simplex simply be the triangle that the point lies on?
I've got pretty much everything else done so if someone could give me a hand with this it'd be much appreciated.

###
#2
Anonymous Poster_Anonymous Poster_*
Guests - Reputation:

Posted 30 September 2005 - 12:00 PM

I think the simplex used in GJK is of one lower dimension than the one the convex objects exist in. In the 2d version, it is a line segment. In the 3d version it would be a triangle.

When they talk about finding the smallest simplex or whatever, they are just trying to state in very non-ambiguous mathematical terms that you choose the points that form the simplex that contains the point closest to the origin. So that would be the triangle which contains the point closest to the origin.

There's no need to start with any points in the simplex at all. You can just start with an empty set of points for the simplex, and keep adding new points to it until it gets to the size where you need to calculate which point to remove at each iteration.

You can initialize the algorithm by choosing an arbitrary direction. That direction gives you the first point, then the next direction is opposite the vector between the origin and the point. That direction produces the second point. Now the simplex is a line, and you find the closest point to the origin on that line, choose the next direction by negating the vector to that point, and that produces the third point. Now you find the closest point on the triangle to the origin, then negate that vector to get the next direction and the fourth point. At this point the simplex contains 4 points, but a subset of that simplex consisting of a simplex of only 3 of the points will contain the point closest to the origin. So you eliminate the point that is not part of that triangle. Then any more iterations look just like the last one...

When they talk about finding the smallest simplex or whatever, they are just trying to state in very non-ambiguous mathematical terms that you choose the points that form the simplex that contains the point closest to the origin. So that would be the triangle which contains the point closest to the origin.

There's no need to start with any points in the simplex at all. You can just start with an empty set of points for the simplex, and keep adding new points to it until it gets to the size where you need to calculate which point to remove at each iteration.

You can initialize the algorithm by choosing an arbitrary direction. That direction gives you the first point, then the next direction is opposite the vector between the origin and the point. That direction produces the second point. Now the simplex is a line, and you find the closest point to the origin on that line, choose the next direction by negating the vector to that point, and that produces the third point. Now you find the closest point on the triangle to the origin, then negate that vector to get the next direction and the fourth point. At this point the simplex contains 4 points, but a subset of that simplex consisting of a simplex of only 3 of the points will contain the point closest to the origin. So you eliminate the point that is not part of that triangle. Then any more iterations look just like the last one...

###
#3
Members - Reputation: **835**

Posted 30 September 2005 - 06:10 PM

Quote:A frequent approach is to start with the simplex from the previous call to the algorithm (for the given pair of objects). The first time around just use one point.

Original post by Gorwooken

Also what is the best way to init a simplex in R3, should I just start with one point and begin the algorithm?

Quote:Yes, you drop the points in the support set that are not needed to express the point that lies on the feature and is closest to the query point. For example, you have four points in the set, forming a tetrahedron. If the closest point lies on one of the faces of the tetrahedron, you keep the three vertices of that face and discard the fourth. If the closest point lies on one of the tetrahedron edges, you keep the pair of points determining the edge and discard the other two. Et cetera.

say I had a tetrahedron simplex and i wanted to reduce the simplex when i calculate the closest point to the origin on the tetrahedron, say the point lies on a face of the tetrahedron, would the simplex simply be the triangle that the point lies on?

Christer Ericson

http://realtimecollisiondetection.net/blog/

http://realtimecollisiondetection.net/blog/

###
#4
Moderators - Reputation: **10469**

Posted 30 September 2005 - 06:26 PM

Quote:

The objects i'm working with are convex

If you find GJK to be too much trouble for convex objects, you can use SAT, or a host of other, possibly more optimal, solutions for convex/convex testing. You probably already know that, but I figured I'd mention it.

###
#5
Members - Reputation: **145**

Posted 30 September 2005 - 10:47 PM

Thanks to AP for the post, you answered most of my questions, I should be able to finish this implementation in the next few days and to Christer, your notes and Slideshow from Siggraph 04 have been a huge help to me and your book on real time collision detection is in the mail :P

hplus0603, I've already got an implementation of the SAT for use with my Oriented Bounding Box Tree class. Thus far I'm quickly able to calculate if two objects are intersecting and i'm in the process of implementing GJK for determination of the penetration distance when two convex polyhedra collide

hplus0603, I've already got an implementation of the SAT for use with my Oriented Bounding Box Tree class. Thus far I'm quickly able to calculate if two objects are intersecting and i'm in the process of implementing GJK for determination of the penetration distance when two convex polyhedra collide