Width of an arbitrary polygon

試著忘記壹切 提交于 2019-12-06 06:13:31

You can compute:

the size of its cross-section perpendicular to its diameter

with the following steps:

  1. Find the convex hull
  2. Find the two points a and b which are furthest apart
  3. Find the direction vector d = (a - b).normalized() between those two
  4. Rotate your axes so that this direction vector lies horizontal, using the matrix:

    [ d.x, d.y]
    [-d.y, d.x]
    
  5. Find the minimum and maximum y value of points in this new coordinate system. The difference is your "width"

Note that this is not a particularly good definition of "width" - a better one is:

The minimal perpendicular distance between two distinct parallel lines each having at least one point in common with the polygon's boundary but none with the polygon's interior


Another useful definition of size might be twice the average distance between points on the hull and the center

center = sum(convexhullpoints) / len(convexhullpoints)
size = 2 * sum(abs(p - center) for p in convexhullpoints) / len(convexhullpoints)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!