Пример #1
0
    def layfootprints(r, t, e):
        eseam, seams, loops = pym.pgtopy(r, 5, e, findeseam=True)
        ebnd = seams[eseam]
        eloop = loops[eseam]
        k = 0
        easement = None
        for j in range(len(ebnd)):
            road = r.es[r.elook[(eloop[k - 1], eloop[k])]]
            edge = (ebnd[j - 1], ebnd[j])
            tang = edge[0].tov(edge[1])
            norm = tang.crs(vec3(0, 0, 1)).nrm()
            p1 = edge[0].cp().trn(tang.cp().uscl(0.0))
            p2 = edge[0].cp().trn(tang.cp().uscl(1.0))
            p3 = p2.cp().trn(norm.uscl(10))
            p4 = p1.cp().trn(norm)
            newfp = [p1, p2, p3, p4]
            newfp = pym.contract(newfp, 2)
            newfp = pym.ebdxy(newfp, ebnd)[0]
            newfp = (newfp, [])
            preasement = easement
            if easement is None: easement = newfp
            else: easement = pym.epuxy(easement, newfp)[0]
            if not eloop[k] == eloop[k - 2]: k += 1

            if False and j > 85:
                print('walk', j, len(eloop), len(ebnd))
                ax = dtl.plot_axes_xy(300)
                ax = dtl.plot_polygon_xy(ebnd, ax, lw=3, col='b')
                ax = dtl.plot_points_xy(ebnd, ax, number=True)
                ax = dtl.plot_edges_xy(edge, ax, lw=7, col='r')
                ax = dtl.plot_polygon_full_xy(easement, ax, lw=5, col='g')
                if preasement:
                    ax = dtl.plot_polygon_full_xy(preasement,
                                                  ax,
                                                  lw=3,
                                                  col='m')
                plt.show()

        #easement = pym.bsuxy(easement,e)
        fps = ([easement], [[] for l in range(len(loops) - 1)])
        # generate a set of footprints connected to road
        # footprint must not overlap interiors with ebnd
        ax = dtl.plot_axes_xy(300)
        ax = dtl.plot_polygon_xy(ebnd, ax, lw=3, col='b')
        for fp in fps[0]:
            ax = dtl.plot_polygon_full_xy(fp, ax, lw=3, col='g')
        plt.show()

        return fps
Пример #2
0
def ajagged(b,epsilon):
    j = random.randint(0,len(b)-1)
    l = b[j-1].d(b[j])
    t = random.uniform(0,2.0*numpy.pi)
    n = random.randint(3,8)

    stamp = b[j-1].mid(b[j]).pring(l/2.0,n)
    q = quat(1,0,0,0).av(t,vec3(0,0,1))
    q.rotps(stamp)
    
    if pym.bintbxy(b,stamp,col = False,ie = False):
        nbs = pym.ebdxy(b,stamp,epsilon)
        nbas = [pym.bareaxy(nb) for nb in nbs]
        nb = nbs[nbas.index(max(nbas))]
        nb = pym.aggregate(nb,1)
        if pym.bvalidxy(nb) > 0:b = nb

    bval = pym.bvalidxy(b)
    if bval == -1:b.reverse()
    if not pym.bvalidxy(b) > 0:
        ax = dtl.plot_axes_xy(700)
        ax = dtl.plot_polygon_xy(b,ax,lw = 4,col = 'b')
        ax = dtl.plot_points_xy(b,ax,number = True)
        ax = dtl.plot_polygon_xy(stamp,ax,lw = 2,col = 'r')
        plt.show()
        #pdb.set_trace()
        raise ValueError
    
    return b
Пример #3
0
    def aaatest(self):
        #i = 5
        i = 6
        p, d = vec3(0, 0, 0), vec3(0, 1, 0)
        axiom = 'X'
        rules = dict([('X', '{[[X}{]X}F]X'), ('F', 'FA'), ('A', 'F')])
        #rules = dict([('X','F{[X}{]X}FX'),('F','FF')])
        #axiom = 'F'
        #rules = dict([('F','F{[F}F{]F}F')])
        params = dict(dazimuthal=gtl.rad(25.7), drho=20)

        pg = dpg.planargraph()
        for piece in lsy.lgen(p, d, axiom, rules, i, **params):
            if isinstance(piece, tuple):
                p1, p2 = piece
                v1, v2 = pg.fp(p1, 10), pg.fp(p2, 10)
                e12 = pg.fe(v1, v2)
            elif isinstance(piece, vec3):
                pass

        py = pym.pgtopy(pg, 1)[0]
        py = pym.bisectb(py)
        py = pym.smoothxy(py, 0.5, 2)
        #py = pym.aggregate(py,2)

        #ax = pg.plotxy(l = 20)
        ax = dtl.plot_axes_xy(20)
        ax = dtl.plot_polygon_xy(py, ax, lw=3)
        plt.show()
Пример #4
0
 def plotxy(self, ax=None):
     scale = vec3(1, 0, 0).prjps(self.footprint)
     scale = scale[1] - scale[0]
     if ax is None: ax = dtl.plot_axes_xy(scale)
     for vx in range(self.vcnt):
         v = self.vs[vx]
         if v is None: continue
         vb = v[1]['fp']
         vrtls = '-' if 'developed' in v[1]['type'] else '--'
         #vrtls = '--' if 'natural' in v[1]['type'] else '-'
         ax = dtl.plot_polygon_xy(pym.contract(vb, 0.01 * scale),
                                  ax,
                                  lw=2,
                                  ls=vrtls,
                                  col=None)
         vbc = vec3(0, 0, 0).com(vb)
         rs = str(vx) + ',' + str(v[1]['edges']) + ',\n' + str(v[1]['type'])
         ax = dtl.plot_point_xy_annotate(vbc, ax, rs)
         for ve in v[1]['edges']:
             if self.vs[ve] is None: continue
             ovbc = vec3(0, 0, 0).com(self.vs[ve][1]['fp'])
             ax = dtl.plot_edges_xy((vbc, ovbc), ax, lw=3, col='c')
         for ep in v[1]['exits']:
             ax = dtl.plot_point_xy(ep, ax, mk='s', col='r')
     ax = dtl.plot_polygon_xy(self.footprint, ax, lw=1, col='g')
     return ax
Пример #5
0
    def aaatest(self):
        #i = 5
        i = 6
        p,d = vec3(0,0,0),vec3(0,1,0)
        axiom = 'X'
        rules = dict([('X','{[[X}{]X}F]X'),('F','FA'),('A','F')])
        #rules = dict([('X','F{[X}{]X}FX'),('F','FF')])
        #axiom = 'F'
        #rules = dict([('F','F{[F}F{]F}F')])
        params = dict(dazimuthal = gtl.rad(25.7),drho = 20)
        
        pg = dpg.planargraph()
        for piece in lsy.lgen(p,d,axiom,rules,i,**params):
            if isinstance(piece,tuple):
                p1,p2 = piece
                v1,v2 = pg.fp(p1,10),pg.fp(p2,10)
                e12 = pg.fe(v1,v2)
            elif isinstance(piece,vec3):pass

        py = pym.pgtopy(pg,1)[0]
        py = pym.bisectb(py)
        py = pym.smoothxy(py,0.5,2)
        #py = pym.aggregate(py,2)

        #ax = pg.plotxy(l = 20)
        ax = dtl.plot_axes_xy(20)
        ax = dtl.plot_polygon_xy(py,ax,lw = 3)
        plt.show()
Пример #6
0
def pgbleed(pg, r, epsilon=0.1):

    # get a copy of the points of the graph without
    # duplicates within neighborhood of epsilon
    ps = []
    for vx in range(pg.vcnt):
        ps.append(pg.fp(pg.vs[vx][1]['p'], epsilon))

    pdb.set_trace()


    '''#
                    ax = dtl.plot_axes_xy(200)
                    ax = dtl.plot_edges_xy(seam,ax,lw = 2,col = 'k')
                    ax = dtl.plot_edges_xy((s1,s2),ax,col = 'b')
                    ax = dtl.plot_edges_xy((s3,s4),ax,col = 'g')
                    ax = dtl.plot_point_xy(ip,ax,mk = 's')
                    plt.show()
    '''#

    py = [eb, ibs]

    ax = dtl.plot_axes_xy(200)
    ax = dtl.plot_polygon_full_xy(py, ax, lw=2, col='k')
    plt.show()

    return py
Пример #7
0
def chunk(b,epsilon,lscl = 1.0,j1 = None,j2 = None,edge = False):
    if j1 is None:j1 = random.randint(0,len(b)-1)
    if j2 is None:j2 = j1-1
    l = b[j1].d(b[j2])*lscl
    t = random.uniform(0,2.0*numpy.pi)
    n = random.randint(3,8)

    if edge:
        stamp = b[j1].mid(b[j2]).pring(l/2.0,n)
    else:
        stamp = vec3(
            random.randint(int(l/4),int(l)),
            random.randint(int(l/4),int(l)),
            0).com(b).pring(l/2.0,n)
    q = quat(1,0,0,0).av(t,vec3(0,0,1))
    q.rotps(stamp)
    
    if pym.binbxy(stamp,b):
        return stamp
    elif pym.bintbxy(b,stamp,col = False,ie = False):
        nbs = pym.ebixy(b,stamp,epsilon)
        nbas = [pym.bareaxy(nb) for nb in nbs]
        nb = nbs[nbas.index(max(nbas))]
        nb = pym.aggregate(nb,1)
        if pym.bvalidxy(nb) > 0:
            return nb
    else:
        ax = dtl.plot_axes_xy(200)
        ax = dtl.plot_polygon_xy(b,ax,col = 'r',lw = 2)
        ax = dtl.plot_polygon_xy(stamp,ax,col = 'b',lw = 2)
        plt.show()
        raise ValueError
