1

How to decompose the polygon with self intersections to the set of simple polygons?

The input polygon P = {p1, ... pn} is given by the set of n vertices with the CCW orientation. I would like to perform a decposition to a set of m polygons P1, ..., Pm.

enter image description here

A simple walking along the segments from the intersection to the next one does not bring any effect; there are 2 segments with the same start point represented by the intersection point.

Probably, some lexicographical sort of edges may help...

justik
  • 4,145
  • 6
  • 32
  • 53
  • Question: is the NE inflexion point of P1 missing a node, or are some of the segments more complex that just (x1,y1) -> (x2, y2) – theMage Dec 21 '18 at 12:51
  • The problem is not well defined. Suppose you have a contour that looks like [this](https://upload.wikimedia.org/wikipedia/commons/thumb/8/8f/Winding_Number_Around_Point.svg/1200px-Winding_Number_Around_Point.svg.png). How many polygons do you want to get out of it? – n. m. could be an AI Dec 21 '18 at 13:37
  • My guess would be 3 – theMage Dec 21 '18 at 14:55
  • @theMage ok, then what about a [trefoil shape](https://upload.wikimedia.org/wikipedia/commons/thumb/b/b3/Blue_Trefoil_Knot.png/220px-Blue_Trefoil_Knot.png)? How many polygons should be produced? How do you reconcile the answer with the previous one? What rule determines which contour is to include or exclude from the answer? – n. m. could be an AI Dec 22 '18 at 07:00
  • Hey n.m., I don't really have an answer to your question - maybe @justik have. From the way the original problem is stated I assumed that it was limited to a 2D space, and a 2D representation of the trefoil shape would have 4 "polygons", but again, that ma making some assumptions that may not be correct – theMage Dec 22 '18 at 07:45

1 Answers1

1

Calculate all intersections, make new nodes and divide edges at intersections, for every node create list of adjacent edges.

Start from some point. Walk using the most CCW edge from current vertex (relative to the last edge). Add traversed edges to polygon and remove them (or mark). When you return to the same vertex, close polygon.

Repeat from the first vertex still having edges.

MBo
  • 77,366
  • 5
  • 53
  • 86
  • @ MBo: I am not sure, whether this strategy leads to the simple polygons. If we reach some intersection, there are 2 ways to go. However, only 1 of them (probably the shorter one) brings the simple polygon. – justik Dec 21 '18 at 12:42
  • No9t shorter, but "faster closing". When we start from the top point of P1, we go left, then down - into node with some edges. We choose edge up - the most "left" relative to old direction, then go left into initial point. – MBo Dec 21 '18 at 12:45
  • I think this is missing a step: "Check if the edge crosses any other edge, and if so, add another vertex at the point where they cross" (Note how those points are not yet present in the upper graph) This can also be done as a pre-processing step for all edges at once. – tobias_k Dec 21 '18 at 12:54
  • @tobias_k Aha, I looked at the second picture where all intersection are ready. – MBo Dec 21 '18 at 12:56
  • But how do you decide which path to follow at an intersection node with mutiple outgoing edges? – tobias_k Dec 21 '18 at 12:56
  • 2
    @tobias_k The most "left" one (the last in CCW order) – MBo Dec 21 '18 at 13:00