Intersection between two polygons

Hi, I am a new user of Box2D. I am trying to get the intersection between two polygons. Here is the code I have written
b2Vec2 vertices1[9];//PolygonA
vertices1[0].Set(0.0f, 0.0f);
vertices1[1].Set(1.0f, 0.0f);
vertices1[2].Set(1.5f, 0.5f);
vertices1[3].Set(1.5f, 1.0f);
vertices1[4].Set(1.3f, 1.3f);
vertices1[5].Set(1.0f, 1.5f);
vertices1[6].Set(0.5f, 1.5f);
vertices1[7].Set(0.3f, 1.3f);
vertices1[8].Set(0.0f, 0.5f);
int count1= 9;
b2PolygonShape* polygon1= new b2PolygonShape;
b2Transform transform1;
transform1.SetIdentity();
b2Vec2 vertices2[3];//PolygonB
vertices2[0].Set(.50f, 0.25f);
vertices2[1].Set(0.50f, 1.25f);
vertices2[2].Set(-0.5f, 1.25f);
int count2= 3;
b2PolygonShape* polygon2= new b2PolygonShape;
polygon2->Set(vertices2, count2);
b2Transform transform2;
transform2.SetIdentity();
b2Manifold* manifold= new b2Manifold;
b2CollidePolygons(manifold, polygon1, transform1, polygon2, transform2);
for(unsigned int i=0; i<manifold->pointCount; i++)
{
//cout<<
b2ManifoldPoint ipoint= manifold->points[i];
b2Vec2 point= ipoint.localPoint;


cout<<point.x<<","<<point.y<<endl;

}


I was expecting only one point (0.5,0.25) as it is the vertex of polygon B that is inside polygon A. But it is showing two points (0.5,0.25 and 0.5,0.52). Can anybody tell me why is it like this? What exactly manifold returns?
Thanks
Sagar
Try using b2WorldManifold as shown in the manual and in the testbed.
I tried with b2Worldmanifold. But it is not giving me the points as I am expecting. I am little bit confused with what is manifold and what exactly it returns. Does it return the vertex of polygon B that is inside polygon A. Are manifold.localPoint and manifold.points[] different? What points are they referring to? Thanks.
Sagar
You can download my presentation from 2006 to see how the contact points are computed:
http://code.google.com/p/box2d/downloads/list

b2Manifold holds data in local coordinates while b2WorldManifold resolves points into world coordinates.
Hi Erin, I looked into your presentation. I guess, I dont have that much background to understand the material. I want to use Box2d only to find out the contact points between two polygons or a polygon and a circle. I used b2WorldManifold.points to find out the contact points. I attached two test cases to this email. I did not find the exact contact point but a point very close to that. I am just wondering, is there any way to get the exact contact points using box2D. I will really appreciate if you take a look at the attached test cases and give me little bit more insight why it is giving these points rather than the actual contact points. I have my own simulation code. I just want to integrate some collision information to my simulation code. Thanks.
Sagar
In Box2D polygons are wrapped with a thin skin that is used for continuous collision detection. See b2_polygonRadius. This is why the contact point may not be exactly where you expect it. In the case of deep penetration, the choice of the contact point becomes somewhat arbitrary.
Thank you so much. By setting b2_polygonRadius to zero I was able to get the exact contact points.

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