Пример #8
0
def chunk(b, epsilon, lscl=1.0, j1=None, j2=None, edge=False):
    if j1 is None: j1 = random.randint(0, len(b) - 1)
    if j2 is None: j2 = j1 - 1
    l = b[j1].d(b[j2]) * lscl
    t = random.uniform(0, 2.0 * numpy.pi)
    n = random.randint(3, 8)

    if edge:
        stamp = b[j1].mid(b[j2]).pring(l / 2.0, n)
    else:
        stamp = vec3(random.randint(int(l / 4), int(l)),
                     random.randint(int(l / 4), int(l)),
                     0).com(b).pring(l / 2.0, n)
    q = quat(1, 0, 0, 0).av(t, vec3(0, 0, 1))
    q.rotps(stamp)

    if pym.binbxy(stamp, b):
        return stamp
    elif pym.bintbxy(b, stamp, col=False, ie=False):
        nbs = pym.ebixy(b, stamp, epsilon)
        nbas = [pym.bareaxy(nb) for nb in nbs]
        nb = nbs[nbas.index(max(nbas))]
        nb = pym.aggregate(nb, 1)
        if pym.bvalidxy(nb) > 0:
            return nb
    else:
        ax = dtl.plot_axes_xy(200)
        ax = dtl.plot_polygon_xy(b, ax, col='r', lw=2)
        ax = dtl.plot_polygon_xy(stamp, ax, col='b', lw=2)
        plt.show()
        raise ValueError
Пример #9
0
 def plotxy(self,fp = None,ax = None):
     if ax is None:ax = dtl.plot_axes_xy(50)
     for rmv in self.vs:
         if rmv is None:continue
         if rmv[2]['level'] > 0:continue
         bcol = 'b' if rmv[2]['shaft'] else None
         rconbs = 0.5 if pym.bccw(rmv[2]['bound']) else -0.5
         rconb = pym.contract(rmv[2]['bound'],rconbs)
         ax = dtl.plot_polygon_xy(rconb,ax,lw = 4,col = bcol)
         rc = vec3(0,0,0).com(rmv[2]['bound'])
         rs = str(rmv[0])+','+str(rmv[1])
         ax = dtl.plot_point_xy(rc,dtl.plot_point_xy_annotate(rc,ax,rs))
         if rmv[1]:
             for re in rmv[1]:
                 if self.vs[re] is None:continue
                 rt = (rc,vec3(0,0,0).com(self.vs[re][2]['bound']))
                 ax = dtl.plot_edges_xy(rt,ax,col = 'g')
         for exit in rmv[2]['exits']:
             if exit is True:
                 exitp = rc
                 ax = dtl.plot_point_xy(exitp,
                     dtl.plot_point_xy_annotate(exitp,ax,'exit'))
             else:
                 ax = dtl.plot_point_xy(exit,
                     dtl.plot_point_xy_annotate(exit,ax,'exit'))
     if not fp is None:
         ax = dtl.plot_polygon_xy(fp,ax,lw = 2,col = 'r')
     return ax
Пример #10
0
 def pl(b1, b2, br):
     ax = dtl.plot_axes_xy(20)
     ax = dtl.plot_polygon_xy(b1, ax, col='b', lw=5.0)
     ax = dtl.plot_polygon_xy(b2, ax, col='g', lw=5.0)
     for b in br:
         ax = dtl.plot_polygon_xy(b, ax, col='r', lw=2.0)
     plt.show()
Пример #11
0
 def plotxy(self, fp=None, ax=None):
     if ax is None: ax = dtl.plot_axes_xy(50)
     for rmv in self.vs:
         if rmv is None: continue
         if rmv[2]['level'] > 0: continue
         bcol = 'b' if rmv[2]['shaft'] else None
         rconbs = 0.5 if pym.bccw(rmv[2]['bound']) else -0.5
         rconb = pym.contract(rmv[2]['bound'], rconbs)
         ax = dtl.plot_polygon_xy(rconb, ax, lw=4, col=bcol)
         rc = vec3(0, 0, 0).com(rmv[2]['bound'])
         rs = str(rmv[0]) + ',' + str(rmv[1])
         ax = dtl.plot_point_xy(rc, dtl.plot_point_xy_annotate(rc, ax, rs))
         if rmv[1]:
             for re in rmv[1]:
                 if self.vs[re] is None: continue
                 rt = (rc, vec3(0, 0, 0).com(self.vs[re][2]['bound']))
                 ax = dtl.plot_edges_xy(rt, ax, col='g')
         for exit in rmv[2]['exits']:
             if exit is True:
                 exitp = rc
                 ax = dtl.plot_point_xy(
                     exitp, dtl.plot_point_xy_annotate(exitp, ax, 'exit'))
             else:
                 ax = dtl.plot_point_xy(
                     exit, dtl.plot_point_xy_annotate(exit, ax, 'exit'))
     if not fp is None:
         ax = dtl.plot_polygon_xy(fp, ax, lw=2, col='r')
     return ax
Пример #12
0
def pgbleed(pg,r,epsilon = 0.1):

    # get a copy of the points of the graph without 
    # duplicates within neighborhood of epsilon
    ps = []
    for vx in range(pg.vcnt):
        ps.append(pg.fp(pg.vs[vx][1]['p'],epsilon))

    pdb.set_trace()


    '''#
                    ax = dtl.plot_axes_xy(200)
                    ax = dtl.plot_edges_xy(seam,ax,lw = 2,col = 'k')
                    ax = dtl.plot_edges_xy((s1,s2),ax,col = 'b')
                    ax = dtl.plot_edges_xy((s3,s4),ax,col = 'g')
                    ax = dtl.plot_point_xy(ip,ax,mk = 's')
                    plt.show()
    '''#

    py = [eb,ibs]

    ax = dtl.plot_axes_xy(200)
    ax = dtl.plot_polygon_full_xy(py,ax,lw = 2,col = 'k')
    plt.show()

    return py
Пример #13
0
def ajagged(b, epsilon):
    j = random.randint(0, len(b) - 1)
    l = b[j - 1].d(b[j])
    t = random.uniform(0, 2.0 * numpy.pi)
    n = random.randint(3, 8)

    stamp = b[j - 1].mid(b[j]).pring(l / 2.0, n)
    q = quat(1, 0, 0, 0).av(t, vec3(0, 0, 1))
    q.rotps(stamp)

    if pym.bintbxy(b, stamp, col=False, ie=False):
        nbs = pym.ebdxy(b, stamp, epsilon)
        nbas = [pym.bareaxy(nb) for nb in nbs]
        nb = nbs[nbas.index(max(nbas))]
        nb = pym.aggregate(nb, 1)
        if pym.bvalidxy(nb) > 0: b = nb

    bval = pym.bvalidxy(b)
    if bval == -1: b.reverse()
    if not pym.bvalidxy(b) > 0:
        ax = dtl.plot_axes_xy(700)
        ax = dtl.plot_polygon_xy(b, ax, lw=4, col='b')
        ax = dtl.plot_points_xy(b, ax, number=True)
        ax = dtl.plot_polygon_xy(stamp, ax, lw=2, col='r')
        plt.show()
        #pdb.set_trace()
        raise ValueError

    return b
Пример #14
0
    def test_ccwboxes(self):
        container = db.persistent_container('dump','boxes')
        if container.load():boxes = container.data
        blgfps = pym.ebuxy_special(boxes)

        ax = dtl.plot_axes_xy(200)
        for b in boxes:ax = dtl.plot_polygon_xy(b,ax,lw = 2,col = 'g')
        plt.show()
Пример #15
0
 def pl(bs):
     ax = dtl.plot_axes_xy(10)
     ax = dtl.plot_polygon_xy(b,ax,col = 'g',lw = 2)
     ax = dtl.plot_edges_xy((s1,s2),ax,col = 'r',lw = 1)
     for bpy in bs:
         bpy = pym.contract(bpy,0.1)
         ax = dtl.plot_polygon_xy(bpy,ax,col = 'b',lw = 4)
     plt.show()
Пример #16
0
 def pl(b1,b2,br):
     ax = dtl.plot_axes_xy()
     ax = dtl.plot_polygon_xy(b1,ax,col = 'b',lw = 5.0)
     ax = dtl.plot_polygon_xy(b2,ax,col = 'g',lw = 5.0)
     for be in br:
         ax = dtl.plot_edges_xy(be,ax,mk = 's',col = 'r',lw = 2.0)
     #ax = dtl.plot_polygon_xy(br,ax,mk = 's',col = 'r',lw = 2.0)
     plt.show()
Пример #17
0
 def pl(bs):
     ax = dtl.plot_axes_xy(10)
     ax = dtl.plot_polygon_xy(b, ax, col='g', lw=2)
     ax = dtl.plot_edges_xy((s1, s2), ax, col='r', lw=1)
     for bpy in bs:
         bpy = pym.contract(bpy, 0.1)
         ax = dtl.plot_polygon_xy(bpy, ax, col='b', lw=4)
     plt.show()
