6
$\begingroup$

I'm in search for an algorithm that takes the left side of the following graphic as an input and outputs a minimal amount of convex polygons as seen on the right side of the graphic.

input and output of the wanted algorithm

The input mesh can be very complex and could contain several holes. The position of the vertices are not constrained to a grid.

The use case for this is the creation of multiple polygon shapes for the Box2D physics engine.

Additional information:

  • The result does not need to be deterministic.
  • The result does not need to be vertically striped.
  • As trichoplax noted, the right part of the picture does not resemble the minimal polygon count that can be achieved. It's just an example.
  • It's not necessary that it will find the absolute minimum of convex polygons. A fast algorithm is preferred over a "best solution" one.
$\endgroup$
  • 1
    $\begingroup$ I notice that the example output is not minimal according to the definition (there exists an arrangement of 5 convex polygons that covers the mesh). Is this because it's just an example, or are there further requirements that prevent the 5 polygon output being valid? For instance, are the output polygons required to be in vertical strips of fixed width or is that just for the example image? $\endgroup$ – trichoplax Jul 7 '17 at 11:18
  • $\begingroup$ Thanks trichoplax. I've added the requested additional information to the question. Hope they clarify your questions. $\endgroup$ – Timm Jul 7 '17 at 11:41
  • $\begingroup$ I've identified the difference between the example output and the minimal one I was thinking of: Mine covers the area using convex polygons that use only the existing vertices, but do not use the existing triangles. The example output shows the minimal number of convex polygons if they are required to be constructed from the existing triangles. Is this a requirement? $\endgroup$ – trichoplax Jul 7 '17 at 15:13
  • 1
    $\begingroup$ No this is no requirement. The resulting polygons can be generated with any means available. The only requirement is, that the resulting shape is exactly the same as with triangles. $\endgroup$ – Timm Jul 7 '17 at 19:23
  • $\begingroup$ This problem is known as convex decomposition. See gamedev.stackexchange.com/q/53142, doc.cgal.org/latest/Partition_2/index.html#title2, masc.cs.gmu.edu/wiki/ACD $\endgroup$ – Rahul Jul 8 '17 at 5:02
1
$\begingroup$

If a edge corner is concave then it needs to border 2 of the output polygons.

So one algorithm would be to find all concave corners (including the ones in the holes) and making cuts starting from them to other concave corners. This will split the polygon in two or join 2 holes into 1 or connect a hole to the outside.

The cut from a concave corner should be constrained by the angle or it will create a new concave corner that then needs to be cut again.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.