예제 #1
0
def opass():
    g = graph()

    bnd = dpr.square(100,100)
    oprgn1 = grg.overpass(bnd)
    oprgn1._graph(g)

    bnd = dpr.square(100,100,dpv.vector(500,0,0),dpr.rad(75))
    oprgn2 = grg.overpass(bnd)
    oprgn2._graph(g)

    bnd = dpr.square(100,100,dpv.vector(250,200,0),dpr.rad(35))
    oprgn3 = grg.overpass(bnd)
    oprgn3._graph(g)

    oprgn1._connect(oprgn2,g)
    oprgn2._connect(oprgn3,g)
    oprgn3._connect(oprgn1,g)

    g._update()

    ax = dtl.plot_axes()
    ax = oprgn1.plot(ax)
    ax = oprgn2.plot(ax)
    ax = oprgn3.plot(ax)
    ax = g.plot(ax)
    ax.set_zlim([0,40])

    plt.show()

    return g
예제 #2
0
 def _walk(self, sndkey, wise):
     if sndkey == self.one.key(): share, unshare = self.one, self.two
     elif sndkey == self.two.key(): share, unshare = self.two, self.one
     turns = [k for k in share.ring if not k == unshare.index]
     tncnt = len(turns)
     if tncnt == 0: return None
     elif tncnt == 1: return turns[0]
     else:
         fa = dpr.rad(share.targetring[unshare.index])
         tangles = [dpr.rad(share.targetring[x]) for x in turns]
         adists = [
             dpr.clamp_periodic(fa - ta, 0, dpr.twoPI) for ta in tangles
         ]
         turns = list(list(zip(*sorted(zip(adists, turns))))[1])
         if not wise == 0: turns.reverse()
         '''#
         e1d = dpv.x().rotate_z(fa)
         e1 = [share.p.copy(),share.p.copy().translate(e1d)]
         oes = []
         tps = []
         for tn in turns:
             t = dpr.rad(share.targetring[tn])
             oed = dpv.x().rotate_z(t)
             oe  = [share.p.copy(),share.p.copy().translate(oed)]
             oes.append(oe)
             tps.append(oe[1])
         ax = dtl.plot_axes_xy()
         ax = dtl.plot_edges_xy(e1,ax,lw = 5)
         for oe in oes:
             ax = dtl.plot_edges_xy(oe,ax)
         ax = dtl.plot_points_xy(tps,ax,number = True)
         plt.show()
         '''#
         return turns[0]
예제 #3
0
 def _walk(self,sndkey,wise):
     if   sndkey == self.one.key():share,unshare = self.one,self.two
     elif sndkey == self.two.key():share,unshare = self.two,self.one
     turns = [k for k in share.ring if not k == unshare.index]
     tncnt = len(turns)
     if tncnt == 0:return None
     elif tncnt == 1:return turns[0]
     else:
         fa = dpr.rad(share.targetring[unshare.index])
         tangles = [dpr.rad(share.targetring[x]) for x in turns]
         adists = [dpr.clamp_periodic(fa-ta,0,dpr.twoPI) for ta in tangles]
         turns = list(list(zip(*sorted(zip(adists,turns))))[1])
         if not wise == 0:turns.reverse()
         '''#
         e1d = dpv.x().rotate_z(fa)
         e1 = [share.p.copy(),share.p.copy().translate(e1d)]
         oes = []
         tps = []
         for tn in turns:
             t = dpr.rad(share.targetring[tn])
             oed = dpv.x().rotate_z(t)
             oe  = [share.p.copy(),share.p.copy().translate(oed)]
             oes.append(oe)
             tps.append(oe[1])
         ax = dtl.plot_axes_xy()
         ax = dtl.plot_edges_xy(e1,ax,lw = 5)
         for oe in oes:
             ax = dtl.plot_edges_xy(oe,ax)
         ax = dtl.plot_points_xy(tps,ax,number = True)
         plt.show()
         '''#
         return turns[0]
예제 #4
0
파일: osm.py 프로젝트: ctogle/dilapidator
def haverside(p1,p2,l1,l2,earthradius = 6371000):
    p1,p2,l1,l2 = dpr.rad(p1),dpr.rad(p2),dpr.rad(l1),dpr.rad(l2) 
    dp = abs(p1-p2)
    dl = abs(l1-l2)
    p = math.sin(dp/2)**2
    l = math.cos(p1)*math.cos(p2)*math.sin(dl/2)**2
    h = 2*earthradius*math.asin(math.sqrt(p+l))
    return h
