polyCrystal.py 文件源码

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

项目:Graphene 作者: ashivni 项目源码 文件源码
def pointsInRegion(regNum, vor, p, overlap=0.0):
    """
    returns the subset of points p that are inside the regNum region of the voronoi object
    vor. The boundaries of the region are extended by an amount given by 'overlap'.
    """
    reg = vor.regions[vor.point_region[regNum]]  # region associated with the point
    if -1 in reg:
        raise Exception('Open region associated with generator')
    nVerts = len(reg)  # number of verticies in the region
    p0 = vor.points[regNum]

    for i in range(len(reg)):
        vert1, vert2 = vor.vertices[reg[i]], vor.vertices[reg[(i + 1) % len(reg)]]
        dr = vert1 - vert2  # edge
        dr = dr / numpy.linalg.norm(dr)  # normalize
        dn = numpy.array([dr[1], -dr[0]])  # normal to edge
        dn = dn if numpy.dot(dn, vert2 - p0[:2]) > 0 else -dn  # orient so that the normal is outwards
        d1 = numpy.einsum('i,ji', dn, vert2 + dn * overlap - p[:, :2])
        p = p[d1 * numpy.dot(dn, vert2 - p0[:2]) > 0]

    return p
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号