-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Square inside polygon results in no collision because of BiasGreaterThan. #6
Comments
Thanks for this post. I wrote that code ages ago... And it looks buggy. Here is what I use in my qu3e repo, which should be robust. // Artificial axis bias to improve frame coherence
const r32 kRelTol = r32( 0.95 );
const r32 kAbsTol = r32( 0.01 );
i32 axis;
r32 sMax;
q3Vec3 n;
r32 faceMax = q3Max( aMax, bMax );
if ( kRelTol * eMax > faceMax + kAbsTol )
{
axis = eAxis;
sMax = eMax;
n = nE;
}
else
{
if ( kRelTol * bMax > aMax + kAbsTol )
{
axis = bAxis;
sMax = bMax;
n = nB;
}
else
{
axis = aAxis;
sMax = aMax;
n = nA;
}
} So then to update our function here (no edge case, just two faces), it can look like: inline bool BiasGreaterThan( real a, real b )
{
const real k_relative = 0.95f;
const real k_absolute = 0.01f;
if (k_relative * a > b + k_absolute) {
return true;
} else {
return false;
}
} Would you like to submit a pull request? If not I can make the modification. Let me know! |
Wow thanks for the quick response! Your modification also fixes the issue. No more false negative intersections. However, I'm still experimenting with the bias in my engine (currently have sequential impulse solver+feature based contacts+warm starting working) to determine what is most stable. Interestingly enough, your original bias implementation was very stable with my stacking test cases (essentially just squares stacked in different nxm configurations). But I've come to realize that it is very dependent on the order of my pairs from the broadphase as this affects the distribution of the bias on each body. For example, when I add the bodies to the world in a reverse order, then the original bias becomes more unstable. Anyway, your change does indeed fix the bug of missing intersections, which was the most critical issue. So you can feel free to make the modification. I'm going to continue to experiment in my own engine with different biases to determine which is most stable. |
I'm finding that the BiasGreaterThan function results in cases where a square can get stuck in a polygon at certain positions. This seems to be because the wrong reference/incidence face gets picked. It appears to be fixed by simply changing BiasGreaterThan to a naive
Or doing what box2d does also works i.e.
This can happen if you spawn a square inside a polygon (with gravity off so the square doesn't move).
Here is an example case, but it's pretty noticeable if you spawn a square inside of any random convex polygon of appropriate size.
PolygontoPolygon(b2, b1); Will return false even though they do clearly intersect.
PolygontoPolygon(b1, b2); Will return true however.
But with the fixes mentioned above they both will return true.
The text was updated successfully, but these errors were encountered: