I am trying to decompose some concave faces into convex faces that cover the same area as the original concave face. I found a package online that should be able to do this (http://sseemayer.github.io/Py2D/documentation/features/convex_decompose.html) however I do no get it to work.

I have tried it with the following lines of code: from py2d.Math import Polygon, Vector

P = Polygon [(2.00, 3.00), (3.00, 3.00), (3.00, 2.00), (4.00, 2.00), (4.00, 4.00), (2.00, 4.00), (2.00, 3.00)] P = Polygon.convex_decompose(P)

P than becomes: [Polygon [(3.00, 2.00), (3.00, 3.00), (2.00, 3.00)], Polygon [(2.00, 3.00), (2.00, 4.00), (4.00, 4.00), (4.00, 2.00), (3.00, 2.00), (2.00, 3.00)]]

Which is the area of the original face plus an extra triangle. I would have expected two (or more) convex polygons that cover the same area as the original polygon (see images).

The original polygon

The original polygonThe area of the result polygon
The combined area of the 'decomposed' polygons Expected polygons

Thanks for taking a look! I would love to hear your solutions.

1

There are 1 answers

0
Joost van den Assum On

I got it to work! The problem was that I defined a closed polygon:

P = Polygon [(2.00, 3.00), (3.00, 3.00), (3.00, 2.00), (4.00, 2.00), (4.00, 4.00), (2.00, 4.00), (2.00, 3.00)]

However Py2D assumes that the last given point connects with the first point. Thus by changing the code to:

P = Polygon [(2.00, 3.00), (3.00, 3.00), (3.00, 2.00), (4.00, 2.00), (4.00, 4.00), (2.00, 4.00)] 

P = Polygon.convex_decompose(P)

I got the expected result.