simplify.py 文件源码

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

项目:pyhiro 作者: wanweiwei07 项目源码 文件源码
def is_circle(points, scale, verbose=True):
    '''
    Given a set of points, quickly determine if they represent
    a circle or not. 
    '''

    # make sure input is a numpy array
    points = np.asanyarray(points)
    scale = float(scale)

    # can only be a circle if the first and last point are the 
    # same (AKA is a closed path)
    if np.linalg.norm(points[0] - points[-1]) > tol.merge:
        return None

    box = points.ptp(axis=0)
    # the bounding box size of the points
    # check aspect ratio as an early exit if the path is not a circle
    aspect = np.divide(*box)
    if np.abs(aspect - 1.0) > tol.aspect_frac: 
        return None

    # fit a circle with tolerance checks
    CR = fit_circle_check(points, scale=scale)
    if CR is None: 
        return None

    # return the circle as three control points
    control = angles_to_threepoint([0,np.pi*.5], *CR)
    return control
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号