DeadPixel99's blog

By DeadPixel99, history, 14 months ago, In English

I'm struggling to find the idea behind solving this problem Polygon Cutting, anyone can help?

  • Vote: I like it
  • +15
  • Vote: I do not like it

»
14 months ago, # |
  Vote: I like it +23 Vote: I do not like it

Consider building a graph: there is a node representing each piece and the weight of that node is the area of the piece. An edge is added between two nodes whose corresponding pieces share an edge.

Claim: This graph is a tree.

Proof idea: Each line segment inside the polygon splits the remaining area into two disjoint parts, similar to how each edge in a tree splits it into two disjoint trees.

We can figure out the vertices of each piece and the edges of the tree with the help of a monotonic stack:

Let's go through the vertices of the polygon in clockwise order and for each vertex, let's go through line segments starting/ending there in counterclockwise order. We'll keep a stack of current pieces and add / remove them from the stack once we've completely considered them. With this we can figure out the vertices of each polygonal piece and the edges of the tree.

My explanation is not very clear, so hopefully this animation is helpful: https://i.imgur.com/AVYpK3J.gif (I don't know how to embed gifs properly)

Once we have the vertices of each polygonal piece, we can calculate their areas easily with the formula from CPH chapter 29.2 (page number 271, page 281 of the pdf).

The rest can be solved with standard tree dp where every node has two states: pick this node or don't pick this node. Transitions are simple.

I can provide code if needed.

  • »
    »
    14 months ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    ohhhhh got it thank you, I'll try to implement it myself <3.

  • »
    »
    14 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I didn't know this algorithm for building the graph. It's beautiful!

    I used another well-know algorithm for building the dual of a planar graph to solve this problem. There's a template in cp-algorithms for finding the faces of a planar graph and building the graph from them should be straight-forward.