Skip to content

Commit

Permalink
Improve termination condition
Browse files Browse the repository at this point in the history
  • Loading branch information
notgiven688 committed Dec 30, 2023
1 parent 047920d commit fbfd7e3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/GJKEPA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,16 @@ public bool Solve(out JVector point1, out JVector point2, out JVector normal, ou
}

ctri = Triangles[closestIndex];

JVector searchDir = ctri.ClosestToOrigin;
double searchDirSq = ctri.ClosestToOriginSq;

if (originEnclosed) searchDir.Negate();

if(ctri.ClosestToOriginSq < NumericEpsilon)
{
searchDir = ctri.Normal;
searchDirSq = ctri.NormalSq;
}

vPointer++;
Expand All @@ -338,14 +342,14 @@ public bool Solve(out JVector point1, out JVector point2, out JVector normal, ou
// Termination condition
// Can we further "extend" the convex hull by adding the new vertex?
//
// n = closest triangle normal
// v = Vertices[vPointer] (support point)
// c = Triangles[Head].ClosestToOrigin
// s = searchDir
//
// abs(dot(c - v, n)) / len(n) < e <=> [dot(c - v, n)]^2 = e*e*n^2
double deltaDist = JVector.Dot(ctri.ClosestToOrigin - Vertices[vPointer], ctri.Normal);
// abs(dot(c - v, s)) / len(s) < e <=> [dot(c - v, s)]^2 = e*e*s^2
double deltaDist = JVector.Dot(ctri.ClosestToOrigin - Vertices[vPointer], searchDir);

if(deltaDist * deltaDist < CollideEpsilon * CollideEpsilon * ctri.NormalSq)
if (deltaDist * deltaDist <= CollideEpsilon * CollideEpsilon * searchDirSq)
{
goto converged;
}
Expand Down

0 comments on commit fbfd7e3

Please sign in to comment.