Пример #18
0
 def pl(b1, b2, br):
     ax = dtl.plot_axes_xy()
     ax = dtl.plot_polygon_xy(b1, ax, col='b', lw=5.0)
     ax = dtl.plot_polygon_xy(b2, ax, col='g', lw=5.0)
     for be in br:
         ax = dtl.plot_edges_xy(be, ax, mk='s', col='r', lw=2.0)
     #ax = dtl.plot_polygon_xy(br,ax,mk = 's',col = 'r',lw = 2.0)
     plt.show()
Пример #19
0
 def plotxy(self,ax = None,l =300):
     if ax is None:ax = dtl.plot_axes_xy(l)
     def pv(v,ax):
         ax = dtl.plot_polygon_xy(v.loop,ax,lw = 2)
         #for c in self.looptree.below(v):pv(c,ax)
         for c in self.below(v):pv(c,ax)
     pv(self.root,ax)
     return ax
Пример #20
0
    def test_ccwboxes(self):
        container = db.persistent_container('dump', 'boxes')
        if container.load(): boxes = container.data
        blgfps = pym.ebuxy_special(boxes)

        ax = dtl.plot_axes_xy(200)
        for b in boxes:
            ax = dtl.plot_polygon_xy(b, ax, lw=2, col='g')
        plt.show()
Пример #21
0
 def pl(s11,s12,s21,s22):
     ax = dtl.plot_axes_xy(1.5)
     ax = dtl.plot_point_xy(s11,dtl.plot_point_xy_annotate(s11,ax,'s11'),col = 'b')
     ax = dtl.plot_point_xy(s12,dtl.plot_point_xy_annotate(s12,ax,'s12'),col = 'b')
     ax = dtl.plot_point_xy(s21,dtl.plot_point_xy_annotate(s21,ax,'s21'),col = 'g')
     ax = dtl.plot_point_xy(s22,dtl.plot_point_xy_annotate(s22,ax,'s22'),col = 'g')
     ax = dtl.plot_vector_xy(s11,s11.tov(s21),ax,lw = 5.0,col = 'r')
     ax = dtl.plot_vector_xy(s11,s11.tov(s12),ax,lw = 2.0,col = 'b')
     ax = dtl.plot_vector_xy(s21,s21.tov(s22),ax,lw = 2.0,col = 'g')
     plt.show()
Пример #22
0
def ebuxy(b1, b2, epsilon=0.1, debug=False, holes=False):
    b1segs, b2segs = bsegbxy(b1, b2), bsegbxy(b2, b1)
    bo = lambda s1, s2, b: s1.mid(s2).inbxy(b)

    def inn(p):
        pn = vec3(0, 0, 1).crs(p[0].tov(p[1])).nrm().uscl(2 * epsilon)
        pm = p[0].mid(p[1])
        ep = pm.cp().trn(pn)
        if not ep.inbxy(b1) and not ep.inbxy(b2): return False
        ep = pm.cp().trn(pn.flp())
        if not ep.inbxy(b1) and not ep.inbxy(b2): return False
        return True

    b1inb2 = [p for p in b1segs if bo(p[0], p[1], b2)]
    b2inb1 = [p for p in b2segs if bo(p[0], p[1], b1)]
    b1only = [p for p in b1segs if not p in b1inb2 and not inn(p)]
    b2only = [p for p in b2segs if not p in b2inb1 and not inn(p)]
    dfs = sloops(b1only + b2only, epsilon)

    if debug:
        ax = dtl.plot_axes_xy(200)
        ax = dtl.plot_polygon_xy(b2, ax, lw=2, col='m')
        for edge in b1segs:
            ax = dtl.plot_edges_xy(edge, ax, lw=5, col='b')
        for edge in b1only:
            ax = dtl.plot_edges_xy(edge, ax, lw=8, col='b')
        for edge in b1inb2:
            ax = dtl.plot_edges_xy(edge, ax, lw=3, col='g')
        #for edge in b2only:
        #    ax = dtl.plot_edges_xy(edge,ax,lw = 5,col = 'g')
        plt.show()

    if len(dfs) > 1:
        edfs = 0
        for jdfs, lp in enumerate(dfs):
            if binbxy(dfs[edfs], lp, ie=0):
                edfs = jdfs
        if holes:
            print('genus of ebuxy changed!')
            return [(dfs.pop(edfs), dfs)]
        else:
            print('discarding holes resulting from ebuxy!')
            return [dfs[edfs]]
        '''
        print('promisedland?')
        ax = dtl.plot_axes_xy(200)
        ax = dtl.plot_polygon_xy(dfs[edfs],ax,lw = 7,col = 'r')
        ax = dtl.plot_polygon_xy(dfs[0],ax,lw = 5,col = 'b')
        ax = dtl.plot_polygon_xy(dfs[1],ax,lw = 3,col = 'g')
        #ax = dtl.plot_polygon_xy(b1,ax,ls = '-.',lw = 5,col = 'k')
        #ax = dtl.plot_polygon_xy(b2,ax,ls = '--',lw = 5,col = 'k')
        plt.show()
        '''
    if holes: return [(dfs[0], [])]
    else: return dfs
Пример #23
0
 def pl(s1, s2, s3, s4):
     ax = dtl.plot_axes_xy(10)
     ax = dtl.plot_edges_xy([s1, s2], ax, lw=2, col='b')
     ax = dtl.plot_edges_xy([s3, s4], ax, lw=2, col='g')
     ip = pym.sintsxyp(s1, s2, s3, s4)
     if type(ip) == type(()):
         ax = dtl.plot_point_xy(ip[0], ax, mk='o', col='r')
         ax = dtl.plot_point_xy(ip[1], ax, mk='s', col='r')
     elif not ip is None:
         ax = dtl.plot_point_xy(ip, ax, mk='o', col='r')
     plt.show()
Пример #24
0
 def pl(s1,s2,s3,s4):
     ax = dtl.plot_axes_xy(10)
     ax = dtl.plot_edges_xy([s1,s2],ax,lw = 2,col = 'b')
     ax = dtl.plot_edges_xy([s3,s4],ax,lw = 2,col = 'g')
     ip = pym.sintsxyp(s1,s2,s3,s4)
     if type(ip) == type(()):
         ax = dtl.plot_point_xy(ip[0],ax,mk = 'o',col = 'r')
         ax = dtl.plot_point_xy(ip[1],ax,mk = 's',col = 'r')
     elif not ip is None:
         ax = dtl.plot_point_xy(ip,ax,mk = 'o',col = 'r')
     plt.show()
Пример #25
0
    def test_intrixy(self):
        a = vec3(-93.6169662475586, 46.23309326171875, 0.0)
        b = vec3(28.083663940429688, 48.28422546386719, 0.0)
        c = vec3(25.696874618530273, 48.28422546386719, 0.0)
        p = vec3(-93.34214782714844, 43.73178482055664, 0.0)
        i = p.intrixy(a, b, c)
        self.assertFalse(i)

        ax = dtl.plot_axes_xy(100)
        ax = dtl.plot_points_xy((a, b, c, p), ax)
        ax = dtl.plot_polygon_xy((a, b, c), ax, lw=2, col='g')
        plt.show()
Пример #26
0
    def test_intrixy(self):
        a = vec3(-93.6169662475586, 46.23309326171875, 0.0)
        b = vec3(28.083663940429688, 48.28422546386719, 0.0)
        c = vec3(25.696874618530273, 48.28422546386719, 0.0)
        p = vec3(-93.34214782714844, 43.73178482055664, 0.0)
        i = p.intrixy(a,b,c)
        self.assertFalse(i)

        ax = dtl.plot_axes_xy(100)
        ax = dtl.plot_points_xy((a,b,c,p),ax)
        ax = dtl.plot_polygon_xy((a,b,c),ax,lw = 2,col = 'g')
        plt.show()
Пример #27
0
def ebuxy(b1,b2,epsilon = 0.1,debug = False,holes = False):
    b1segs,b2segs = bsegbxy(b1,b2),bsegbxy(b2,b1)
    bo = lambda s1,s2,b : s1.mid(s2).inbxy(b)
    def inn(p):
        pn = vec3(0,0,1).crs(p[0].tov(p[1])).nrm().uscl(2*epsilon)
        pm = p[0].mid(p[1])
        ep = pm.cp().trn(pn)
        if not ep.inbxy(b1) and not ep.inbxy(b2):return False
        ep = pm.cp().trn(pn.flp())
        if not ep.inbxy(b1) and not ep.inbxy(b2):return False
        return True
    b1inb2 = [p for p in b1segs if bo(p[0],p[1],b2)]
    b2inb1 = [p for p in b2segs if bo(p[0],p[1],b1)]
    b1only = [p for p in b1segs if not p in b1inb2 and not inn(p)]
    b2only = [p for p in b2segs if not p in b2inb1 and not inn(p)]
    dfs = sloops(b1only+b2only,epsilon)

    if debug:
        ax = dtl.plot_axes_xy(200)
        ax = dtl.plot_polygon_xy(b2,ax,lw = 2,col = 'm')
        for edge in b1segs:
            ax = dtl.plot_edges_xy(edge,ax,lw = 5,col = 'b')
        for edge in b1only:
            ax = dtl.plot_edges_xy(edge,ax,lw = 8,col = 'b')
        for edge in b1inb2:
            ax = dtl.plot_edges_xy(edge,ax,lw = 3,col = 'g')
        #for edge in b2only:
        #    ax = dtl.plot_edges_xy(edge,ax,lw = 5,col = 'g')
        plt.show()

    if len(dfs) > 1:
        edfs = 0
        for jdfs,lp in enumerate(dfs):
            if binbxy(dfs[edfs],lp,ie = 0):
                edfs = jdfs
        if holes:
            print('genus of ebuxy changed!')
            return [(dfs.pop(edfs),dfs)]
        else:
            print('discarding holes resulting from ebuxy!')
            return [dfs[edfs]]
        '''
        print('promisedland?')
        ax = dtl.plot_axes_xy(200)
        ax = dtl.plot_polygon_xy(dfs[edfs],ax,lw = 7,col = 'r')
        ax = dtl.plot_polygon_xy(dfs[0],ax,lw = 5,col = 'b')
        ax = dtl.plot_polygon_xy(dfs[1],ax,lw = 3,col = 'g')
        #ax = dtl.plot_polygon_xy(b1,ax,ls = '-.',lw = 5,col = 'k')
        #ax = dtl.plot_polygon_xy(b2,ax,ls = '--',lw = 5,col = 'k')
        plt.show()
        '''
    if holes:return [(dfs[0],[])]
    else:return dfs
