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()
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()
def realize(i, p, d, axiom, rules, **params): ax = dtl.plot_axes(10) for piece in lsy.lgen(p, d, axiom, rules, i, **params): if isinstance(piece, tuple): ax = dtl.plot_edges(piece, ax, lw=2, col='k') elif isinstance(piece, vec3): ax = dtl.plot_point(piece, ax) plt.show()
def realize(i,p,d,axiom,rules,**params): ax = dtl.plot_axes(10) for piece in lsy.lgen(p,d,axiom,rules,i,**params): if isinstance(piece,tuple): ax = dtl.plot_edges(piece,ax,lw = 2,col = 'k') elif isinstance(piece,vec3): ax = dtl.plot_point(piece,ax) plt.show()
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
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()
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
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()
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
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
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
def _____genroadnetwork(self, t): p, d, i, axiom, rules = ((vec3(0, 0, 0), vec3(0, 1, 0), 5, 'X', dict([('X', '{[[F}{]A}A]F'), ('F', 'FA'), ('A', 'F')]))) params = dict(dazimuthal=gtl.rad(45), drho=20) drho, i = 10, 5 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) 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) 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) print('ROOOOADDDS') ax = dtl.plot_axes_xy(200) ax = pg.plotxy(ax) #ax = dtl.plot_polygon_xy(py,ax,lw = 3) plt.show() pdb.set_trace() # need a graph that spans all landmasses of the continent # at boundaries of existing regions, line up the roads nicely # within existing regions, add more regions based on road graph # develop resulting regions as before 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() for lm in t.looptree.below(t.root): fp = lm.loop #seq = 'S<>G<>L<>' #rg = rdg.checkseq(rg,fp,seq,False) easement = 20 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, w=0) i2, r1 = rg.mev(i1, {'p': ex2, 'l': 0, 'w': 0.5}, {}) 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(20) np = op.cp().trn(nptn) np = trimtofp(op, np, easement) nv, nr = rg.mev(tip, {'p': np, 'l': 0, 'w': 1}, {}) start = nv tip = start fp_relax = pym.aggregate(pym.contract(fp, 30), 30) #fp_relax = fp[:] for p_relax in fp_relax: nv, nr = rg.mev(tip, {'p': p_relax, 'l': 0, 'w': 1}, {}) tip = nv ne = rg.ae(tip, start, **{}) #ax = rg.plotxy(l = 220) #plt.show() rg.smooth_sticks(1, 0.5) #ax = rg.plotxy(l = 220) #plt.show() '''# 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') plt.show() '''# #pdb.set_trace() for rgv in rg.vs: rgp = rgv[1]['p'] rgp.ztrn(t(rgp.x, rgp.y)) ax = rg.plot(l=220) plt.show() return rg