예제 #5
0
파일: osm.py 프로젝트: ctogle/dilapidator
def haverside(p1, p2, l1, l2, earthradius=6371000):
    p1, p2, l1, l2 = dpr.rad(p1), dpr.rad(p2), dpr.rad(l1), dpr.rad(l2)
    dp = abs(p1 - p2)
    dl = abs(l1 - l2)
    p = math.sin(dp / 2)**2
    l = math.cos(p1) * math.cos(p2) * math.sin(dl / 2)**2
    h = 2 * earthradius * math.asin(math.sqrt(p + l))
    return h
예제 #6
0
파일: road.py 프로젝트: ctogle/dilapidator
    def calculate(self, controls=[]):
        self.tipnormal = self.tip.copy().flip().xy()
        self.tipnormal.rotate_z(dpr.rad(-90)).normalize()
        self.tailnormal = self.tail.copy().xy()
        self.tailnormal.rotate_z(dpr.rad(90)).normalize()

        self.controls = [self.start.copy(), self.end.copy()]
        self.calculate_tips(controls)
        self.calculate_vertices()
예제 #7
0
 def _walk(self,sndkey,wise):
     if   sndkey == self.one.key():share,unshare = self.one,self.two
     elif sndkey == self.two.key():share,unshare = self.two,self.one
     turns = [k for k in share.ring if not k == unshare.index]
     tncnt = len(turns)
     if tncnt == 0:return None
     elif tncnt == 1:return turns[0]
     else:
         fa = dpr.rad(share.targetring[unshare.index])
         tangles = [dpr.rad(share.targetring[x]) for x in turns]
         adists = [dpr.clamp_periodic(fa-ta,0,dpr.twoPI) for ta in tangles]
         turns = list(list(zip(*sorted(zip(adists,turns))))[1])
         if not wise == 0:turns.reverse()
         return turns[0]
예제 #8
0
 def _place_road(self,graph):                       
     rcnt = int(self.tangent.magnitude()/8.0)
     spk1 = self.one.p.copy().translate(self.one.spikes[self.two.index])
     spk2 = spk1.copy().translate(self.one.spikes[self.two.index])
     spk4 = self.two.p.copy().translate(self.two.spikes[self.one.index])
     spk3 = spk4.copy().translate(self.two.spikes[self.one.index])
     if self.interpolated:rpts = dpv.vector_spline(spk1,spk2,spk3,spk4,rcnt)
     else:rpts = dpr.point_line(spk1,spk4,rcnt)
     self.rpts = rpts
     self.rtangents = []
     self.rnormals = []
     self.lbpts = []
     self.rbpts = []
     for rpx in range(1,len(rpts)):
         rtangent = dpv.v1_v2(rpts[rpx-1],rpts[rpx]).xy().normalize()
         rnormal = rtangent.copy().rotate_z(dpr.rad(90)).normalize()
         self.rtangents.append(rtangent)
         self.rnormals.append(rnormal)
         rwv = rnormal.copy().scale_u(self.width/2.0)             
         self.lbpts.append(rpts[rpx-1].copy().translate(rwv))
         self.rbpts.append(rpts[rpx-1].copy().translate(rwv.flip()))
     self.rtangents.append(self.rtangents[-1])
     self.rnormals.append(self.rnormals[-1])
     rwv = self.rnormals[-1].copy().scale_u(self.width/2.0)
     self.lbpts.append(rpts[-1].copy().translate(rwv))
     self.rbpts.append(rpts[-1].copy().translate(rwv.flip()))
     self.lbpts.reverse()
예제 #9
0
 def _place_road(self,graph):                       
     rcnt = int(self.tangent.magnitude()/8.0)
     spk1 = self.one.p.copy().translate(self.one.spikes[self.two.index])
     spk2 = spk1.copy().translate(self.one.spikes[self.two.index])
     spk4 = self.two.p.copy().translate(self.two.spikes[self.one.index])
     spk3 = spk4.copy().translate(self.two.spikes[self.one.index])
     if self.interpolated:rpts = dpv.vector_spline(spk1,spk2,spk3,spk4,rcnt)
     else:rpts = dpr.point_line(spk1,spk4,rcnt)
     self.rpts = rpts
     self.rtangents = []
     self.rnormals = []
     self.lbpts = []
     self.rbpts = []
     for rpx in range(1,len(rpts)):
         rtangent = dpv.v1_v2(rpts[rpx-1],rpts[rpx]).xy().normalize()
         rnormal = rtangent.copy().rotate_z(dpr.rad(90)).normalize()
         self.rtangents.append(rtangent)
         self.rnormals.append(rnormal)
         rwv = rnormal.copy().scale_u(self.width/2.0)             
         self.lbpts.append(rpts[rpx-1].copy().translate(rwv))
         self.rbpts.append(rpts[rpx-1].copy().translate(rwv.flip()))
     self.rtangents.append(self.rtangents[-1])
     self.rnormals.append(self.rnormals[-1])
     rwv = self.rnormals[-1].copy().scale_u(self.width/2.0)
     self.lbpts.append(rpts[-1].copy().translate(rwv))
     self.rbpts.append(rpts[-1].copy().translate(rwv.flip()))
     self.lbpts.reverse()