Пример #28
0
    def mountains(topo, tip, e=2):
        '''topographical loop corresponding to the base of a mountain range'''
        p, d, i, axiom, rules = ((vec3(0, 0, 0), vec3(0, 1, 0), 6, 'X',
                                  dict([('X', '{[[X}{]X}F]X'), ('F', 'FA'),
                                        ('A', 'F')])))
        params = dict(dazimuthal=gtl.rad(25.7), drho=20)

        pg = pgr.planargraph()
        for piece in lsy.lgen(p, d, axiom, rules, i, **params):
            if isinstance(piece, tuple):
                p1, p2 = piece
                v1, v2 = pg.fp(p1, 10), pg.fp(p2, 10)
                e12 = pg.fe(v1, v2)
            elif isinstance(piece, vec3):
                pass
        py = pym.pgtopy(pg, 5)[0]
        py = pym.smoothxy(py, 0.5, 2, 0)
        py = pym.pinchb(py, 5)[0]

        pyprjx = vec3(1, 0, 0).prjps(py)
        pyprjy = vec3(0, 1, 0).prjps(py)
        tipprjx = vec3(1, 0, 0).prjps(tip.loop)
        tipprjy = vec3(0, 1, 0).prjps(tip.loop)
        recenter = vec3(
            ((pyprjx[1] + pyprjx[0]) - (tipprjx[1] + tipprjx[0])) / -2.0,
            ((pyprjy[1] + pyprjy[0]) - (tipprjy[1] + tipprjy[0])) / -2.0, 0)
        for p in py:
            p.trn(recenter)
        pyprjx = vec3(1, 0, 0).prjps(py)
        pyprjy = vec3(0, 1, 0).prjps(py)
        tipprjx = vec3(1, 0, 0).prjps(tip.loop)
        tipprjy = vec3(0, 1, 0).prjps(tip.loop)
        scale = 1.*(tipprjx[1]-tipprjx[0]+tipprjy[1]-tipprjy[0])/\
                    ( pyprjx[1]- pyprjx[0]+ pyprjy[1]- pyprjy[0])
        for p in py:
            p.scl(vec3(scale, scale, 0))

        #com = vec3(0,0,0).com(tip.loop).tov(vec3(0,0,0).com(py)).uscl(-1)
        py = pym.ebixy(tip.loop, py)[0]
        #py = pym.smoothxy(py,0.5,2)
        py = pym.pinchb(py, 5)[0]

        newtips = [topo.avert(tip, loop=py)]

        print('mountains')
        ax = dtl.plot_axes_xy(400)
        ax = dtl.plot_polygon_xy(tip.loop, ax, lw=3, col='b')
        ax = dtl.plot_polygon_xy(py, ax, lw=3, col='g')
        plt.show()

        return newtips
Пример #29
0
    def pg(self,*ags,**kws):
        pg = dpg.planargraph()
        for piece in lsy.lgen(*ags,**kws):
            if isinstance(piece,tuple):
                p1,p2 = piece
                v1,v2 = pg.fp(p1,10),pg.fp(p2,10)
                e12 = pg.fe(v1,v2)
            elif isinstance(piece,vec3):pass
        py = pym.pgtopy(pg,1)[0]
        py = pym.bisectb(py)
        py = pym.smoothxy(py,0.5,2)

        #ax = pg.plotxy(l = 20)
        ax = dtl.plot_axes_xy(50)
        ax = dtl.plot_polygon_xy(py,ax,lw = 3)
        plt.show()
Пример #30
0
    def atest_pgbleed(self):
        def trimtofp(p1, p2, r=5):
            ips = pym.sintbxyp(p1, p2, fp)
            if len(ips) > 0:
                for ip in ips:
                    if ip.isnear(p1): continue
                    p2 = p1.lerp(ip, 1 - r / p1.d(ip))
            return p2

        rg = pgr.planargraph()

        easement = 10
        fp = vec3(0, 0, 0).pring(100, 8)

        exp = fp[-1].lerp(fp[0], 0.5)
        exn = vec3(0, 0, 1).crs(fp[-1].tov(fp[0])).nrm()
        ex1 = exp.cp()
        ex2 = ex1.cp().trn(exn.cp().uscl(easement))
        i1 = rg.av(p=ex1, l=0)
        i2, r1 = rg.mev(i1, {'p': ex2, 'l': 0}, {})

        tip = i2
        tv = rg.vs[tip]
        avs = [rg.vs[k] for k in rg.orings[tip]]
        if len(avs) == 1:
            op = tv[1]['p']
            nptn = avs[0][1]['p'].tov(op).nrm().uscl(100)
            np = op.cp().trn(nptn)
            np = trimtofp(op, np, easement + 10)
            nv, nr = rg.mev(tip, {'p': np, 'l': 0}, {})

        start = nv
        tip = start
        fp_relax = pym.aggregate(pym.contract(fp, 20), 20)
        for p_relax in fp_relax:
            nv, nr = rg.mev(tip, {'p': p_relax, 'l': 0}, {})
            tip = nv
        ne = rg.ae(tip, start, **{})

        rpy = pym.pgbleed(rg, 5)

        ax = dtl.plot_axes_xy(300)
        ax = rg.plotxy(ax)
        ax = dtl.plot_polygon_xy(fp, ax, lw=2, col='b')
        ax = dtl.plot_polygon_xy(fp_relax, ax, lw=2, col='b')
        ax = dtl.plot_polygon_full_xy(rpy, ax, lw=2, col='g')
        plt.show()
Пример #31
0
    def mountains(topo,tip,e = 2):
        '''topographical loop corresponding to the base of a mountain range'''
        p,d,i,axiom,rules = ((vec3(0,0,0),vec3(0,1,0),6,
            'X',dict([('X','{[[X}{]X}F]X'),('F','FA'),('A','F')])))
        params = dict(dazimuthal = gtl.rad(25.7),drho = 20)

        pg = pgr.planargraph()
        for piece in lsy.lgen(p,d,axiom,rules,i,**params):
            if isinstance(piece,tuple):
                p1,p2 = piece
                v1,v2 = pg.fp(p1,10),pg.fp(p2,10)
                e12 = pg.fe(v1,v2)
            elif isinstance(piece,vec3):pass
        py = pym.pgtopy(pg,5)[0]
        py = pym.smoothxy(py,0.5,2,0)
        py = pym.pinchb(py,5)[0]
  
        pyprjx = vec3(1,0,0).prjps(py)
        pyprjy = vec3(0,1,0).prjps(py)
        tipprjx = vec3(1,0,0).prjps(tip.loop)
        tipprjy = vec3(0,1,0).prjps(tip.loop)
        recenter = vec3(
            ((pyprjx[1]+pyprjx[0])-(tipprjx[1]+tipprjx[0]))/-2.0,
            ((pyprjy[1]+pyprjy[0])-(tipprjy[1]+tipprjy[0]))/-2.0,0)
        for p in py:p.trn(recenter)
        pyprjx = vec3(1,0,0).prjps(py)
        pyprjy = vec3(0,1,0).prjps(py)
        tipprjx = vec3(1,0,0).prjps(tip.loop)
        tipprjy = vec3(0,1,0).prjps(tip.loop)
        scale = 1.*(tipprjx[1]-tipprjx[0]+tipprjy[1]-tipprjy[0])/\
                    ( pyprjx[1]- pyprjx[0]+ pyprjy[1]- pyprjy[0])
        for p in py:p.scl(vec3(scale,scale,0))

        #com = vec3(0,0,0).com(tip.loop).tov(vec3(0,0,0).com(py)).uscl(-1)
        py = pym.ebixy(tip.loop,py)[0]
        #py = pym.smoothxy(py,0.5,2)
        py = pym.pinchb(py,5)[0]

        newtips = [topo.avert(tip,loop = py)]

        print('mountains')
        ax = dtl.plot_axes_xy(400)
        ax = dtl.plot_polygon_xy(tip.loop,ax,lw = 3,col = 'b')
        ax = dtl.plot_polygon_xy(py,ax,lw = 3,col = 'g')
        plt.show()

        return newtips
