Volume of Voronoi cell (python)

前端 未结 2 765
春和景丽
春和景丽 2020-12-31 14:45

I\'m using Scipy 0.13.0 in Python 2.7 to calculate a set of Voronoi cells in 3d. I need to get the volume of each cell for (de)weighting output of a proprietary simulation.

2条回答
  •  难免孤独
    2020-12-31 15:25

    As was mentioned in comments, you can compute ConvexHull of each Voronoi cell. Since Voronoi cells are convex, you will get the proper volumes.

    def voronoi_volumes(points):
        v = Voronoi(points)
        vol = np.zeros(v.npoints)
        for i, reg_num in enumerate(v.point_region):
            indices = v.regions[reg_num]
            if -1 in indices: # some regions can be opened
                vol[i] = np.inf
            else:
                vol[i] = ConvexHull(v.vertices[indices]).volume
        return vol
    

    This method works in any dimensions

提交回复
热议问题