예제 #10
0
 def __init__(self,*args,**kwargs):
     self._def('axiom','X',**kwargs)
     self._def('rules',[('X','F-[[X]+X]+F[+FX]-X'),('F','FF')],**kwargs)
     self._def('iterations',3,**kwargs) # number of iterations
     self._def('angle',dpr.rad(25),**kwargs) # angle used for rotations
     self._def('seed',0,**kwargs) # seed used for random numbers
     lsystem.__init__(self,*args,**kwargs)
예제 #11
0
파일: wall.py 프로젝트: ctogle/dilapidator
 def _endpoints(self,v1,v2):
     self.v1 = v1.copy()
     self.v2 = v2.copy()
     self.l = dpv.distance(v1,v2)
     self.center = dpv.midpoint(v1,v2)
     self.tangent = dpv.v1_v2(v1,v2).normalize()
     self.normal = self.tangent.copy()
     self.normal.rotate_z(dpr.rad(90)).normalize()
예제 #12
0
 def __init__(self,*args,**kwargs):
     #self._def('axiom','F',**kwargs)
     #self._def('rules',[('F','F[+F]F[-F]F')],**kwargs)
     self._def('axiom','X',**kwargs)
     self._def('rules',[('X','F[+X][-X]FX'),('F','FF')],**kwargs)
     self._def('iterations',5,**kwargs) # number of iterations
     self._def('angle',dpr.rad(25.7),**kwargs) # angle used for rotations
     self._def('seed',0,**kwargs) # seed used for random numbers
     lsystem.__init__(self,*args,**kwargs)
예제 #13
0
 def face_away(self, side):
     rp = side[1]['room']
     intpt = dpv.vector(rp[1]['x'], rp[1]['y'], 0.0)
     midpt = dpv.midpoint(*side[0])
     tangt = dpv.v1_v2(*side[0]).normalize()
     norml = tangt.copy().rotate_z(dpr.rad(90)).normalize()
     tstpt = midpt.copy().translate(norml)
     side[1]['normal'] = norml
     if dpv.distance(intpt, midpt) > dpv.distance(intpt, tstpt):
         side[1]['normal'].flip()
예제 #14
0
 def face_away(self,side):
     rp = side[1]['room']
     intpt = dpv.vector(rp[1]['x'],rp[1]['y'],0.0)
     midpt = dpv.midpoint(*side[0])
     tangt = dpv.v1_v2(*side[0]).normalize()
     norml = tangt.copy().rotate_z(dpr.rad(90)).normalize()
     tstpt = midpt.copy().translate(norml)
     side[1]['normal'] = norml
     if dpv.distance(intpt,midpt) > dpv.distance(intpt,tstpt):
         side[1]['normal'].flip()
