简体   繁体   中英

Python Py2D - Polygon convex decomposition (Polygon.convex_decompose()) adds extra area instead of decomposing a concave face into convex faves

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM