Exemplo n.º 1
0
 def grow(self,plans,length = None,side = None,force = False):
     side = self.grow_side(plans,side)
     if side is None:return False
     gleng = self.grow_length(plans,length,side)
     if gleng is None:return False
     self.face_away(side)
     v1,v2 = side[0]
     c1 = v2.copy()
     c2 = v1.copy()
     c3,c4 = dpr.extrude_edge(c1,c2,gleng,side[1]['normal'])
     newcorners = [c1,c2,c3,c4]
     x,y,z = dpv.center_of_mass(newcorners)
     xpj = dpv.project_coords(newcorners,dpv.x())
     ypj = dpv.project_coords(newcorners,dpv.y())
     l,w = xpj.y-xpj.x,ypj.y-ypj.x
     margs = ((),{'x':x,'y':y,'l':l,'w':w,'shafted':False})
     self.create_bbox(margs)
     if not self.verify_growth(plans,margs):return False
     splan = self.should_shaft(plans,margs)
     cpairs = [(c2,c3),(c3,c4),(c4,c1)]
     iwargs = []
     ewargs = [[cp,
         {'h':4.0,'w':0.5,'walltype':'exterior','room':margs}] 
             for cp in cpairs]
     self.switch_walltype(plans,side)
     if self.resolve_walls(plans,ewargs,iwargs,margs):
         rps,eps,ips,sps = plans
         rps.append(margs)
         eps.extend(ewargs)
         ips.extend(iwargs)
         if splan:sps.append(splan)
         return True
     else:return False
Exemplo n.º 2
0
 def _cover(self,radius = 100,tri_edgelength = 10,mod_edgelength = 250):
     convexcover = dpr.pts_to_convex_xy(self.regions)
     dpr.inflate(convexcover,radius)
     pts,tris = dpr.triangle_cover(convexcover,mod_edgelength)
     wts = [dpv.one() for x in pts]
     self.center = dpv.center_of_mass(convexcover)
     return pts,wts,tris,convexcover
Exemplo n.º 3
0
 def _geo(self,n = 8):
     bottom = dpr.point_ring(1,n)
     dpv.translate_coords_z(bottom,-0.5)
     top = dpv.center_of_mass(bottom).translate_z(1)
     bottom.reverse()
     self._tripie(bottom)
     bottom.append(bottom[0])
     bottom.reverse()
     self._trifan(top,bottom)
Exemplo n.º 4
0
 def _geo(self):
     n = 8
     bottom = dpr.point_ring(self.radius, n)
     top = dpv.center_of_mass(bottom).translate_z(self.height)
     bottom.reverse()
     self._tripie(bottom)
     bottom.append(bottom[0])
     bottom.reverse()
     self._trifan(top, bottom)
Exemplo n.º 5
0
 def _geo(self, n=8):
     bottom = dpr.point_ring(1, n)
     dpv.translate_coords_z(bottom, -0.5)
     top = dpv.center_of_mass(bottom).translate_z(1)
     bottom.reverse()
     self._tripie(bottom)
     bottom.append(bottom[0])
     bottom.reverse()
     self._trifan(top, bottom)
Exemplo n.º 6
0
def polygons_incomplex(p1s,plc2):
    plc2.refine,plc2.smooth = False,False
    plc2.triangulate()
    tris = plc2.simplices
    outpolyhedron = []
    for x in range(len(p1s)):
        point = dpv.center_of_mass(list(p1s[x][0]))
        if inpolyhedron(point,tris):outpolyhedron.append(p1s[x])
    return outpolyhedron
Exemplo n.º 7
0
def orient_loop(loop,targetnormal,control = None):
    if control is None:control = dpv.center_of_mass(loop)
    n = normal(*loop[:3])
    if n == targetnormal.copy().flip():
        #print('HACK?')
        #qrot = dpq.q_from_av(numpy.pi,dpv.zhat)
        qrot = dpq.q_from_av(PI,dpv.yhat)
    else:qrot = dpq.q_from_uu(n,targetnormal)
    looprot = dpq.rotate_coords(loop,control,qrot)
    return looprot
