凸包面积递增

Lau*_*šys 4 python math geometry

我想使用凸包在点列表周围画一条线。但是,我希望该面积大于最小凸包。我该如何实现这一目标。PS 我正在使用 ConvexHull 的 scipy.spatial 实现,但是它只找到点列表周围的最小区域。

在此输入图像描述

dan*_*sch 5

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

def PointsInCircum(eachPoint,r,n=100):
    return [(eachPoint[0] + math.cos(2*math.pi/n*x)*r,eachPoint[1] + math.sin(2*math.pi/n*x)*r) for x in range(0,n+1)]


def bufferPoints (inPoints, stretchCoef, n):
    newPoints = []
    for eachPoint in inPoints:
        newPoints += PointsInCircum(eachPoint, stretchCoef, n)
    newPoints = np.array(newPoints)
    newBuffer = ConvexHull (newPoints)

    return newPoints[newBuffer.vertices]


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)#Get the first convexHull (speeds up the next process)

    stretchCoef = 1.2
    pointsStretched = bufferPoints (points[convh.vertices], stretchCoef, n=10)
    plt.scatter(points[:,0], points[:,1])
    plt.scatter(pointsStretched[:,0], pointsStretched[:,1], color='r')
    plt.show() 
Run Code Online (Sandbox Code Playgroud)

所以我更新了上面的代码。它围绕第一组 ConvexHull 顶点创建一个点圆,然后创建一个新的 ConvexHull。

这是此代码图视图的输出