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

后端 未结 12 1905
醉话见心
醉话见心 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:23

    I use simple geometry: Vectors and/or Trigonometry

    1. At each corner find the mid vector, and mid angle. Mid vector is the arithmetic average of the two unit vectors defined by the edges of the corner. Mid Angle is the half of the angle defined by the edges.

    2. If you need to expand (or contract) your polygon by the amount of d from each edge; you should go out (in) by the amount d/sin(midAngle) to get the new corner point.

    3. Repeat this for all the corners

    *** Be careful about your direction. Make CounterClockWise Test using the three points defining the corner; to find out which way is out, or in.

提交回复
热议问题