Exemplo n.º 8
0
    def populate(self):
        def clear(b):
            b = tuple(dpr.inflate([bp.copy() for bp in b], 2))
            clr = True
            '''#
            if dpr.concaves_intersect(bnd,b):return False
            if not dpr.inconcave(b[0],bnd):return False
            for h in holes:
                if dpr.concaves_intersect(h,b):return False
                if dpr.inconcave(b[0],h):return False
            for p in prints:
                if dpr.concaves_intersect(p,b):return False
                if dpr.inconcave(b[0],p):return False
            '''#
            if dpr.concaves_intersect(bnd, b): clr = False
            if not dpr.inconcave_xy(b[0], bnd): clr = False
            for h in holes:
                if dpr.concaves_intersect(h, b): clr = False
                if dpr.inconcave_xy(b[0], h): clr = False
            for p in prints:
                if dpr.concaves_intersect(p, b): clr = False
                if dpr.inconcave_xy(b[0], p): clr = False

            #if not clr:
            if False:
                ax = dtl.plot_axes_xy()
                ax = dtl.plot_polygon_xy(list(bnd), ax, lw=1)
                ax = dtl.plot_polygon_xy(list(b), ax, lw=5)
                for h in holes:
                    ax = dtl.plot_polygon_xy(list(h), ax, lw=2)
                for p in prints:
                    ax = dtl.plot_polygon_xy(list(p), ax, lw=1)
                plt.show()

            #return True
            return clr

        bnd = self.boundary[0]
        holes = self.boundary[1]

        '''#
        prints = []
        for segx in range(1,len(bnd)):
            p1,p2 = bnd[segx-1],bnd[segx]
            tn = dpv.v1_v2(p1,p2).normalize()
            nn = tn.copy().rotate_z(-dpr.PI/2.0)
            bl,bw,bh = 50,50,20
            segp = tn.copy().scale_u(bl/2.0)+nn.copy().scale_u(bw)
            p,r = p1 + segp,dpr.angle_from_xaxis_xy(tn)
            lfootprint = tuple(dpr.square(bl,bw,p,r))
            if clear(lfootprint):prints.append(lfootprint)
        '''#
        prints = [tuple(dpr.square(50, 50, dpv.center_of_mass(list(bnd))))]

        self.lfootprints = prints
Exemplo n.º 9
0
    def populate(self):
        def clear(b):
            b = tuple(dpr.inflate([bp.copy() for bp in b],2))
            clr = True
            '''#
            if dpr.concaves_intersect(bnd,b):return False
            if not dpr.inconcave(b[0],bnd):return False
            for h in holes:
                if dpr.concaves_intersect(h,b):return False
                if dpr.inconcave(b[0],h):return False
            for p in prints:
                if dpr.concaves_intersect(p,b):return False
                if dpr.inconcave(b[0],p):return False
            '''#
            if dpr.concaves_intersect(bnd,b):clr = False
            if not dpr.inconcave_xy(b[0],bnd):clr = False
            for h in holes:
                if dpr.concaves_intersect(h,b):clr = False
                if dpr.inconcave_xy(b[0],h):clr = False
            for p in prints:
                if dpr.concaves_intersect(p,b):clr = False
                if dpr.inconcave_xy(b[0],p):clr = False

            #if not clr:
            if False:
                ax = dtl.plot_axes_xy()
                ax = dtl.plot_polygon_xy(list(bnd),ax,lw = 1)
                ax = dtl.plot_polygon_xy(list(b),ax,lw = 5)
                for h in holes:
                    ax = dtl.plot_polygon_xy(list(h),ax,lw = 2)
                for p in prints:
                    ax = dtl.plot_polygon_xy(list(p),ax,lw = 1)
                plt.show()

            #return True
            return clr
        bnd = self.boundary[0]
        holes = self.boundary[1]

        '''#
        prints = []
        for segx in range(1,len(bnd)):
            p1,p2 = bnd[segx-1],bnd[segx]
            tn = dpv.v1_v2(p1,p2).normalize()
            nn = tn.copy().rotate_z(-dpr.PI/2.0)
            bl,bw,bh = 50,50,20
            segp = tn.copy().scale_u(bl/2.0)+nn.copy().scale_u(bw)
            p,r = p1 + segp,dpr.angle_from_xaxis_xy(tn)
            lfootprint = tuple(dpr.square(bl,bw,p,r))
            if clear(lfootprint):prints.append(lfootprint)
        '''#
        prints = [tuple(dpr.square(50,50,dpv.center_of_mass(list(bnd))))]

        self.lfootprints = prints
