Esempio n. 1
0
def unique_signature(pts):
    """Similar to signature, it produces a string associated to the point set,
       but it is independent of the labelling of the point set.
       It runs in O(n^3 \logn) time"""
    pts=[x[:] for x in pts]
    D=points_index(pts)
    ch=convexhull.CH(pts)
    S=[]
    for p in ch:
        idx=D[tuple(p)]
        pts2=pts[:idx]
        pts2.extend(pts[idx+1:])
        pts2=geometricbasics.sort_around_point(p,pts2)
        pts2.append(p)
        S.append(signature(pts2))
    print S
    return min(S)
Esempio n. 2
0
def lambda_matrix(pts):
    """M[i,j] is the number of points of pts that lie to the LEFT
    of the edge (pts[i],pts[j])."""
    M=[[0 for i in xrange(len(pts))] for j in xrange(len(pts))]
    D=points_index(pts)
    n=len(pts)
    for i in xrange(n):
        tpts=pts[:i]
        tpts.extend(pts[i+1:])
        p=pts[i]
        #check whether we have the C++ version running correctly
        pts_sorted=geometricbasics.sort_around_point(p,tpts)
        k=0 
        for j in xrange(n-1):
            while (geometricbasics.turn(p,pts_sorted[j],pts_sorted[(k+1)%(n-1)])<=0 and
                    (k+1)%(n-1)!=j):
                k=k+1
            ni=(k-j)%(n-1)
            M[D[tuple(p)]][D[tuple(pts_sorted[j])]]=ni
    return M
Esempio n. 3
0
def _visible_points(n):        
    """Returns the first n points visibible from
        the origin in the integer grid."""
    V=[[1,0],[-1,0],[0,1],[0,-1]]
    gcd=_gcd_dict(n)
    k=2
    while len(V)<n:
        for i in range(1,k):
            j=k-i
            if gcd[i][j]==1:
                #V=V+[[i,j],[-i,-j]]
                V.append([i,j])
                V.append([-i,-j])
                if len(V)==n:
                    break
                #V=V+[[-i,j],[i,-j]]
                V.append([-i,j])
                V.append([i,-j])
                if len(V)==n:
                    break
        k=k+1
    #print k
    V=V[:n]
    return geometricbasics.sort_around_point([0,0],V)