An algorithm for inflating/deflating (offsetting, buffering) polygons

后端 未结 12 2089
醉话见心
醉话见心 2020-11-22 12:58

How would I "inflate" a polygon? That is, I want to do something similar to this:

\"alt

<
12条回答
  •  孤城傲影
    2020-11-22 13:18

    Sounds to me like what you want is:

    • Starting at a vertex, face anti-clockwise along an adjacent edge.
    • Replace the edge with a new, parallel edge placed at distance d to the "left" of the old one.
    • Repeat for all edges.
    • Find the intersections of the new edges to get the new vertices.
    • Detect if you've become a crossed polygon and decide what to do about it. Probably add a new vertex at the crossing-point and get rid of some old ones. I'm not sure whether there's a better way to detect this than just to compare every pair of non-adjacent edges to see if their intersection lies between both pairs of vertices.

    The resulting polygon lies at the required distance from the old polygon "far enough" from the vertices. Near a vertex, the set of points at distance d from the old polygon is, as you say, not a polygon, so the requirement as stated cannot be fulfilled.

    I don't know if this algorithm has a name, example code on the web, or a fiendish optimisation, but I think it describes what you want.

提交回复
热议问题