Exemplo n.º 10
0
 def _geo(self):
     for pdx in range(self.pieces):
         zero = dpv.zero()
         p1 = self._point(zero)
         p2 = self._point(p1)
         ps = [p1, p2]
         t = random.random() * 2 * numpy.pi
         dpv.rotate_z_coords_about(ps, dpv.center_of_mass(ps), t)
         p3 = p2.copy().translate_z(self.height)
         p4 = p1.copy().translate_z(self.height)
         nfs = self._quad(p4, p1, p2, p3, m='grass4')
         self._scale_uv_v(nfs, 0.75)
         self._translate_uv_v(nfs, 0.05)
Exemplo n.º 11
0
 def _tripie(self,loop,ns = None,us = None,m = None):
     nfstart = len(self.faces)
     lcom = dpv.center_of_mass(loop)
     tcnt = len(loop)
     for trdx in range(tcnt):
         c2dx = trdx
         c3dx = trdx+1
         if c3dx == tcnt: c3dx = 0
         c1 = lcom.copy()
         c2 = loop[c2dx].copy()
         c3 = loop[c3dx].copy()
         self._triangle(c1,c2,c3,ns,us,m)
     nfend = len(self.faces)
     return range(nfstart,nfend)
Exemplo n.º 12
0
def polygon(n):
    angle = 360.0/n
    turns = [x*angle for x in range(n)]
    poly = [dpv.zero()]
    current_angle = 0.0
    for si in range(n):
        l,t = 1.0,turns[si]
        current_angle = t
        dx = l*numpy.cos(rad(current_angle))
        dy = l*numpy.sin(rad(current_angle))
        new = poly[-1].copy().translate_x(dx).translate_y(dy)
        poly.append(new)
    poly.pop()
    dpv.translate_coords(poly,dpv.center_of_mass(poly).flip())
    return poly
Exemplo n.º 13
0
    def _bridge_patch(self,loop,n = 10,m = None):
        nfstart = len(self.faces)
        def move(oloop):
            iloop = [l.copy() for l in oloop]
            [l.translate(ray) for l,ray in zip(iloop,rays)]
            self._bridge(iloop,oloop,m = m)
            return iloop

        com = dpv.center_of_mass(loop)
        loop.append(loop[0])
        rays = [dpv.v1_v2(l,com).scale_u(1.0/n) for l in loop]
        for x in range(n):loop = move(loop)
        self._tripie(loop,m = m)
        nfend = len(self.faces)
        return range(nfstart,nfend)
Exemplo n.º 14
0
    def generate(self,worn = 0):
        e1 = dpv.v1_v2(self.boundary[0],self.boundary[1])
        e2 = dpv.v1_v2(self.boundary[1],self.boundary[2])
        a = dpr.angle_from_xaxis_xy(e1)
        t = dpv.center_of_mass(list(self.boundary))
        r = dpq.q_from_av(a,dpv.z())
        tf,rf = t.copy().flip(),r.copy().flip()
        hl = e1.magnitude()
        hw = e2.magnitude()

        hbnd = [b.copy().translate(tf).rotate(rf) for b in self.boundary]
        house = dlh.house(hbnd,l = hl,w = hw)
        self.structures = [house]

        for s in self.structures:
            node = self._node_wrap(s.model(t,r))
            self._nodes_to_graph(node)
        return self
