b2CollideEdgeAndPolygon

Hi,

I am having some weird results when trying to get the point count of a collision between a polygon (4 sided) and an edge (just a line). Maybe Im not understanding what a definition of a point is in a collision...

I have tried with the stable release as well as the most recent release (as of today) r206

// box2d 2.1.2
//b2CollidePolygons(&manifold, box_, *boxTransform_, poly2Region_, *poly2Transform_);

// box2d r206
b2CollideEdgeAndPolygon(&manifold, poly2Region_, *poly2Transform_,box_, *boxTransform_ );

points = manifold.pointCount;
Please provide the coordinates for the shapes and bodies.
Hi Erin - Thank you for your quick response!

I tried with many similar shapes and got same results, but this is the one from the images.

#define PTM_RATIO 32

// EDGE LINE
b2Vec2(10.f/PTM_RATIO,10.f/PTM_RATIO),b2Vec2(-40.f/PTM_RATIO,40.f/PTM_RATIO);

// POLYGON
b2Vec2 vertices[4];
vertices[0] = b2Vec2(-19.0/PTM_RATIO,-8.0/PTM_RATIO);
vertices[1] = b2Vec2(13.0/PTM_RATIO,-20.0/PTM_RATIO);
vertices[2] = b2Vec2(20.0/PTM_RATIO,57.0/PTM_RATIO);
vertices[3] = b2Vec2(5.0/PTM_RATIO,57.0/PTM_RATIO);

// this is another polygon I used that is more pronounced - seems like it only registered 2 points when near the top and bottom, but not in the middle.

/*
vertices[0] = b2Vec2(30.0/PTM_RATIO,40.0/PTM_RATIO);
vertices[1] = b2Vec2(-10.0/PTM_RATIO,40.0/PTM_RATIO);
vertices[2] = b2Vec2(0.0/PTM_RATIO,-40.0/PTM_RATIO);
vertices[3] = b2Vec2(15.0/PTM_RATIO,-40.0/PTM_RATIO);
*/
Thanks for the data. I tested these and got these pictures from the testbed.

Attachment:
Poly1.png
Poly1.png [ 5.55 KiB | Viewed 937 times ]


Attachment:
Poly2.png
Poly2.png [ 4.54 KiB | Viewed 937 times ]


In these cases we get just one contact point because the separating axis test determined that the shortest motion was along one of the polygon face normals. These are drawn as white lines. In that case it is correct to have a single contact point generated by one vertex of the edge. The other edge vertex is outside the polygon, so it generates no contact point.

I'm curious why your images look different than mine.
Hi - yes that scenario always shows one contact point for me, the issue I have is if I move the polygon so it makes 2 contacts in the middle of the polygon, in some positions it only return 1 contact point when it should be returning 2, can you move the poly with a mouse and display the contact points to see what i mean?

Try placing the polygon so that the left and right sides of it intersect the edge in the middle of the poly like in my screen shot.

thanks for your help.

edit: I added a movie to show what I mean.. thanks again for your time!!
Yeah, this is how the separating axis test works. Since that edge is short relative to the height of the polygon, there are some configurations where a sideways motion gives a shorter route to separation.

Original thread: https://box2d.org/forum/viewtopic.php?t=7538