Пример #32
0
    def atest_pgbleed(self):
        def trimtofp(p1,p2,r = 5):
            ips = pym.sintbxyp(p1,p2,fp)
            if len(ips) > 0:
                for ip in ips:
                    if ip.isnear(p1):continue
                    p2 = p1.lerp(ip,1-r/p1.d(ip))
            return p2

        rg = pgr.planargraph()

        easement = 10
        fp = vec3(0,0,0).pring(100,8)

        exp = fp[-1].lerp(fp[0],0.5)
        exn = vec3(0,0,1).crs(fp[-1].tov(fp[0])).nrm()
        ex1 = exp.cp()
        ex2 = ex1.cp().trn(exn.cp().uscl(easement))
        i1 = rg.av(p = ex1,l = 0)
        i2,r1 = rg.mev(i1,{'p':ex2,'l':0},{})
        
        tip = i2
        tv = rg.vs[tip]
        avs = [rg.vs[k] for k in rg.orings[tip]]
        if len(avs) == 1:
            op = tv[1]['p']
            nptn = avs[0][1]['p'].tov(op).nrm().uscl(100)
            np = op.cp().trn(nptn)
            np = trimtofp(op,np,easement+10)
            nv,nr = rg.mev(tip,{'p':np,'l':0},{})

        start = nv
        tip = start
        fp_relax = pym.aggregate(pym.contract(fp,20),20)
        for p_relax in fp_relax:
            nv,nr = rg.mev(tip,{'p':p_relax,'l':0},{})
            tip = nv
        ne = rg.ae(tip,start,**{})

        rpy = pym.pgbleed(rg,5)

        ax = dtl.plot_axes_xy(300)
        ax = rg.plotxy(ax)
        ax = dtl.plot_polygon_xy(fp,ax,lw = 2,col = 'b')
        ax = dtl.plot_polygon_xy(fp_relax,ax,lw = 2,col = 'b')
        ax = dtl.plot_polygon_full_xy(rpy,ax,lw = 2,col = 'g')
        plt.show()
Пример #33
0
    def atest_ebuxy(self):
        def pl(b1, b2, br):
            ax = dtl.plot_axes_xy(20)
            ax = dtl.plot_polygon_xy(b1, ax, col='b', lw=5.0)
            ax = dtl.plot_polygon_xy(b2, ax, col='g', lw=5.0)
            for b in br:
                ax = dtl.plot_polygon_xy(b, ax, col='r', lw=2.0)
            plt.show()

        vb = vec3(0, 0, 0).sq(400, 400)
        dx, dy, xn, yn = 20, 20, 4, 3
        o = vec3(-dx * xn / 2.0, -dy * yn, 0).com(vb)
        vgrid = [
            o.cp().trn(vec3(x * dx, y * dy, 0)) for y in range(yn)
            for x in range(xn)
        ]
        boxes = [p.sq(dx, dy) for p in vgrid]
        boxes = [b for b in boxes if pym.binbxy(b, vb)]
        box = pym.bsuxy(boxes)

        ax = dtl.plot_axes_xy(300)
        ax = dtl.plot_polygon_xy(vb, ax, lw=2, col='b')
        for b in boxes:
            ax = dtl.plot_polygon_xy(b, ax, lw=2, col='g')
        for b in box:
            ax = dtl.plot_polygon_xy(b, ax, lw=2, col='r')
        plt.show()

        b1 = vec3(7, 0, 0).sq(8, 8)
        b2 = vec3(0, 0, 0).sq(8, 8)
        br = pym.ebuxy(b1, b2)
        pl(b1, b2, br)
        self.assertTrue(len(br) == 1)
        self.assertTrue(len(br[0]) == 8)
        b1 = vec3(0, 0, 0).sq(20, 8)
        b2 = vec3(0, 8, 0).sq(20, 8)
        br = pym.ebuxy(b1, b2)
        pl(b1, b2, br)
        self.assertTrue(len(br) == 1)
        self.assertTrue(len(br[0]) == 6)
        b1 = vec3(8, 2, 0).sq(8, 8)
        b2 = vec3(0, 0, 0).sq(8, 8)
        br = pym.ebuxy(b1, b2)
        pl(b1, b2, br)
        self.assertTrue(len(br) == 1)
        self.assertTrue(len(br[0]) == 10)
Пример #34
0
    def pg(self, *ags, **kws):
        pg = dpg.planargraph()
        for piece in lsy.lgen(*ags, **kws):
            if isinstance(piece, tuple):
                p1, p2 = piece
                v1, v2 = pg.fp(p1, 10), pg.fp(p2, 10)
                e12 = pg.fe(v1, v2)
            elif isinstance(piece, vec3):
                pass
        py = pym.pgtopy(pg, 1)[0]
        py = pym.bisectb(py)
        py = pym.smoothxy(py, 0.5, 2)

        #ax = pg.plotxy(l = 20)
        ax = dtl.plot_axes_xy(50)
        ax = dtl.plot_polygon_xy(py, ax, lw=3)
        plt.show()
Пример #35
0
 def pl(s11, s12, s21, s22):
     ax = dtl.plot_axes_xy(1.5)
     ax = dtl.plot_point_xy(s11,
                            dtl.plot_point_xy_annotate(s11, ax, 's11'),
                            col='b')
     ax = dtl.plot_point_xy(s12,
                            dtl.plot_point_xy_annotate(s12, ax, 's12'),
                            col='b')
     ax = dtl.plot_point_xy(s21,
                            dtl.plot_point_xy_annotate(s21, ax, 's21'),
                            col='g')
     ax = dtl.plot_point_xy(s22,
                            dtl.plot_point_xy_annotate(s22, ax, 's22'),
                            col='g')
     ax = dtl.plot_vector_xy(s11, s11.tov(s21), ax, lw=5.0, col='r')
     ax = dtl.plot_vector_xy(s11, s11.tov(s12), ax, lw=2.0, col='b')
     ax = dtl.plot_vector_xy(s21, s21.tov(s22), ax, lw=2.0, col='g')
     plt.show()
Пример #36
0
    def layroads(t, e):
        '''generate a planargraph of a network of roads'''

        #return pgr.planargraph()

        drho, i = 20, 3
        p, d = vec3(0, 0, 0), vec3(0, 1, 0)
        #axiom = 'X'
        #rules = dict([('X','F{[X}{]X}X'),('F','FF')])
        #params = dict(dazimuthal = gtl.rad(90),drho = drho)
        axiom = 'X'
        rules = dict([('X', 'F]{{X}[X}[F{[FX}]X'), ('F', 'FF')])
        params = dict(dazimuthal=gtl.rad(90), drho=drho)
        pg = pgr.planargraph()
        for piece in lsy.lgen(p, d, axiom, rules, i, **params):
            if isinstance(piece, tuple):
                p1, p2 = piece
                v1, v2 = pg.fp(p1, drho / 2), pg.fp(p2, drho / 2)
                rdkws = {'style': 'urban'}
                e12 = pg.fe(v1, v2, **rdkws)
            elif isinstance(piece, vec3):
                pass

        #for v in pg.vs:
        #    if v is None:continue
        #    p = v[1]['p']
        #    p.ztrn(t(p.x,p.y))

        #pyscale = vec3(0,1,0).prjps(py)
        #tipscale = vec3(0,1,0).prjps(tip.loop)
        #pyscale = pyscale[1]-pyscale[0]
        #tipscale = tipscale[1]-tipscale[0]
        #scale = tipscale/pyscale
        #com = vec3(0,0,0).com(tip.loop).tov(vec3(0,0,0).com(py)).uscl(-1)
        #for p in py:p.scl(vec3(scale,scale,0)).trn(com)

        print('ROADS')
        ax = dtl.plot_axes_xy(200)
        ax = pg.plotxy(ax)
        plt.show()
        #pdb.set_trace()
        return pg
Пример #37
0
    def atest_ebuxy(self):
        def pl(b1,b2,br):
            ax = dtl.plot_axes_xy(20)
            ax = dtl.plot_polygon_xy(b1,ax,col = 'b',lw = 5.0)
            ax = dtl.plot_polygon_xy(b2,ax,col = 'g',lw = 5.0)
            for b in br:ax = dtl.plot_polygon_xy(b,ax,col = 'r',lw = 2.0)
            plt.show()

        vb = vec3(0,0,0).sq(400,400)
        dx,dy,xn,yn = 20,20,4,3
        o = vec3(-dx*xn/2.0,-dy*yn,0).com(vb)
        vgrid = [o.cp().trn(vec3(x*dx,y*dy,0)) for y in range(yn) for x in range(xn)]
        boxes = [p.sq(dx,dy) for p in vgrid]
        boxes = [b for b in boxes if pym.binbxy(b,vb)]
        box = pym.bsuxy(boxes)

        ax = dtl.plot_axes_xy(300)
        ax = dtl.plot_polygon_xy(vb,ax,lw = 2,col = 'b')
        for b in boxes:ax = dtl.plot_polygon_xy(b,ax,lw = 2,col = 'g')
        for b in box:ax = dtl.plot_polygon_xy(b,ax,lw = 2,col = 'r')
        plt.show()

        b1 = vec3(7,0,0).sq(8,8)
        b2 = vec3(0,0,0).sq(8,8)
        br = pym.ebuxy(b1,b2)
        pl(b1,b2,br)
        self.assertTrue(len(br) == 1)
        self.assertTrue(len(br[0]) == 8)
        b1 = vec3(0,0,0).sq(20,8)
        b2 = vec3(0,8,0).sq(20,8)
        br = pym.ebuxy(b1,b2)
        pl(b1,b2,br)
        self.assertTrue(len(br) == 1)
        self.assertTrue(len(br[0]) == 6)
        b1 = vec3(8,2,0).sq(8,8)
        b2 = vec3(0,0,0).sq(8,8)
        br = pym.ebuxy(b1,b2)
        pl(b1,b2,br)
        self.assertTrue(len(br) == 1)
        self.assertTrue(len(br[0]) == 10)
