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
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
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
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
def sow_earth(b,e): '''generate landmasses within a boundary polygon''' lm = pym.contract(b,e*50.0,e) return [lm] for x in range(10):lm = pyg.ajagged(lm,e) lm = pym.bisectb(lm) lm = pym.smoothxy(lm,0.5,e) lm = pym.smoothxy(lm,0.5,e) lm = pym.smoothxy(lm,0.5,e) lm = pym.aggregate(lm,2) lm = pym.blimithmin(lm,2,50) lms = [lm] return lms
def splotch(vb, easement=10): # WIP vbes = [(vb[0][x - 1], vb[0][x]) for x in range(len(vb[0]))] vbels = [vb[0][x - 1].d(vb[0][x]) for x in range(len(vb[0]))] vbe_primary = vbels.index(max(vbels)) vbe_primary_tn = vb[0][vbe_primary - 1].tov(vb[0][vbe_primary]).nrm() bq = quat(0, 0, 0, 1).uu(vec3(1, 0, 0), vbe_primary_tn) if not bq: bq = quat(1, 0, 0, 0) vbcon = pym.aggregate(pym.contract(vb[0], easement), 5) vbxpj = vbe_primary_tn.prjps(vb[0]) vbypj = vbe_primary_tn.cp().zrot(gtl.PI2).prjps(vb[0]) vbxl, vbyl = vbxpj[1] - vbxpj[0], vbypj[1] - vbypj[0] dx, dy = 20, 20 xn, yn = int(1.5 * vbxl / dx), int(1.5 * vbyl / dy) print('xn,yn', xn, yn) o = vec3(0, 0, 0).com(vbcon) vgrid = [ o.cp().xtrn(dx * (x - (xn / 2.0))).ytrn(dy * (y - (yn / 2.0))) for x in range(xn) for y in range(yn) ] #vgrid = [p for p in vgrid if abs(p.x-10) > 10] boxes = [ p.cp().trn(o.flp()).rot(bq).trn(o.flp()).sq(dx, dy) for p in vgrid ] for b in boxes: bcom = vec3(0, 0, 0).com(b).flp() bcom.trnos(b) bq.rotps(b) bcom.flp().trnos(b) boxes = [b for b in boxes if pym.binbxy(b, vbcon)] for ib in vb[1]: boxes = [ b for b in boxes if not pym.bintbxy(b, ib) and not b[0].inbxy(ib) and not ib[0].inbxy(b[0]) ] blgfps = pym.ebuxy_special(boxes, 5, 4) ps = [vec3(0, 0, 0).com(blgfp) for blgfp in blgfps] qs = [bq.cp() for blgfp in blgfps] ss = [vec3(1, 1, 1) for blgfp in blgfps] for p, q, s, blgfp in zip(ps, qs, ss, blgfps): p.cpxy().flp().trnos(blgfp) q.cpf().rotps(blgfp) return zip(ps, qs, ss, blgfps)
def sow_earth(b, e): '''generate landmasses within a boundary polygon''' lm = pym.contract(b, e * 50.0, e) return [lm] for x in range(10): lm = pyg.ajagged(lm, e) lm = pym.bisectb(lm) lm = pym.smoothxy(lm, 0.5, e) lm = pym.smoothxy(lm, 0.5, e) lm = pym.smoothxy(lm, 0.5, e) lm = pym.aggregate(lm, 2) lm = pym.blimithmin(lm, 2, 50) lms = [lm] return lms
def raise_earth(topo, tips, e, mingrad=1.0, mindelz=-5.0, depth=0): if depth == 0: for j, tip in enumerate(tips): tips[j].loop = pym.bisectb(tips[j].loop) #if depth == 10:return print('... raising earth ... (depth: %d)' % depth) newtips = [] for tip in tips: if tip is None: continue newloop = [p.cp().ztrn(mindelz) for p in tip.loop] newloop = pym.aggregate( pym.contract(newloop, abs(mindelz / mingrad)), 5) #uloops = [pym.smoothxyi(newloop,0.8,e,10,1)] #uloops = [pym.pinchb(u,10) for u in uloops if u] #uloops = [pym.pinchb(newloop,10)] uloops = pym.pinchb(newloop, 10) uloops = [u for u in uloops if u] for u in uloops: if not pym.bccw(u): u.reverse() ''' if len(uloops) == 1: print('... 1 loop to raise ...') theloop = uloops[0] newtiparea = pym.bareaxy(theloop,True) elif uloops: print('... 2+ loops to raise ...') bareas = [pym.bareaxy(u,True) for u in uloops] theloop = uloops[bareas.index(max(bareas))] newtiparea = max(bareas) else: print('... no loops to raise ...') theloop = [] ''' for theloop in uloops: newtiparea = pym.bareaxy(theloop, True) newtip = None if theloop and newtiparea > 10: #2*(e)**2: newtip = topo.avert(tip, loop=theloop) else: print('... abortive tip! ...') if newtip is None: continue else: newtips.append(newtip) if newtips: terrain.raise_earth(topo, newtips, e, mingrad, mindelz, depth + 1) else: print('... exhausted tip! ...')
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()
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()
def splotch(vb,easement = 10): # WIP vbes = [(vb[0][x-1],vb[0][x]) for x in range(len(vb[0]))] vbels = [vb[0][x-1].d(vb[0][x]) for x in range(len(vb[0]))] vbe_primary = vbels.index(max(vbels)) vbe_primary_tn = vb[0][vbe_primary-1].tov(vb[0][vbe_primary]).nrm() bq = quat(0,0,0,1).uu(vec3(1,0,0),vbe_primary_tn) if not bq:bq = quat(1,0,0,0) vbcon = pym.aggregate(pym.contract(vb[0],easement),5) vbxpj = vbe_primary_tn.prjps(vb[0]) vbypj = vbe_primary_tn.cp().zrot(gtl.PI2).prjps(vb[0]) vbxl,vbyl = vbxpj[1]-vbxpj[0],vbypj[1]-vbypj[0] dx,dy = 20,20 xn,yn = int(1.5*vbxl/dx),int(1.5*vbyl/dy) print('xn,yn',xn,yn) o = vec3(0,0,0).com(vbcon) vgrid = [o.cp().xtrn(dx*(x-(xn/2.0))).ytrn(dy*(y-(yn/2.0))) for x in range(xn) for y in range(yn)] #vgrid = [p for p in vgrid if abs(p.x-10) > 10] boxes = [p.cp().trn(o.flp()).rot(bq).trn(o.flp()).sq(dx,dy) for p in vgrid] for b in boxes: bcom = vec3(0,0,0).com(b).flp() bcom.trnos(b) bq.rotps(b) bcom.flp().trnos(b) boxes = [b for b in boxes if pym.binbxy(b,vbcon)] for ib in vb[1]: boxes = [b for b in boxes if not pym.bintbxy(b,ib) and not b[0].inbxy(ib) and not ib[0].inbxy(b[0])] blgfps = pym.ebuxy_special(boxes,5,4) ps = [vec3(0,0,0).com(blgfp) for blgfp in blgfps] qs = [bq.cp() for blgfp in blgfps] ss = [vec3(1,1,1) for blgfp in blgfps] for p,q,s,blgfp in zip(ps,qs,ss,blgfps): p.cpxy().flp().trnos(blgfp) q.cpf().rotps(blgfp) return zip(ps,qs,ss,blgfps)
def pepper(t, tip, e=2): print('pepper') c = vec3(0, 0, 0).com(tip.loop) d = vec3(1, 0, 0).uscl(1000) s1, s2 = c.cp().trn(d.flp()), c.cp().trn(d.flp()) ch = lambda b: pyg.chunk( b, e, random.random() + 0.2, edge=random.randint(0, 1)) bs = [ch(tip.loop) for x in range(10)] bs = pym.bsuxy(bs, e) #ax = dtl.plot_axes_xy(200) #for b in bs: # dtl.plot_polygon_xy(b,ax,lw = 2) #plt.show() newtips = [] for sb in bs: if not pym.bccw(sb): sb.reverse() sb = pyg.ajagged(sb, 2) sb = pyg.ajagged(sb, 2) sb = pyg.ajagged(sb, 2) #sb = pyg.ajagged(sb,2) #for x in range(3):b = pyg.ajagged(b,e) sb = pym.bisectb(sb) #sb = pym.smoothxy(sb,0.5,e) sb = pym.smoothxy(sb, 0.5, e) sb = pym.aggregate(sb, 4) #sb = pym.blimithmin(sb,2,50) for p in sb: p.ztrn(2) newtips.append(t.al(sb, tip)) ax = dtl.plot_axes(200) ax = dtl.plot_polygon(t.root.loop, ax, ls='--', lw=2, col='k') ax = dtl.plot_polygon(tip.loop, ax, lw=3, col='r') for b in bs: ax = dtl.plot_polygon(b, ax, lw=3, col='g') plt.show() return newtips
def raise_earth(topo,tips,e,mingrad = 1.0,mindelz = -5.0,depth = 0): if depth == 0: for j,tip in enumerate(tips): tips[j].loop = pym.bisectb(tips[j].loop) #if depth == 10:return print('... raising earth ... (depth: %d)' % depth) newtips = [] for tip in tips: if tip is None:continue newloop = [p.cp().ztrn(mindelz) for p in tip.loop] newloop = pym.aggregate(pym.contract(newloop,abs(mindelz/mingrad)),5) #uloops = [pym.smoothxyi(newloop,0.8,e,10,1)] #uloops = [pym.pinchb(u,10) for u in uloops if u] #uloops = [pym.pinchb(newloop,10)] uloops = pym.pinchb(newloop,10) uloops = [u for u in uloops if u] for u in uloops: if not pym.bccw(u): u.reverse() ''' if len(uloops) == 1: print('... 1 loop to raise ...') theloop = uloops[0] newtiparea = pym.bareaxy(theloop,True) elif uloops: print('... 2+ loops to raise ...') bareas = [pym.bareaxy(u,True) for u in uloops] theloop = uloops[bareas.index(max(bareas))] newtiparea = max(bareas) else: print('... no loops to raise ...') theloop = [] ''' for theloop in uloops: newtiparea = pym.bareaxy(theloop,True) newtip = None if theloop and newtiparea > 10:#2*(e)**2: newtip = topo.avert(tip,loop = theloop) else:print('... abortive tip! ...') if newtip is None:continue else:newtips.append(newtip) if newtips: terrain.raise_earth(topo,newtips,e,mingrad,mindelz,depth+1) else:print('... exhausted tip! ...')
def pepper(t,tip,e = 2): print('pepper') c = vec3(0,0,0).com(tip.loop) d = vec3(1,0,0).uscl(1000) s1,s2 = c.cp().trn(d.flp()),c.cp().trn(d.flp()) ch = lambda b : pyg.chunk(b,e,random.random()+0.2,edge = random.randint(0,1)) bs = [ch(tip.loop) for x in range(10)] bs = pym.bsuxy(bs,e) #ax = dtl.plot_axes_xy(200) #for b in bs: # dtl.plot_polygon_xy(b,ax,lw = 2) #plt.show() newtips = [] for sb in bs: if not pym.bccw(sb):sb.reverse() sb = pyg.ajagged(sb,2) sb = pyg.ajagged(sb,2) sb = pyg.ajagged(sb,2) #sb = pyg.ajagged(sb,2) #for x in range(3):b = pyg.ajagged(b,e) sb = pym.bisectb(sb) #sb = pym.smoothxy(sb,0.5,e) sb = pym.smoothxy(sb,0.5,e) sb = pym.aggregate(sb,4) #sb = pym.blimithmin(sb,2,50) for p in sb:p.ztrn(2) newtips.append(t.al(sb,tip)) ax = dtl.plot_axes(200) ax = dtl.plot_polygon(t.root.loop,ax,ls = '--',lw = 2,col = 'k') ax = dtl.plot_polygon(tip.loop,ax,lw = 3,col = 'r') for b in bs: ax = dtl.plot_polygon(b,ax,lw = 3,col = 'g') plt.show() return newtips
def grow(self,par,z,r,epsilon,base = None): if base is None:base = [p.cp() for p in par.loop] i = base[:] i = pym.contract(i,r,epsilon) if i is None:return None #i = pym.smoothxy(i,0.5,epsilon) #i = pym.smoothxy(i,0.5,epsilon) #i = pym.smoothxy(i,0.5,epsilon) i = pym.aggregate(i,r) #i = pym.cleanbxy(i,2.0) bv = pym.bvalidxy(i,epsilon) if bv == -1:i.reverse() elif bv == -2: return None raise ValueError if len(i) > 3:lout = i else:return None for p in lout:p.ztrn(z) iv = self.avert(par,loop = lout) return iv
def split(self,v,s,z,rad,epsilon): sp = vec3(0,0,0).com(v.loop) sd = vec3(0,1,0) if random.random() > 0.5 else vec3(1,0,0) s1 = sp.cp().trn(sd.cp().uscl( 10000)) s2 = sp.cp().trn(sd.cp().uscl(-10000)) loops = pym.bsegsxy(v.loop,s1,s2,0.1) lvs = [] for el in loops: if not pym.bccw(el):el.reverse() el = pym.blimithmin(el,2,50) el = pym.aggregate(el,2) #el = pym.smoothxy(el,0.5,epsilon) nv = self.grow(v,z,rad,epsilon,el) lvs.append(nv) ax = self.plot() for el in loops: ax = dtl.plot_polygon(el,ax,lw = 2,col = 'r') plt.show() return lvs
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
def vblgsplotch(self, v, pg, easement=10): vb = v[1]['b'] vbes = [(vb[0][x - 1], vb[0][x]) for x in range(len(vb[0]))] vbels = [vb[0][x - 1].d(vb[0][x]) for x in range(len(vb[0]))] vbe_primary = vbels.index(max(vbels)) vbe_primary_tn = vb[0][vbe_primary - 1].tov(vb[0][vbe_primary]).nrm() bq = quat(0, 0, 0, 1).uu(vec3(1, 0, 0), vbe_primary_tn) if not bq: bq = quat(1, 0, 0, 0) #bq = quat(1,0,0,0) vbcon = pym.aggregate(pym.contract(vb[0], easement), 5) #vbcon = pym.aggregate(pym.contract(vb[0],0),5) #ax = dtl.plot_axes_xy(120) #ax = dtl.plot_polygon_xy(vbcon,ax,lw = 3,col = 'g') #plt.show() #if len(fbnd) > 3:fbnd = pinchb(fbnd,epsilon) vbxpj = vbe_primary_tn.prjps(vb[0]) vbypj = vbe_primary_tn.cp().zrot(gtl.PI2).prjps(vb[0]) vbxl, vbyl = vbxpj[1] - vbxpj[0], vbypj[1] - vbypj[0] dx, dy = 20, 20 xn, yn = int(1.5 * vbxl / dx), int(1.5 * vbyl / dy) print('xn,yn', xn, yn) #do = vec3(-dx*xn/2.0,-dy*yn/2.0,0) o = vec3(0, 0, 0).com(vbcon) vgrid = [ o.cp().xtrn(dx * (x - (xn / 2.0))).ytrn(dy * (y - (yn / 2.0))) for x in range(xn) for y in range(yn) ] boxes = [ p.cp().trn(o.flp()).rot(bq).trn(o.flp()).sq(dx, dy) for p in vgrid ] #boxes = [p.cp().trn(o.flp()).rot(bq).trn(o.flp()).sq(dx,dy) # for p in vgrid if abs(p.x - o.x) > dx] for b in boxes: bcom = vec3(0, 0, 0).com(b).flp() bcom.trnos(b) bq.rotps(b) bcom.flp().trnos(b) boxes = [b for b in boxes if pym.binbxy(b, vbcon)] for ib in vb[1]: boxes = [ b for b in boxes if not pym.bintbxy(b, ib) and not b[0].inbxy(ib) and not ib[0].inbxy(b[0]) ] '''# ax = dtl.plot_axes_xy(400) ax = dtl.plot_point_xy(o,ax) ax = dtl.plot_polygon_xy(vb[0],ax,lw = 2,col = 'b') ax = dtl.plot_polygon_xy(vbcon,ax,ls = '--',lw = 2,col = 'r') #ax = dtl.plot_polygon_xy(box,ax,lw = 2,col = 'r') for b in boxes:ax = dtl.plot_polygon_xy(b,ax,lw = 2,col = 'g') plt.show() '''# #blgfps = pym.bsuxy(boxes) blgfps = pym.ebuxy_special(boxes, 5, 4) ps = [vec3(0, 0, 0).com(blgfp) for blgfp in blgfps] qs = [bq.cp() for blgfp in blgfps] ss = [vec3(1, 1, 1) for blgfp in blgfps] for p, q, s, blgfp in zip(ps, qs, ss, blgfps): p.cpxy().flp().trnos(blgfp) q.cpf().rotps(blgfp) '''# ax = dtl.plot_axes_xy(700) ax = dtl.plot_point_xy(o,ax) ax = dtl.plot_polygon_xy(vb[0],ax,lw = 2,col = 'b') #ax = dtl.plot_polygon_xy(box,ax,lw = 2,col = 'r') for b in boxes:ax = dtl.plot_polygon_xy(b,ax,lw = 2,col = 'g') for b in blgfps:ax = dtl.plot_polygon_xy(b,ax,lw = 2,col = 'r') plt.show() '''# '''# bx,by,sx,sy = -30,30,30,30 r = abs(random.random())*20 bz = v[1]['tmesh'](bx,by)+r blgfps.append(vec3(bx,by,bz).sq(sx,sy)) bx,by,sx,sy = 30,30,50,30 r = abs(random.random())*20 bz = v[1]['tmesh'](bx,by)+r blgfps.append(vec3(bx,by,bz).sq(sx,sy)) bx,by,sx,sy = 30,-30,40,60 r = abs(random.random())*20 bz = v[1]['tmesh'](bx,by)+r blgfps.append(vec3(bx,by,bz).sq(sx,sy)) '''# #blgfps.append(vec3(bx,by,v[1]['tmesh'](bx,by)).sq(sx,sy)) #bx,by,sx,sy = 30,30,50,30 #blgfps.append(vec3(bx,by,v[1]['tmesh'](bx,by)).sq(sx,sy)) #bx,by,sx,sy = 30,-30,40,60 #blgfps.append(vec3(bx,by,v[1]['tmesh'](bx,by)).sq(sx,sy)) #for blgfp in blgfps: # r = v[1]['b'][0][0].z+abs(random.random())*20 # for p in blgfp: # p.ztrn(r) return zip(ps, qs, ss, blgfps)