增加凸包的面积 [英] Incrementing area of convex hull

查看:177
本文介绍了增加凸包的面积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用凸包围着点列表绘制一条线。但是,我希望该区域比最小凸包更大。我如何做到这一点。附:我正在使用ConvexHull的scipy.spatial实现,但它只能找到围绕点列表的最小区域。




解决方案

这是一个解决纸上问题的想法:

  from scipy.spatial import ConvexHull 
import matplotlib.pyplot as plt
import numpy as np

if __name__ =='__main__ ':
points = np.array([[ - 2,3],[2,4],[-2,-2],[2,-1],[1,-1],[ - ] 0.5)])
plt.scatter(points [:,0],points [:,1])$ ​​b $ b plt.show()
convh = ConvexHull(points)

stretchCoef = 1.2
pointsStretched = points [convh.vertices] * stretchCoef
plt.scatter(points [:,0],points [:,1])$ ​​b $ b plt。 scatter(pointsStretched [:,0],pointsStretched [:,1],color ='r')
plt.show ()

pointsStretched找到新凸包的新点。
在这里使用拉伸系数是有用的,因为你在不同象限的凸体的每个顶点上都有点,但我认为你知道如何解决这个问题。一种方法是在拉伸的凸包中找到点,这些点与初始点的矢量相同。

I want to use convex hull to draw a line around a list of points. However, I would like for the area to be larger than just minimum convex hull. How do I achieve that. P.S. I am using scipy.spatial implementation of ConvexHull, however it finds only the minimum area around list of points.

解决方案

Here is an idea to solve the exact problem you have on paper:

from scipy.spatial  import ConvexHull
import matplotlib.pyplot as plt
import numpy as np

if __name__ == '__main__':
    points = np.array([[-2,3], [2,4], [-2,-2], [2,-1], [1,-1], [-0.5, 0.5]])
    plt.scatter(points[:,0], points[:,1])
    plt.show()
    convh = ConvexHull(points)

    stretchCoef = 1.2
    pointsStretched = points[convh.vertices]*stretchCoef
    plt.scatter(points[:,0], points[:,1])
    plt.scatter(pointsStretched[:,0], pointsStretched[:,1], color='r')
    plt.show()

pointsStretched find the new points for your new convex hull. Using a stretching coefficient works here because you have the points on each of the vertices of the convexhull on different quadrants, but I think you get the idea of how to solve this. One way is to find the points in your stretched convexhull, which will be along the same vector as the initial points.

这篇关于增加凸包的面积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