Пример #38
0
def ___lsystemboundary(b):
    p, d, i, axiom, rules = ((vec3(0, 0, 0), vec3(0, 1, 0), 5, 'X',
                              dict([('X', '{[[X}{]X}F]X'), ('F', 'FA'),
                                    ('A', 'F')])))
    params = dict(dazimuthal=gtl.rad(25.7), drho=20)

    pg = dpg.planargraph()
    for piece in lsy.lgen(p, d, axiom, rules, i, **params):
        if isinstance(piece, tuple):
            p1, p2 = piece
            v1, v2 = pg.fp(p1, 10), pg.fp(p2, 10)
            e12 = pg.fe(v1, v2)
        elif isinstance(piece, vec3):
            pass
    py = pym.pgtopy(pg, 5)[0]
    py = pym.smoothxy(py, 0.5, 2)
    #py = pym.aggregate(py,2)
    py = pym.pinchb(py, 5)

    #ax = dtl.plot_axes_xy(400)
    #ax = pg.plotxy(ax,l = 300)
    #ax = dtl.plot_polygon_xy(b,ax,lw = 3,col = 'b')
    #ax = dtl.plot_polygon_xy(py,ax,lw = 3,col = 'g')
    #plt.show()

    pyscale = vec3(0, 1, 0).prjps(py)
    tipscale = vec3(0, 1, 0).prjps(b)
    pyscale = pyscale[1] - pyscale[0]
    tipscale = tipscale[1] - tipscale[0]
    scale = tipscale / pyscale
    com = vec3(0, 0, 0).com(b).tov(vec3(0, 0, 0).com(py)).uscl(-1)
    for p in py:
        p.scl(vec3(scale, scale, 0)).trn(com)

    ax = dtl.plot_axes_xy(400)
    ax = dtl.plot_polygon_xy(b, ax, lw=3, col='b')
    ax = dtl.plot_polygon_xy(py, ax, lw=3, col='g')
    plt.show()

    return py
Пример #39
0
 def plotxy(self,ax = None,l = 10,s = 1.0,number = True,**kws):
     if ax is None:ax = dtl.plot_axes_xy(l,**kws)
     for j in range(self.vcnt):
         i = self.vs[j]
         if i is None:continue
         ip = i[1]['p']
         if number:
             jstr = str(j)+str([v for v in self.rings[j]])
             jstrccw = str([self.ccw(j,v) for v in self.rings[j]])
             jstrcw = str([self.cw(j,v) for v in self.rings[j]])
             jstr += '\n'+jstrccw+'\n'+jstrcw
             ax = dtl.plot_point_xy_annotate(ip,ax,jstr)
         ax = dtl.plot_point_xy(ip,ax,col = 'r')
     for k in self.rings:
         vr = self.rings[k]
         for ov in vr:
             if vr[ov] is None:continue
             re = (self.vs[k][1]['p'].cp(),self.vs[ov][1]['p'].cp())
             rn = vec3(0,0,1).crs(re[0].tov(re[1])).nrm().uscl(s)
             re = (re[0].trn(rn),re[1].trn(rn))
             ax = dtl.plot_edges_xy(re,ax,lw = 2,col = 'g')
     return ax
Пример #40
0
 def plotxy(self, ax=None, l=10, s=1.0, number=True, **kws):
     if ax is None: ax = dtl.plot_axes_xy(l, **kws)
     for j in range(self.vcnt):
         i = self.vs[j]
         if i is None: continue
         ip = i[1]['p']
         if number:
             jstr = str(j) + str([v for v in self.rings[j]])
             jstrccw = str([self.ccw(j, v) for v in self.rings[j]])
             jstrcw = str([self.cw(j, v) for v in self.rings[j]])
             jstr += '\n' + jstrccw + '\n' + jstrcw
             ax = dtl.plot_point_xy_annotate(ip, ax, jstr)
         ax = dtl.plot_point_xy(ip, ax, col='r')
     for k in self.rings:
         vr = self.rings[k]
         for ov in vr:
             if vr[ov] is None: continue
             re = (self.vs[k][1]['p'].cp(), self.vs[ov][1]['p'].cp())
             rn = vec3(0, 0, 1).crs(re[0].tov(re[1])).nrm().uscl(s)
             re = (re[0].trn(rn), re[1].trn(rn))
             ax = dtl.plot_edges_xy(re, ax, lw=2, col='g')
     return ax
Пример #41
0
def splotch(g, subseq):
    irx, easement, splotchseq = subseq.split(',')
    irx, easement = int(irx), float(easement)
    print('SPLOTCH!', subseq, splotchseq)
    iv = g.vs[irx]
    fp = iv[1]['fp']

    xprj = vec3(1, 0, 0).prjps(fp)
    yprj = vec3(0, 1, 0).prjps(fp)
    xlen = xprj[1] - xprj[0]
    ylen = yprj[1] - yprj[0]
    rad = max(xlen, ylen) / 2.0

    #r1 = vec3(0,10,0).com(fp).sq(30,40)
    #r2 = vec3(-10,-20,0).com(fp).sq(20,40)
    #r3 = vec3(0,-10,0).com(fp).sq(50,30)
    #rs = [r1,r2,r3]

    #r = rs.pop(0)
    #while rs:r = pym.ebuxy(r,rs.pop(0))

    r = dbl.block('H', rad / 3.0, rad, rad)
    r = r[0]

    for j in range(3):
        r = pym.smoothxy(r, 0.1)

    #r = pym.ebixy(fp,r)
    l = fp

    nv = g.sv(irx, l, r)

    ax = dtl.plot_axes_xy(2 * rad)
    ax = dtl.plot_polygon_xy(fp, ax, lw=6, col=None)
    ax = dtl.plot_polygon_xy(r, ax, lw=4, col='b')
    ax = dtl.plot_polygon_xy(l, ax, lw=2, col='g')
    plt.show()

    return g
Пример #42
0
    def plotxy(self,ax = None,scale = 250):
        if ax is None:ax = dtl.plot_axes_xy(scale)
        ax = pgr.planargraph.plotxy(self,ax)
        ekeys = []
        for vx in range(self.vcnt):
            v = self.vs[vx]
            if v is None:continue
            vb = v[1]['b']
            vrtls = '-'
            if 't' in v[1]:vrtls = '--' if 'developed' in v[1]['t'] else '-'
            conr = 1 if pym.bccw(vb[0]) else -1
            ax = dtl.plot_polygon_xy(pym.contract(vb[0],conr),
                ax,lw = 2,ls = vrtls,col = 'b')
            for ib in vb[1]:
                conr = 1 if pym.bccw(ib) else -1
                ax = dtl.plot_polygon_xy(pym.contract(ib,conr),ax,lw = 2,col = 'r')
            vbc = vec3(0,0,0).com(vb[0])
            rs = str(vx)+','+str(self.orings[vx])#+',\n'+str(v[1]['type'])
            ax = dtl.plot_point_xy_annotate(vbc,ax,rs)
            for ve in self.orings[vx]:
                ov = self.vs[ve]
                if ov is None:continue

                if not (vx,ve) in ekeys and not (ve,vx) in ekeys:
                    ekeys.append((vx,ve))
                    aws = pym.badjbxy(vb[0],ov[1]['b'][0],0)
                    for awx in range(len(aws)):
                        vwx,owx = aws[awx]
                        ex,ekws = self.es[self.elook[ekeys[-1]]]
                        door = vb[0][vwx-1].lerp(vb[0][vwx],ekws['p'])
                        ax = dtl.plot_point_xy(door,ax,col = 'r')

                ovbc = vec3(0,0,0).com(self.vs[ve][1]['b'][0])
                ax = dtl.plot_edges_xy((vbc,ovbc),ax,lw = 3,col = 'c')

            #for ep in v[1]['exits']:
            #    ax = dtl.plot_point_xy(ep,ax,mk = 's',col = 'r')

        return ax
Пример #43
0
def splotch(g,subseq):
    irx,easement,splotchseq = subseq.split(',')
    irx,easement = int(irx),float(easement)
    print('SPLOTCH!',subseq,splotchseq)
    iv = g.vs[irx]
    fp = iv[1]['fp']

    xprj = vec3(1,0,0).prjps(fp)
    yprj = vec3(0,1,0).prjps(fp)
    xlen = xprj[1]-xprj[0]
    ylen = yprj[1]-yprj[0]
    rad = max(xlen,ylen)/2.0
    
    #r1 = vec3(0,10,0).com(fp).sq(30,40)
    #r2 = vec3(-10,-20,0).com(fp).sq(20,40)
    #r3 = vec3(0,-10,0).com(fp).sq(50,30)
    #rs = [r1,r2,r3]

    #r = rs.pop(0)
    #while rs:r = pym.ebuxy(r,rs.pop(0))

    r = dbl.block('H',rad/3.0,rad,rad)
    r = r[0]

    for j in range(3):r = pym.smoothxy(r,0.1)

    #r = pym.ebixy(fp,r)
    l = fp

    nv = g.sv(irx,l,r)

    ax = dtl.plot_axes_xy(2*rad)
    ax = dtl.plot_polygon_xy(fp,ax,lw = 6,col = None)
    ax = dtl.plot_polygon_xy(r,ax,lw = 4,col = 'b')
    ax = dtl.plot_polygon_xy(l,ax,lw = 2,col = 'g')
    plt.show()

    return g