Exemplo n.º 15
0
 def grow(self, plans, length=None, side=None, force=False):
     side = self.grow_side(plans, side)
     if side is None: return False
     gleng = self.grow_length(plans, length, side)
     if gleng is None: return False
     self.face_away(side)
     v1, v2 = side[0]
     c1 = v2.copy()
     c2 = v1.copy()
     c3, c4 = dpr.extrude_edge(c1, c2, gleng, side[1]['normal'])
     newcorners = [c1, c2, c3, c4]
     x, y, z = dpv.center_of_mass(newcorners)
     xpj = dpv.project_coords(newcorners, dpv.x())
     ypj = dpv.project_coords(newcorners, dpv.y())
     l, w = xpj.y - xpj.x, ypj.y - ypj.x
     margs = ((), {'x': x, 'y': y, 'l': l, 'w': w, 'shafted': False})
     self.create_bbox(margs)
     if not self.verify_growth(plans, margs): return False
     splan = self.should_shaft(plans, margs)
     cpairs = [(c2, c3), (c3, c4), (c4, c1)]
     iwargs = []
     ewargs = [[
         cp, {
             'h': 4.0,
             'w': 0.5,
             'walltype': 'exterior',
             'room': margs
         }
     ] for cp in cpairs]
     self.switch_walltype(plans, side)
     if self.resolve_walls(plans, ewargs, iwargs, margs):
         rps, eps, ips, sps = plans
         rps.append(margs)
         eps.extend(ewargs)
         ips.extend(iwargs)
         if splan: sps.append(splan)
         return True
     else:
         return False
Exemplo n.º 16
0
 def _tangent(self, o):
     scom = dpv.center_of_mass(self.boundary)
     ocom = dpv.center_of_mass(o.boundary)
     sotang = dpv.v1_v2(scom, ocom)
     return sotang
Exemplo n.º 17
0
 def _tangent(self,o):
     scom = dpv.center_of_mass(self.boundary)
     ocom = dpv.center_of_mass(o.boundary)
     sotang = dpv.v1_v2(scom,ocom)
     return sotang
Exemplo n.º 18
0
def plot_polygon(points,ax = None,center = False,lw = 1.0):
    epts = list(points[:])
    epts.append(points[0])
    ax = plot_edges(epts,ax,lw = lw)
    if center:plot_point(dpv.center_of_mass(points),ax,marker = 's')
    return ax
Exemplo n.º 19
0
def icosphere(r = 1,n = 1):
    import dilap.mesh.piecewisecomplex as pwc
    plc = pwc.piecewise_linear_complex()

    # create 12 vertices of a icosahedron
    t = (1.0+math.sqrt(5.0))/2.0
    pts = []
    pts.append(dpv.vector(-1, t, 0))
    pts.append(dpv.vector( 1, t, 0))
    pts.append(dpv.vector(-1,-t, 0))
    pts.append(dpv.vector( 1,-t, 0))
    pts.append(dpv.vector( 0,-1, t))
    pts.append(dpv.vector( 0, 1, t))
    pts.append(dpv.vector( 0,-1,-t))
    pts.append(dpv.vector( 0, 1,-t))
    pts.append(dpv.vector( t, 0,-1))
    pts.append(dpv.vector( t, 0, 1))
    pts.append(dpv.vector(-t, 0,-1))
    pts.append(dpv.vector(-t, 0, 1))
    dpv.translate_coords(pts,dpv.center_of_mass(pts).flip())

    triangles = []
    # 5 faces around point 0
    triangles.append((0,11,5))
    triangles.append((0,5,1))
    triangles.append((0,1,7))
    triangles.append((0,7,10))
    triangles.append((0,10,11))
    # 5 adjacent faces
    triangles.append((1,5,9))
    triangles.append((5,11,4))
    triangles.append((11,10,2))
    triangles.append((10,7,6))
    triangles.append((7,1,8))
    # 5 faces around point 3
    triangles.append((3,9,4))
    triangles.append((3,4,2))
    triangles.append((3,2,6))
    triangles.append((3,6,8))
    triangles.append((3,8,9))
    # 5 adjacent faces
    triangles.append((4,9,5))
    triangles.append((2,4,11))
    triangles.append((6,2,10))
    triangles.append((8,6,7))
    triangles.append((9,8,1))

    def esplit(lk,u,v):
        k = (u,v)
        if not k in lk:
            pts.append(dpv.midpoint(pts[u],pts[v]))
            lk[k] = len(pts)-1
        return lk[k]
    def tsplit(lk,u,v,w):
        m1 = esplit(lk,u,v)
        m2 = esplit(lk,v,w)
        m3 = esplit(lk,w,u)
        return (m1,m3,u),(m2,m1,v),(m3,m2,w),(m1,m2,m3)
    def split(itris):
        otris = []
        nwpts = {}
        for t in itris:otris.extend(tsplit(nwpts,*t))
        return otris
    for nx in range(n):triangles = split(triangles)
    for p in pts:p.normalize().scale_u(r)

    polygons = tuple((tuple(pts[x].copy() for x in t),()) for t in triangles)
    plc.add_polygons(*polygons)

    #dprf.profile_function(plc.triangulate)
    #plc.simplices = [(pts[u],pts[v],pts[w]) for u,v,w in triangles]
    #plc.ghostbnds = []
    #ax = plc.plot()
    #plt.show()
    return plc
