# GJK point-in-tetrahedron - capping the number of searches?

The very informative mollyrocket video has given me quite a lot to work with, but one thing that the video seems to suggest is that the algorithm should ideally run until it definitely determines whether or not there's a hit.

I was of the idea that if there's no collision, it would be obvious by testing the dot product of the latest point against the search direction; if it is not positive, then we did not pass the origin, so a tetrahedron which encloses the origin simply cannot be built.

In cases where there is a hit OR a clear miss, the routine typically picks up less than 11 loops through. However, as I tend towards 'questionable territory' and the definitive hit/miss is visually less distinct, there are times when the method apparently continues to pass the origin yet construct unsuccessful simplexes.

Is it common to cap this kind of function at a max number of tries? Right now I am somewhat arbitrarily using the number of points in one shape times the number of points in the other shape; in other words:

max_tries = len(shape1.pts) * len(shape2.pts)


It feels a bit hacky and I have to assume that the routine is geared towards simply running ad nauseum until it smacks into a clear hit/miss situation.

Has anyone experienced this before? Is this a problem or an anticipated safety measure in such an algorithm? If it needs to be done I'll gladly share some code, but I think it stands as self-evident that it is kind of a longer read than most code snippets so I've abstained for now.