Пример #44
0
 def plotxy(self,ax = None):
     scale = vec3(1,0,0).prjps(self.footprint)
     scale = scale[1]-scale[0]
     if ax is None:ax = dtl.plot_axes_xy(scale)
     for vx in range(self.vcnt):
         v = self.vs[vx]
         if v is None:continue
         vb = v[1]['fp']
         vrtls = '-' if 'developed' in v[1]['type'] else '--'
         #vrtls = '--' if 'natural' in v[1]['type'] else '-'
         ax = dtl.plot_polygon_xy(
             pym.contract(vb,0.01*scale),ax,lw = 2,ls = vrtls,col = None)
         vbc = vec3(0,0,0).com(vb)
         rs = str(vx)+','+str(v[1]['edges'])+',\n'+str(v[1]['type'])
         ax = dtl.plot_point_xy_annotate(vbc,ax,rs)
         for ve in v[1]['edges']:
             if self.vs[ve] is None:continue
             ovbc = vec3(0,0,0).com(self.vs[ve][1]['fp'])
             ax = dtl.plot_edges_xy((vbc,ovbc),ax,lw = 3,col = 'c')
         for ep in v[1]['exits']:
             ax = dtl.plot_point_xy(ep,ax,mk = 's',col = 'r')
     ax = dtl.plot_polygon_xy(self.footprint,ax,lw = 1,col = 'g')
     return ax
Пример #45
0
def ___lsystemboundary(b):
    p,d,i,axiom,rules = ((vec3(0,0,0),vec3(0,1,0),5,
        'X',dict([('X','{[[X}{]X}F]X'),('F','FA'),('A','F')])))
    params = dict(dazimuthal = gtl.rad(25.7),drho = 20)

    pg = dpg.planargraph()
    for piece in lsy.lgen(p,d,axiom,rules,i,**params):
        if isinstance(piece,tuple):
            p1,p2 = piece
            v1,v2 = pg.fp(p1,10),pg.fp(p2,10)
            e12 = pg.fe(v1,v2)
        elif isinstance(piece,vec3):pass
    py = pym.pgtopy(pg,5)[0]
    py = pym.smoothxy(py,0.5,2)
    #py = pym.aggregate(py,2)
    py = pym.pinchb(py,5)

    #ax = dtl.plot_axes_xy(400)
    #ax = pg.plotxy(ax,l = 300)
    #ax = dtl.plot_polygon_xy(b,ax,lw = 3,col = 'b')
    #ax = dtl.plot_polygon_xy(py,ax,lw = 3,col = 'g')
    #plt.show()

    pyscale = vec3(0,1,0).prjps(py)
    tipscale = vec3(0,1,0).prjps(b)
    pyscale = pyscale[1]-pyscale[0]
    tipscale = tipscale[1]-tipscale[0]
    scale = tipscale/pyscale
    com = vec3(0,0,0).com(b).tov(vec3(0,0,0).com(py)).uscl(-1)
    for p in py:p.scl(vec3(scale,scale,0)).trn(com)

    ax = dtl.plot_axes_xy(400)
    ax = dtl.plot_polygon_xy(b,ax,lw = 3,col = 'b')
    ax = dtl.plot_polygon_xy(py,ax,lw = 3,col = 'g')
    plt.show()

    return py
Пример #46
0
 def plot(self,l,sx,sy):
     sq = vec3(0,0,0).sq(sx,sy)
     ax = dtl.plot_axes_xy(10)
     ax = dtl.plot_polygon_xy(sq,ax,lw = 1,col = 'r')
     ax = dtl.plot_polygon_full_xy(l,ax,lw = 2,col = 'g')
     plt.show()
Пример #47
0
 def pl(b):
     ax = dtl.plot_axes_xy(300)
     ax = dtl.plot_polygon_xy(b,ax)
     plt.show()
Пример #48
0
 def pl():
     ax = dtl.plot_axes_xy(700)
     ax = dtl.plot_polygon_xy(fp,ax,lw = 2,col = 'g')
     ax = dtl.plot_points_xy(fp,ax,number = True)
     plt.show()
Пример #49
0
    def test_bnrm(self):
        def pl():
            ax = dtl.plot_axes_xy(700)
            ax = dtl.plot_polygon_xy(fp,ax,lw = 2,col = 'g')
            ax = dtl.plot_points_xy(fp,ax,number = True)
            plt.show()

        ebnd = db.persistent_container('/home/cogle/dev/dilapidator/test/','ebnd')
        ebnd.load()
        ebnd = ebnd.data

        ax = dtl.plot_axes_xy(120)
        ax = dtl.plot_polygon_xy(ebnd,ax,lw = 4,col = 'r')
        ax = dtl.plot_points_xy(ebnd,ax,number = True)
        plt.show()

        fp = [
            vec3(-6.9831085205078125, 121.9827880859375, 0.0),
            vec3(-26.983108520507812, 121.9827880859375, 0.0),
            vec3(-46.98310852050781, 121.9827880859375, 0.0),
            vec3(-66.98310852050781, 121.9827880859375, 0.0),
            vec3(-85.984375, 121.9827880859375, 0.0),
            vec3(-85.98310852050781, 102.9827880859375, 0.0),
            vec3(-85.98310852050781, 82.9827880859375, 0.0),
            vec3(-85.98310852050781, 63.9814453125, 0.0),
            vec3(-66.98310852050781, 63.9827880859375, 0.0),
            vec3(-46.98310852050781, 63.9827880859375, 0.0),
            vec3(-26.983108520507812, 63.9827880859375, 0.0),
            vec3(-6.9831085205078125, 63.9827880859375, 0.0),
            vec3(13.016891479492188, 63.9827880859375, 0.0),
            vec3(33.01689147949219, 63.9827880859375, 0.0),
            vec3(53.01689147949219, 63.9827880859375, 0.0),
            vec3(73.01689147949219, 63.9827880859375, 0.0),
            vec3(93.01689147949219, 63.9827880859375, 0.0),
            vec3(112.017578125, 63.9827880859375, 0.0),
            vec3(112.01689147949219, 82.9827880859375, 0.0),
            vec3(112.01689147949219, 102.9827880859375, 0.0),
            vec3(112.01689147949219, 121.9833984375, 0.0),
            vec3(93.01689147949219, 121.9827880859375, 0.0),
            vec3(73.01689147949219, 121.9827880859375, 0.0),
            vec3(53.01689147949219, 121.9827880859375, 0.0),
            vec3(33.01689147949219, 121.9827880859375, 0.0),
            vec3(13.016891479492188, 121.9827880859375, 0.0)]
        ax = dtl.plot_axes_xy(200)
        ax = dtl.plot_polygon_xy(fp,ax,lw = 3,col = 'b')
        ax = dtl.plot_points_xy(fp,ax,number = True)
        plt.show()
        self.assertTrue(pym.bnrm(fp).isnear(vec3(0,0,1)))

        vb = vec3(-100,100,0).sq(400,400)
        dx,dy,xn,yn = 20,20,10,30
        o = vec3(-dx*xn/2.0,-dy*yn,0).com(vb)
        vgrid = [o.cp().trn(vec3(x*dx,y*dy,0)) for y in range(yn) for x in range(xn)]
        boxes = [p.sq(dx,dy) for p in vgrid]
        boxes = [b for b in boxes if pym.binbxy(b,vb)]
        box = pym.bsuxy(boxes)
        self.assertTrue(pym.bnrm(box[0]).isnear(vec3(0,0,1)))

        fp = [vec3(0,0,0),
            vec3(20,0,0),vec3(20,-20,0),vec3(40,-30,0),vec3(60,-30,0),
            vec3(60,40,0),vec3(-60,40,0),vec3(-60,-30,0),vec3(-40,-30,0),
            vec3(-20,-20,0),vec3(-20,0,0)]
        self.assertTrue(pym.bnrm(fp).isnear(vec3(0,0,1)))
        self.assertTrue(pym.bnrm(fp[::-1]).isnear(vec3(0,0,-1)))

        fp = [
            vec3(-282.1204528808594, 127.64604187011719, 0.0),
            vec3(-334.1018981933594, 179.6274871826172, 0.0),
            vec3(-130.43038940429688, 179.62747192382812, 0.0),
            vec3(-130.43038940429688, 336.434326171875, 0.0),
            vec3(-36.91655731201172, 366.8188171386719, 0.0),
            vec3(-36.916534423828125, 461.72088623046875, 0.0),
            vec3(191.35768127441406, 461.841796875, 0.0),
            vec3(275.3216552734375, 373.85748291015625, 0.0),
            vec3(152.47915649414062, 204.779296875, 0.0),
            vec3(332.7578430175781, -43.35302734375, 0.0),
            vec3(454.96630859375, -3.6450958251953125, 0.0),
            vec3(456.61492919921875, -166.4105224609375, 0.0), 
            vec3(316.5687561035156, -120.90676879882812, 0.0),
            vec3(201.97442626953125, -278.63232421875, 0.0), 
            vec3(277.8673400878906, -383.0899963378906, 0.0),
            vec3(195.58241271972656, -472.19598388671875, 0.0),
            vec3(-10.369781494140625, -468.9277038574219, 0.0),
            vec3(-10.369804382324219, -395.02154541015625, 0.0),
            vec3(-78.82841491699219, -326.56292724609375, 0.0),
            vec3(-175.64352416992188, -326.56292724609375, 0.0),
            vec3(-244.10214233398438, -395.0215759277344, 0.0),
            vec3(-244.10214233398438, -414.89117431640625, 0.0),
            vec3(-465.6239929199219, -192.85736083984375, 0.0),
            vec3(-466.0299072265625, -122.715087890625, 0.0),
            vec3(-385.8233947753906, -122.71507263183594, 0.0),
            vec3(-282.1204528808594, -19.01211929321289, 0.0),
                ]
        bn = pym.bnrm(fp)
        print('bnnn',bn)
        fp.reverse()
        pl()
        bn = pym.bnrm(fp)
        print('bnnnrev',bn)
        self.assertTrue(pym.bnrm(fp).isnear(vec3(0,0,1)))
        self.assertTrue(pym.bnrm(fp[::-1]).isnear(vec3(0,0,-1)))