Exemplo n.º 20
0
def plot_polygon_xy(points, ax=None, center=False, lw=1.0):
    epts = list(points[:])
    epts.append(points[0])
    ax = plot_edges_xy(epts, ax, lw=lw)
    if center: plot_point_xy(dpv.center_of_mass(points), ax, marker='s')
    return ax
Exemplo n.º 21
0
def icosphere(r=1, n=1):
    import dilap.mesh.piecewisecomplex as pwc
    plc = pwc.piecewise_linear_complex()

    # create 12 vertices of a icosahedron
    t = (1.0 + math.sqrt(5.0)) / 2.0
    pts = []
    pts.append(dpv.vector(-1, t, 0))
    pts.append(dpv.vector(1, t, 0))
    pts.append(dpv.vector(-1, -t, 0))
    pts.append(dpv.vector(1, -t, 0))
    pts.append(dpv.vector(0, -1, t))
    pts.append(dpv.vector(0, 1, t))
    pts.append(dpv.vector(0, -1, -t))
    pts.append(dpv.vector(0, 1, -t))
    pts.append(dpv.vector(t, 0, -1))
    pts.append(dpv.vector(t, 0, 1))
    pts.append(dpv.vector(-t, 0, -1))
    pts.append(dpv.vector(-t, 0, 1))
    dpv.translate_coords(pts, dpv.center_of_mass(pts).flip())

    triangles = []
    # 5 faces around point 0
    triangles.append((0, 11, 5))
    triangles.append((0, 5, 1))
    triangles.append((0, 1, 7))
    triangles.append((0, 7, 10))
    triangles.append((0, 10, 11))
    # 5 adjacent faces
    triangles.append((1, 5, 9))
    triangles.append((5, 11, 4))
    triangles.append((11, 10, 2))
    triangles.append((10, 7, 6))
    triangles.append((7, 1, 8))
    # 5 faces around point 3
    triangles.append((3, 9, 4))
    triangles.append((3, 4, 2))
    triangles.append((3, 2, 6))
    triangles.append((3, 6, 8))
    triangles.append((3, 8, 9))
    # 5 adjacent faces
    triangles.append((4, 9, 5))
    triangles.append((2, 4, 11))
    triangles.append((6, 2, 10))
    triangles.append((8, 6, 7))
    triangles.append((9, 8, 1))

    def esplit(lk, u, v):
        k = (u, v)
        if not k in lk:
            pts.append(dpv.midpoint(pts[u], pts[v]))
            lk[k] = len(pts) - 1
        return lk[k]

    def tsplit(lk, u, v, w):
        m1 = esplit(lk, u, v)
        m2 = esplit(lk, v, w)
        m3 = esplit(lk, w, u)
        return (m1, m3, u), (m2, m1, v), (m3, m2, w), (m1, m2, m3)

    def split(itris):
        otris = []
        nwpts = {}
        for t in itris:
            otris.extend(tsplit(nwpts, *t))
        return otris

    for nx in range(n):
        triangles = split(triangles)
    for p in pts:
        p.normalize().scale_u(r)

    polygons = tuple((tuple(pts[x].copy() for x in t), ()) for t in triangles)
    plc.add_polygons(*polygons)

    #dprf.profile_function(plc.triangulate)
    #plc.simplices = [(pts[u],pts[v],pts[w]) for u,v,w in triangles]
    #plc.ghostbnds = []
    #ax = plc.plot()
    #plt.show()
    return plc
Exemplo n.º 22
0
 def center(self):
     com = dpv.center_of_mass(self.pcoords)
     self.translate(com.flip())
     return self