예제 #15
0
def smatter():
    g = graph()

    g._node(node(dpv.vector(0,0,0)))
    for x in range(100):
        ndx = rm.choice(range(g.nodecount))
        rcnt = len(g.nodes[ndx].ring)
        if rcnt == 0:
            ndd = dpv.xhat.copy()
            ndd.rotate_z(dpr.rad(rm.choice(range(360))))
            ndd.scale_u(rm.choice([100,200,300]))
        elif rcnt == 1:
            ndir = next(iter(g.nodes[ndx].ring.values()))
            nda = ndir+180 if ndir < 180 else ndir - 180
            ndd = dpv.xhat.copy().rotate_z(dpr.rad(nda))
            ndd.scale_u(rm.choice([100,200,300]))
        elif rcnt == 2:
            r1,r2 = tuple(g.nodes[ndx].ring.values())
            mpt = (r1+r2)/2.0
            nda = mpt+180 if mpt < 180 else mpt - 180
            ndd = dpv.xhat.copy().rotate_z(dpr.rad(nda))
            ndd.scale_u(rm.choice([100,200,300]))
        elif rcnt == 3:
            t1,t2,t3 = tuple(g.nodes[ndx].ring.values())
            d1,d2,d3 = adist(t1,t2),adist(t2,t3),adist(t3,t1)
            if   d1 > d2 and d1 > d3:nda = (t1+t2)/2.0
            elif d2 > d1 and d2 > d3:nda = (t2+t3)/2.0
            elif d3 > d1 and d3 > d2:nda = (t3+t1)/2.0
            ndd = dpv.xhat.copy().rotate_z(dpr.rad(nda))
            ndd.scale_u(rm.choice([100,200,300]))
        elif rcnt == 4:
            print('this node cannot be more connected!',ndx)
        #g._extrude_safe(ndx,ndd)
        g._extrude(ndx,ndd)

        #g._update()

        #ax = g.plot_xy()
        #ax.set_aspect('equal')
        #plt.show()

    return g
예제 #16
0
    def _spikes_nudge(self,graph,target):
        ws = []
        angles = []
        tkeys = list(self.targetring.keys())
        for tk in tkeys:
            ekey = (self.key(),graph.nodes[tk].key())
            edx = graph.edges_lookup[ekey]
            ws.append(1.0 if graph.edges[edx].interpolated else 0.0)
            angles.append(self.targetring[tk])

        iangles = nudge(angles,ws,target = target)
        nr = self._node_radius(graph)
        for tk,na in zip(tkeys,iangles):
            self.ring[tk] = na
            #spike = dpv.xhat.copy().rotate_z(dpr.rad(na)).scale_u(8)
            spike = dpv.vector(1,0,0).rotate_z(dpr.rad(na)).scale_u(nr)
            self.spikes[tk] = spike
예제 #17
0
    def _connect_edges(self,o,sedgex,oedgex,g,**kwargs):
        splugs,oplugs = self._plugsonedge(sedgex),o._plugsonedge(oedgex)
        spgcnt,opgcnt = len(splugs),len(oplugs)

        spkeys = self._plugkeys()
        subspkeys = [spkeys[splugs[x]] for x in range(spgcnt)]
        opkeys = o._plugkeys()
        subopkeys = [opkeys[oplugs[x]] for x in range(opgcnt)]
        b1,b2 = self._tangent(o).rotate_z(dpr.rad(90)).normalize(),dpv.zhat.copy()
        sps = dpv.projected_order([dpv.vector(*spk) for spk in subspkeys],b1,b2)
        ops = dpv.projected_order([dpv.vector(*opk) for opk in subopkeys],b1,b2)

        if spgcnt == opgcnt:pgpairs = [(x,y) for x,y in zip(sps,ops)]
        else:
            print('plug ambiguity!!!')
            pdb.set_trace()

        for pgpair in pgpairs:
            pkey1,pkey2 = spkeys[splugs[pgpair[0]]],opkeys[oplugs[pgpair[1]]]
            g._add_edge(pkey1,pkey2,**kwargs)
            print('added edge',pkey1,pkey2)
예제 #18
0
    def _connect_edges(self, o, sedgex, oedgex, g, **kwargs):
        splugs, oplugs = self._plugsonedge(sedgex), o._plugsonedge(oedgex)
        spgcnt, opgcnt = len(splugs), len(oplugs)

        spkeys = self._plugkeys()
        subspkeys = [spkeys[splugs[x]] for x in range(spgcnt)]
        opkeys = o._plugkeys()
        subopkeys = [opkeys[oplugs[x]] for x in range(opgcnt)]
        b1, b2 = self._tangent(o).rotate_z(
            dpr.rad(90)).normalize(), dpv.zhat.copy()
        sps = dpv.projected_order([dpv.vector(*spk) for spk in subspkeys], b1,
                                  b2)
        ops = dpv.projected_order([dpv.vector(*opk) for opk in subopkeys], b1,
                                  b2)

        if spgcnt == opgcnt: pgpairs = [(x, y) for x, y in zip(sps, ops)]
        else:
            print('plug ambiguity!!!')
            pdb.set_trace()

        for pgpair in pgpairs:
            pkey1, pkey2 = spkeys[splugs[pgpair[0]]], opkeys[oplugs[pgpair[1]]]
            g._add_edge(pkey1, pkey2, **kwargs)
            print('added edge', pkey1, pkey2)