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 area of the result polygon
Thanks for taking a look! I would love to hear your solutions.
I got it to work! The problem was that I defined a closed polygon:
However
Py2D
assumes that the last given point connects with the first point. Thus by changing the code to:I got the expected result.