Concave and Convex Polygon - Turn arbitrary polygon into a convex polygon

后端 未结 4 1345
梦毁少年i
梦毁少年i 2021-02-15 14:47

How can I identify and remove those four RED points drawn in image \"alt

Those four points

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-15 15:06

    aioobe has it right—you sound as though you are looking to compute the convex hull of your polygon, in which case you want one of the convex hull algorithms like Graham scan or Chan's algorithm.

    However, if you just want to know whether an angle is convex or concave there's a quick way to compute this that avoids trigonometry.

    If A, B, and C are consecutive vertices going clockwise around the polygon, then the vertex at B is convex if

    (B − A) · (C − B) < 0

    Here V is a vector that's V rotated by 90° anti-clockwise, which can be computed like so: (xy) = (−yx).

提交回复
热议问题