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

FPE 3.0: Creating a PolygonShape is failing with Debug.Assert

Oct 20, 2010 at 4:47 PM
Edited Oct 21, 2010 at 4:14 PM

Hello, farseer noob here.

I'm trying to create a PolygonShape (green terrain) as shown in the video below:

(first vertex is the top left green edge and I add my vertices clockwise until I'm back at the start)


PolygonShape polygonShape = new PolygonShape(vertices); // vertices = 8 x Vector2's
Fixture polygonFixture = body.CreateFixture(polygonShape);


assert failing here in the FPE code:


            // Ensure the polygon is convex and the interior
            // is to the left of each edge.
            for (int i = 0; i < vertices.Count; ++i)
                int i1 = i;
                int i2 = i + 1 < vertices.Count ? i + 1 : 0;
                Vector2 edge = Vertices[i2] - Vertices[i1];

                for (int j = 0; j < vertices.Count; ++j)
                    // Don't check vertices on the current edge.
                    if (j == i1 || j == i2)

                    Vector2 r = Vertices[j] - Vertices[i1];

                    // Your polygon is non-convex (it has an indentation) or
                    // has colinear edges.
                    float s;
                    MathUtils.Cross(ref edge, ref  r, out s);

                    Debug.Assert(s > 0.0f); //FAILS HERE

I guess the obvious answer is that my shape is non-convex... if so, how to add a concave shape like in the video?


Oct 20, 2010 at 9:28 PM

FPE 3.0 only support convex shapes. If you add a concave shape, then you will have to decompose the concave shape into several convex shapes first. You can do that with one of the two decomposition tools inside FPE 3.0.

Oct 21, 2010 at 3:35 PM

I ended up chucking the PolygonShape and used "ConvertPathToPolygon" instead:

            FarseerPhysics.Common.Path farseerPath = new FarseerPhysics.Common.Path(vertices);

            farseerPath.Closed = true;

            PathManager.ConvertPathToPolygon(farseerPath, body, 1.0f, vertices.Count);

ConvertPathToPolygon does the decomposition for us :) worked great. Thanks!

Oct 22, 2010 at 2:39 AM

You could also use EarclipDecomposer or BayazitDecomposer directly as they may be much faster by themselves.