This project has moved and is read-only. For the latest updates, please go here.

Collision problems when creating a 4 vertices rectangle geom

May 14, 2009 at 8:25 PM


Why do I get wrong collisions (even full penetration) if I define my geoms like a 4 vertices only rectangle via CreatePolygonGeom() ? I see that CreateRectangleGeom() uses 4 vertices per edge (16 total) but, why ? Will do I have to be careful when defining my final irregular polygon geoms ?


May 14, 2009 at 8:29 PM

Collisions need polygons along the edges too, not only the ones required to define the geometry. You can get away with small geometries (and only polygons that define the shape), but not larger ones.

You can use Vertices.SubDivideEdges() to add more vertices along the edges.

May 15, 2009 at 7:29 AM


Thank you very much for the explanation and the tip.

Will a single call to Vertices.SubDivideEdges() be enough ? Do I have to repeat Vertices.SubDivideEdges() calls until my vertices achieve some requirement ?

Thanks again.

May 15, 2009 at 9:38 AM
Edited May 15, 2009 at 9:42 AM

the parameter for SubDivideEdges specifies the length of each segment. a rectangle with a side length of say 10 and subdivision of 0.1 should get you 10/0.1 = 100 vertices per side

btw: Farseer is very well documented, especially for an opensource project :) . have a look at the last chapter of the manual and the demos. there it says "sharp edges" are a problem, adjust the grid cell size.

something you might wanna check: do you know what the centroids are and how the behave? maybe your collision works fine but is just a little "off".

May 30, 2009 at 10:13 AM
Edited May 30, 2009 at 10:14 AM

Thank you very much for your reply, yovib. SubDivideEdges() worked like a charm on simple geometries (rectangles) but for complex ones it has extrange behaviour, but I haven't tested it in depth yet. I'll feedback if it keeps failing.

I will keep in mind your recomendation on adjusting grid cell size.

About centroids, yeah, I think I know what they are and how they work but they are giving me headaches :(



May 31, 2009 at 10:37 PM

some saint was writing an explanation about centroids lately:

Jun 2, 2009 at 11:00 AM


Thank you for the centroid FAQ. I'll print and stick it on the wall ;)