quantities.py 文件源码

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

项目:crowddynamics 作者: jaantollander 项目源码 文件源码
def density_voronoi_2(points, cell_size):
    r"""Density definition base on Voronoi-diagram. [Steffen2010]_

    Compute Voronoi-diagram for each position :math:`\mathbf{p}_i` giving
    cells :math:`A_i` to each agent :math:`i`. Area of Voronoi cell is
    denoted :math:`|A_i|`. Area :math:`A` is the area inside which we
    measure the density.

    :math:`S = \{i : \mathbf{p}_i \in A\}` is the set of agents and
    :math:`N = |S|` the number of agents that is inside area :math:`A`.

    .. math::
        D_{V^\prime} = \frac{N}{\sum_{i \in S} |A_i|}

    Args:
        points (numpy.ndarray):
            Two dimensional points :math:`\mathbf{p}_{i \in \mathbb{N}}`
        cell_size (float):
            Cell size of the meshgrid. Each cell represents an area :math:`A`
            inside which density is measured.

    Returns:
        numpy.ndarray: Grid of values density values for each cell.

    """
    # Voronoi tesselation
    vor = Voronoi(points)
    new_regions, new_vertices = voronoi_finite_polygons_2d(vor)

    # Compute areas for all of the Voronoi regions
    area = np.array([polygon_area(new_vertices[i]) for i in new_regions])

    return _core_2(points, cell_size, area, vor.point_region)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号