Пример #50
0
 def pl(b1,b2,br):
     ax = dtl.plot_axes_xy(20)
     ax = dtl.plot_polygon_xy(b1,ax,col = 'b',lw = 5.0)
     ax = dtl.plot_polygon_xy(b2,ax,col = 'g',lw = 5.0)
     for b in br:ax = dtl.plot_polygon_xy(b,ax,col = 'r',lw = 2.0)
     plt.show()
Пример #51
0
 def pl():
     ax = dtl.plot_axes_xy(50)
     ax = dtl.plot_polygon_full_xy(py,ax,lw = 2,col = 'b')
     plt.show()
Пример #52
0
def pinchb(b,epsilon = 5):
    pde = lambda p,e1,e2 : abs()
    new = lambda s1,s2 : not ((s1,s2) in unfin or (s1,s2) in unfin)
    unfin = [(b[x-1],b[x]) for x in range(len(b))]
    fin = []
    while unfin:
        u1,u2 = unfin.pop(0)
        clear = True
        for e1,e2 in unfin:
            e1u12d = e1.dexy(u1,u2,0)
            e2u12d = e2.dexy(u1,u2,0)
            if False and e1u12d > -1 and e1u12d < epsilon:

                ax = dtl.plot_axes_xy(200)
                ax = dtl.plot_polygon_xy(b,ax,lw = 2,ls = '--',col = 'k')
                ax = dtl.plot_edges_xy((u1,u2),ax,lw = 3,col = 'b')
                ax = dtl.plot_edges_xy((e1,e2),ax,lw = 3,col = 'g')
                plt.show()

                pdb.set_trace()
            elif False and e2u12d > -1 and e2u12d < epsilon:

                ax = dtl.plot_axes_xy(200)
                ax = dtl.plot_polygon_xy(b,ax,lw = 2,ls = '--',col = 'k')
                ax = dtl.plot_edges_xy((u1,u2),ax,lw = 3,col = 'b')
                ax = dtl.plot_edges_xy((e1,e2),ax,lw = 3,col = 'g')
                plt.show()

                pdb.set_trace()
            elif e1.onsxy(u1,u2,0):
                if new(u1,e1):unfin.append((u1,e1))
                if new(e1,u2):unfin.append((e1,u2))
                clear = False
                break
            elif e2.onsxy(u1,u2,0):
                if new(u1,e2):unfin.append((u1,e2))
                if new(e2,u2):unfin.append((e2,u2))
                clear = False
                break
            elif sintsxy(u1,u2,e1,e2,ie = False,ieb = False):
                '''#
                ax = dtl.plot_axes_xy(200)
                for u in unfin:
                    ax = dtl.plot_edges_xy(u,ax,col = 'r',lw = 8)
                for f in fin:
                    ax = dtl.plot_edges_xy(f,ax,col = 'g',lw = 7)
                ax = dtl.plot_edges_xy((u1,u2),ax,col = 'c',lw = 5)
                ax = dtl.plot_edges_xy((e1,e2),ax,col = 'b',lw = 2)
                plt.show()
                '''#
                if sintsxy(u1,u2,e1,e2,ie = False,ieb = False,col = False):
                    ip = sintsxyp(u1,u2,e1,e2)
                    if new(u1,ip):unfin.append((u1,ip))
                    if new(ip,u2):unfin.append((ip,u2))
                    clear = False
                    break
                else:
                    if new(u1,u2):unfin.append((u1,u2))
                    clear = False
        if clear:
            fin.append((u1,u2))

    uloops = sloops(fin,epsilon)
    if len(uloops) > 1:
        #las = [bareaxy(ol) for ol in uloops]
        las = [bareaxy(ol,True) for ol in uloops]
        ulas = [(u,a) for u,a in zip(uloops,las) if a > 10]
        if ulas:
            uloops,las = zip(*ulas)
            uloops,las = list(uloops),list(las)
            uloops.insert(0,uloops.pop(las.index(max(las))))
    print('PINCHB ACCOMPLISHED')
    return uloops
Пример #53
0
 def pl(b1,b2):
     ax = dtl.plot_axes_xy(10)
     ax = dtl.plot_polygon_xy(b1,ax,lw = 2.0,col = 'g')
     ax = dtl.plot_polygon_xy(b2,ax,lw = 2.0,col = 'b')
     plt.show()
Пример #54
0
def pinchb(b, epsilon=5):
    pde = lambda p, e1, e2: abs()
    new = lambda s1, s2: not ((s1, s2) in unfin or (s1, s2) in unfin)
    unfin = [(b[x - 1], b[x]) for x in range(len(b))]
    fin = []
    while unfin:
        u1, u2 = unfin.pop(0)
        clear = True
        for e1, e2 in unfin:
            e1u12d = e1.dexy(u1, u2, 0)
            e2u12d = e2.dexy(u1, u2, 0)
            if False and e1u12d > -1 and e1u12d < epsilon:

                ax = dtl.plot_axes_xy(200)
                ax = dtl.plot_polygon_xy(b, ax, lw=2, ls='--', col='k')
                ax = dtl.plot_edges_xy((u1, u2), ax, lw=3, col='b')
                ax = dtl.plot_edges_xy((e1, e2), ax, lw=3, col='g')
                plt.show()

                pdb.set_trace()
            elif False and e2u12d > -1 and e2u12d < epsilon:

                ax = dtl.plot_axes_xy(200)
                ax = dtl.plot_polygon_xy(b, ax, lw=2, ls='--', col='k')
                ax = dtl.plot_edges_xy((u1, u2), ax, lw=3, col='b')
                ax = dtl.plot_edges_xy((e1, e2), ax, lw=3, col='g')
                plt.show()

                pdb.set_trace()
            elif e1.onsxy(u1, u2, 0):
                if new(u1, e1): unfin.append((u1, e1))
                if new(e1, u2): unfin.append((e1, u2))
                clear = False
                break
            elif e2.onsxy(u1, u2, 0):
                if new(u1, e2): unfin.append((u1, e2))
                if new(e2, u2): unfin.append((e2, u2))
                clear = False
                break
            elif sintsxy(u1, u2, e1, e2, ie=False, ieb=False):
                '''#
                ax = dtl.plot_axes_xy(200)
                for u in unfin:
                    ax = dtl.plot_edges_xy(u,ax,col = 'r',lw = 8)
                for f in fin:
                    ax = dtl.plot_edges_xy(f,ax,col = 'g',lw = 7)
                ax = dtl.plot_edges_xy((u1,u2),ax,col = 'c',lw = 5)
                ax = dtl.plot_edges_xy((e1,e2),ax,col = 'b',lw = 2)
                plt.show()
                '''#
                if sintsxy(u1, u2, e1, e2, ie=False, ieb=False, col=False):
                    ip = sintsxyp(u1, u2, e1, e2)
                    if new(u1, ip): unfin.append((u1, ip))
                    if new(ip, u2): unfin.append((ip, u2))
                    clear = False
                    break
                else:
                    if new(u1, u2): unfin.append((u1, u2))
                    clear = False
        if clear:
            fin.append((u1, u2))

    uloops = sloops(fin, epsilon)
    if len(uloops) > 1:
        #las = [bareaxy(ol) for ol in uloops]
        las = [bareaxy(ol, True) for ol in uloops]
        ulas = [(u, a) for u, a in zip(uloops, las) if a > 10]
        if ulas:
            uloops, las = zip(*ulas)
            uloops, las = list(uloops), list(las)
            uloops.insert(0, uloops.pop(las.index(max(las))))
    print('PINCHB ACCOMPLISHED')
    return uloops
Пример #55
0
 def pl():
     ax = dtl.plot_axes_xy(700)
     ax = dtl.plot_polygon_xy(fp, ax, lw=2, col='g')
     ax = dtl.plot_points_xy(fp, ax, number=True)
     plt.show()
Пример #56
0
 def pl():
     ax = dtl.plot_axes_xy(50)
     ax = dtl.plot_polygon_full_xy(py, ax, lw=2, col='b')
     plt.show()
Пример #57
0
 def pl(b):
     ax = dtl.plot_axes_xy(300)
     ax = dtl.plot_polygon_xy(b, ax)
     plt.show()