Skip to content

Square inside polygon results in no collision because of BiasGreaterThan. #6

@anon38

Description

@anon38

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

inline bool BiasGreaterThan( real a, real b )
{
  return a >= b;
}

Or doing what box2d does also works i.e.

...
const float k_tol = 0.1f * b2_linearSlop; 
if (separationB > separationA + k_tol)
...

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.

PolygonShape poly;
    Vec2 vertices[] = {Vec2(-0.5, -0.5), Vec2(0.5,-0.5), Vec2(0.5, 0.5), Vec2(-0.5,0.5)};
    poly.Set( vertices, 4 );
    Body *b1 = new Body(&poly,-1.6,0);
    b1->SetOrient(0);
    
    PolygonShape poly2;
    Vec2 vertices2[] = {Vec2( -3.740512982560686,  -0.5735584769983424), Vec2( -3.719614114679503,  -1.7226350555144725), Vec2( -2.4932647260279026,  -2.7316117009988794), Vec2( -0.8201915887684166,  -3.339520273224558), Vec2( 0.8485318324075104,  -3.768661315482074), Vec2( 1.4125001862587832,  -3.877552867283213), Vec2( 3.7734708786741002,  -2.3132118400651835), Vec2( 3.9056625143223886,  -2.053720640728945), Vec2( 3.9608941922040817,  -0.21303954202834152), Vec2( 3.4524715186551624,  1.0169073997947553), Vec2( 1.9124525889738742,  2.634607801080719), Vec2( 0.24731544222635193,  3.825379925658064), Vec2( -1.1199503300054676,  4.6035871781070306), Vec2( -3.0722506887204464,  2.6117852157357326)};
    poly2.Set( vertices2, 14);
    Body *b2 = new Body(&poly2,0,0);
    
    b2->SetOrient(0);

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions