简体   繁体   中英

find the outline of adjacent polygons

I'm searching for a way to find the outline of two adjacent polygons.

The polygons are defined by a list of points ordered by occurrence in the polygon. In my use case, there are no overlapping polygons, there are no gaps between the polygons, and there are no polygons with "holes".

I want to calculate the outline of the two polygons without any "holes". These pictures show the expected results.

在此输入图像描述

I know that there are a lot of libraries for clipping polygons, but for most of them the performance is not very good because they work for any kind of polygon (with holes, overlapping polygons etc.). In my use case the algorithm has to work in real time for a lot of polygons (>20.000). How can I most efficiently calculate the outline?

Given

no overlapping polygons, there are no gaps between the polygons and there are no polygons with "holes"

the following algorithm should do the trick.

  1. Discard duplicate line segments.

  2. Compute the natural combinatorial embedding of what's left as a doubly connected edge list . Each segment gives rise to two nodes (half edges, reverses of each other, with one endpoint of the segment being the head (respectively, the tail) and the other being the tail (respectively, the head)), and each half edge links to the next half edge with the same head in counterclockwise order.

  3. Extract the faces. A face in the combinatorial embedding is a minimal, nonempty set of half edges such that, for each half edge e, the reverse of the next half edge from e is in the set. The set of faces is a partition of the half edges. See the ASCII art diagram below.

     U----V----W | | | | | | Z----Y----X 

    The infinite face is {U->Z, Z->Y, Y->X, X->W, W->V, V->U} . The next half edge from W->V is U->V . The reverse of the next half edge from W->V is V->U . The other faces are {U->V, V->Y, Y->Z, Z->U} and {V->W, W->X, X->Y, Y->V} .

  4. Retain only the infinite faces by summing signed counterclockwise angles and testing the sign. A finite face like {U->V, V->Y, Y->Z, Z->U} has negative sum

     /_UVY - 180 + /_VYZ - 180 + /_YZU - 180 + /_ZUV - 180 = 4 * (90 - 180) = -360. 

    The infinite face has positive sum

     /_UZY - 180 + /_ZYX - 180 + /_YXW - 180 + /_XWV - 180 + /_WVU - 180 + /_VUZ - 180 = 4 * (270 - 180) + 2 * (180 - 180) = 360. 

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