atlas.py 文件源码

python
阅读 41 收藏 0 点赞 0 评论 0

项目:kingfisher 作者: peixian 项目源码 文件源码
def _region_centroid(self, vertices):
        """
        Finds the centroid of the voronoi region bounded by given vertices
        See: https://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon

        :param vertices: list of vertices that bound the region
        :type vertices: numpy array of vertices from the scipy.spatial.Voronoi.regions (e.g. vor.vertices[region + [region[0]], :])

        :return: list of centroids
        :rtype: np.array of centroids
        """
        signed_area = 0
        C_x = 0
        C_y = 0
        for i in range(len(vertices)-1):
            step = (vertices[i, 0]*vertices[i+1, 1])-(vertices[i+1, 0]*vertices[i, 1])
            signed_area += step
            C_x += (vertices[i, 0] + vertices[i+1, 0])*step
            C_y += (vertices[i, 1] + vertices[i+1, 1])*step
        signed_area = 1/2*signed_area
        C_x = (1.0/(6.0*signed_area))*C_x
        C_y = (1.0/(6.0*signed_area))*C_y
        return np.array([[C_x, C_y]])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号