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
def triang(): #pts = dpr.dice_edges(dpr.square(50,10),2) hpts = [dpv.vector(5,-2,3)] hpts.append(hpts[-1].copy().translate(dpv.vector(0,5,0))) hpts.append(hpts[-1].copy().translate(dpv.vector(-10,0,0))) hpts.append(hpts[-1].copy().translate(dpv.vector(0,-3,0))) hpts.append(hpts[-1].copy().translate(dpv.vector(5,0,0))) hpts.append(hpts[-1].copy().translate(dpv.vector(0,-2,0))) hpts2 = [h.copy().translate_x(-12).translate_z(-6) for h in hpts] pts = dpr.inflate([h.copy().translate_x(-6).translate_z(-3) for h in hpts],14) #pts = dpv.translate_coords(dpr.square(50,10),dpv.vector(-30,-12,0)) pts2 = dpv.translate_coords(dpr.square(30,10),dpv.vector(30,20,0)) pts3 = dpv.translate_coords(dpr.square(20,10),dpv.vector(-30,-20,0)) pts2.insert(1,dpv.vector(25,15,0)) pts2.insert(1,dpv.vector(25,20,0)) pts2.insert(1,dpv.vector(20,20,0)) pts2.insert(1,dpv.vector(20,15,0)) #pts2 = dpr.point_ring(100,16) ax = dtl.plot_axes_xy() ax = dtl.plot_points_xy(pts2,ax,number = True) plt.show() points = [] edges = [] polygons = [(pts,(hpts,hpts2)),(pts2,()),(pts3,())] #polygons = [(pts2,())] #polygons = [(pts,(hpts,hpts2))] #polygons = [(pts,()),(pts2,())] polyhedra = [] plc = pwc.piecewise_linear_complex( refine = True,smooth = False) plc.add_points(*points) plc.add_edges(*edges) plc.add_polygons(*polygons) #plc.add_polyhedra(*polyhedra) plc.triangulate() #ax = plc.plot_xy() ax = plc.plot() plt.show() '''#
def create_bbox(self,roomplan): x,y = roomplan[1]['x'],roomplan[1]['y'] l,w = roomplan[1]['l']-0.01,roomplan[1]['w']-0.01 cns = dpr.square(l,w,dpv.vector(x,y,0)) xpj = dpv.project_coords(cns,dpv.x()) ypj = dpv.project_coords(cns,dpv.y()) zpj = dpv.project_coords(cns,dpv.z()) bb = dbb.bbox(xpj,ypj,zpj) roomplan[1]['bbox'] = bb
def _geo_gapless(self): l,w,h,m = self.l,self.w,self.h,self.m corners = dpr.square(l,w) #us = dpr.polygon(4) us = dpr.square(1,1) dpv.translate_coords(us,dpv.one().scale_u(0.5)) dpv.scale_coords_x(us,l) dpv.scale_coords_y(us,w) us = [v.xy2d() for v in us] self._quad(*corners,us = us,m = m) bcorners = [c.copy().translate_z(-h) for c in corners] bcorners.reverse() self._quad(*bcorners,us = us,m = m) bcorners.reverse() bcorners.append(bcorners[0]) corners.append(corners[0]) nfs = self._bridge(corners,bcorners,m = m) self._project_uv_flat(nfs)
def _geo_gap(self): l, w, h, g, m = self.l, self.w, self.h, self.gap, self.m gp, gl, gw = g iloop = dpr.square(gl, gw, gp) oloop = dpr.square(l, w) iloop.append(iloop[0]) oloop.append(oloop[0]) iloopb = [c.copy() for c in iloop] oloopb = [c.copy() for c in oloop] [c.translate_z(-h) for c in iloopb] [c.translate_z(-h) for c in oloopb] nfs = self._bridge(iloop, oloop, m=m) self._project_uv_xy(nfs) nfs = self._bridge(oloopb, iloopb, m=m) self._project_uv_xy(nfs) nfs = self._bridge(iloopb, iloop, m=m) self._project_uv_flat(nfs) nfs = self._bridge(oloop, oloopb, m=m) self._project_uv_flat(nfs)
def wall_verts(self,rmargs): rmkws = rmargs[1] cs = dpr.square(rmkws['l'],rmkws['w'], dpv.vector(rmkws['x'],rmkws['y'],0.0)) pairs = [] for cdx in range(1,len(cs)): c1,c2 = cs[cdx-1].copy(),cs[cdx].copy() pairs.append((c1,c2)) c1,c2 = cs[-1].copy(),cs[0].copy() pairs.append((c1,c2)) return pairs
def wall_verts(self, rmargs): rmkws = rmargs[1] cs = dpr.square(rmkws['l'], rmkws['w'], dpv.vector(rmkws['x'], rmkws['y'], 0.0)) pairs = [] for cdx in range(1, len(cs)): c1, c2 = cs[cdx - 1].copy(), cs[cdx].copy() pairs.append((c1, c2)) c1, c2 = cs[-1].copy(), cs[0].copy() pairs.append((c1, c2)) return pairs
def _geo_gap(self): l,w,h,g,m = self.l,self.w,self.h,self.gap,self.m gp,gl,gw = g iloop = dpr.square(gl,gw,gp) oloop = dpr.square(l,w) iloop.append(iloop[0]) oloop.append(oloop[0]) iloopb = [c.copy() for c in iloop] oloopb = [c.copy() for c in oloop] [c.translate_z(-h) for c in iloopb] [c.translate_z(-h) for c in oloopb] nfs = self._bridge(iloop,oloop,m = m) self._project_uv_xy(nfs) nfs = self._bridge(oloopb,iloopb,m = m) self._project_uv_xy(nfs) nfs = self._bridge(iloopb,iloop,m = m) self._project_uv_flat(nfs) nfs = self._bridge(oloop,oloopb,m = m) self._project_uv_flat(nfs)
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
def post(p, s, w, h): #base = dpr.point_ring(w/2.0,s) base = dpr.square(w, w) dpv.translate_coords(base, p) top = [b.copy().translate_z(h) for b in base] wls = ( ((base[0].copy(), base[1].copy(), top[1].copy(), top[0].copy()), ()), ((base[1].copy(), base[2].copy(), top[2].copy(), top[1].copy()), ()), ((base[2].copy(), base[3].copy(), top[3].copy(), top[2].copy()), ()), ((base[3].copy(), base[0].copy(), top[0].copy(), top[3].copy()), ()), ) return wls
def grow_length(self,plans,length,side): if length is None: l,w = self.bldg.l,self.bldg.w corners = dpr.square(l,w) sidept = dpv.midpoint(*side[0]) bdist = dpv.distance_to_border_xy(sidept,corners) length = rm.choice([8,12,16,20,24,28,32]) if bdist < 8:return elif length > bdist:length = bdist return length
def grow_length(self, plans, length, side): if length is None: l, w = self.bldg.l, self.bldg.w corners = dpr.square(l, w) sidept = dpv.midpoint(*side[0]) bdist = dpv.distance_to_border_xy(sidept, corners) length = rm.choice([8, 12, 16, 20, 24, 28, 32]) if bdist < 8: return elif length > bdist: length = bdist return length
def post(p,s,w,h): #base = dpr.point_ring(w/2.0,s) base = dpr.square(w,w) dpv.translate_coords(base,p) top = [b.copy().translate_z(h) for b in base] wls = ( ((base[0].copy(),base[1].copy(),top[1].copy(),top[0].copy()),()), ((base[1].copy(),base[2].copy(),top[2].copy(),top[1].copy()),()), ((base[2].copy(),base[3].copy(),top[3].copy(),top[2].copy()),()), ((base[3].copy(),base[0].copy(),top[0].copy(),top[3].copy()),()), ) return wls
def cgstest(): p1 = (tuple(dpr.square(5,5)),()) p2 = (tuple(dpr.square(4,4,dpv.vector(0,0,0))),()) #p2 = (tuple(dpr.square(5,4,dpv.vector(4,0,0))),()) #p3 = (tuple(dpr.square(5,3,dpv.vector(8,0,0))),()) #dpr.rotate_polygon(p1,dpq.q_from_av(dpr.PI/2.0,dpv.x())) #dpr.rotate_polygon(p2,dpq.q_from_av(dpr.PI/2.0,dpv.x())) #dpr.rotate_polygon(p3,dpq.q_from_av(dpr.PI/2.0,dpv.x())) ptest = polygon_union(p1,p2) #ptest = polygon_union(ptest,p3) #ptest = polygon_intersection(p1,p2) #ptest = polygon_difference(p1,p2) #ptest = merge_polygons([p1,p2,p3]) ax = plot_axes() #for seg in p1segs:ax = plot_edges_xy(seg,ax) #for seg in p2segs:ax = plot_edges_xy(seg,ax) #plot_polygon_full(p1,ax) #plot_polygon_full(p2,ax) plot_polygon_full(ptest,ax) #for pt in ptest:plot_polygon_full(pt,ax,lw = 4.0) plt.show() if ptest is None:print('unacceptable union') else: print('soo whats happeningjj?') ax = plot_axes() #for seg in p1segs:ax = plot_edges_xy(seg,ax) #for seg in p2segs:ax = plot_edges_xy(seg,ax) plot_polygon_full(p1,ax) plot_polygon_full(p2,ax) plot_polygon_full(ptest,ax,lw = 4.0) #for pt in ptest:plot_polygon_full(pt,ax,lw = 4.0) plt.show()
def cgstest(): p1 = (tuple(dpr.square(5, 5)), ()) p2 = (tuple(dpr.square(4, 4, dpv.vector(0, 0, 0))), ()) #p2 = (tuple(dpr.square(5,4,dpv.vector(4,0,0))),()) #p3 = (tuple(dpr.square(5,3,dpv.vector(8,0,0))),()) #dpr.rotate_polygon(p1,dpq.q_from_av(dpr.PI/2.0,dpv.x())) #dpr.rotate_polygon(p2,dpq.q_from_av(dpr.PI/2.0,dpv.x())) #dpr.rotate_polygon(p3,dpq.q_from_av(dpr.PI/2.0,dpv.x())) ptest = polygon_union(p1, p2) #ptest = polygon_union(ptest,p3) #ptest = polygon_intersection(p1,p2) #ptest = polygon_difference(p1,p2) #ptest = merge_polygons([p1,p2,p3]) ax = plot_axes() #for seg in p1segs:ax = plot_edges_xy(seg,ax) #for seg in p2segs:ax = plot_edges_xy(seg,ax) #plot_polygon_full(p1,ax) #plot_polygon_full(p2,ax) plot_polygon_full(ptest, ax) #for pt in ptest:plot_polygon_full(pt,ax,lw = 4.0) plt.show() if ptest is None: print('unacceptable union') else: print('soo whats happeningjj?') ax = plot_axes() #for seg in p1segs:ax = plot_edges_xy(seg,ax) #for seg in p2segs:ax = plot_edges_xy(seg,ax) plot_polygon_full(p1, ax) plot_polygon_full(p2, ax) plot_polygon_full(ptest, ax, lw=4.0) #for pt in ptest:plot_polygon_full(pt,ax,lw = 4.0) plt.show()
def gen(self,*args,**kwargs): l,w,rh = self.l,self.w,10 base1 = dpr.square(l,w) base2 = dpr.square(l,w) dpv.translate_coords_x(base2,l) room1 = ((base1,rh,(-1,-2,1,-2)),{'style':'empty'}) room2 = ((base2,rh,(0,-2,-1,-2)),{'style':'empty'}) rooms = (room1,room2) #self.graph.add_room(base1,(0,),**{'height':rh,'style':'empty'}) r = 20 self.graph._add_room(( ((0,0,0),(r,0,0),(r,r,0),(0,r,0)), ((0,0,1),(r,0,1),(r,r,1),(0,r,1)), #((r,0,0),(r,r,0),(0,r,0)), #((r,0,1),(r,r,1),(0,r,1)), )) self.graph._add_room((((r,0,0),(2*r,0,0),(2*r,r,0),(r,r,0)),)) self.graph._add_room((((r,r,0),(2*r,r,0),(2*r,2*r,0),(r,2*r,0)),)) self.graph._connect_rooms(0,1) self.graph._connect_rooms(1,2) self.graph._connect_rooms(0,-1)
def generate_walls(self,level): l,w,fh,wh,ch = self._params(level) cs = dpr.square(l,w) margs = () wargs = [ [(cs[1],cs[2]),{'h':wh,'w':0.25,'fh':fh, 'walltype':'solid','room':margs}], [(cs[2],cs[3]),{'h':wh,'w':0.25,'fh':fh, 'walltype':'solid','room':margs}], [(cs[3],cs[0]),{'h':wh,'w':0.25,'fh':fh, 'walltype':'solid','room':margs}], [(cs[0],cs[1]),{'h':wh,'w':0.25,'fh':fh, 'walltype':'interior','room':margs}], ] walls = [dw.wall(*w[0],**w[1]) for w in wargs] return self._node_wrap(*walls)
def tetra(): pts = dpr.dice_edges(dpr.square(5, 5), 1) pts.extend([d.copy().translate_z(10) for d in pts]) plc = pwc.piecewise_linear_complex() plcxs = plc.add_points(*pts) for x in range(8): y = x + 1 if x < 7 else 0 plc.add_edge(x, y) print('input plc') plc.plot() plt.show() print('begin tetra') plc.tetrahedralize() print('end tetra') print('output plc') plc.plot() plt.show()
def tetra(): pts = dpr.dice_edges(dpr.square(5,5),1) pts.extend([d.copy().translate_z(10) for d in pts]) plc = pwc.piecewise_linear_complex() plcxs = plc.add_points(*pts) for x in range(8): y = x+1 if x < 7 else 0 plc.add_edge(x,y) print('input plc') plc.plot() plt.show() print('begin tetra') plc.tetrahedralize() print('end tetra') print('output plc') plc.plot() plt.show()
def generate_walls(self, level): l, w, fh, wh, ch = self._params(level) cs = dpr.square(l, w) margs = () wargs = [ [(cs[1], cs[2]), { 'h': wh, 'w': 0.25, 'fh': fh, 'walltype': 'solid', 'room': margs }], [(cs[2], cs[3]), { 'h': wh, 'w': 0.25, 'fh': fh, 'walltype': 'solid', 'room': margs }], [(cs[3], cs[0]), { 'h': wh, 'w': 0.25, 'fh': fh, 'walltype': 'solid', 'room': margs }], [(cs[0], cs[1]), { 'h': wh, 'w': 0.25, 'fh': fh, 'walltype': 'interior', 'room': margs }], ] walls = [dw.wall(*w[0], **w[1]) for w in wargs] return self._node_wrap(*walls)
def block(self, bnd): bl = (tuple(dpr.square(5, 10, dpv.vector(2.5, 5, 0))), ()) nbnd = dtl.polygon_difference(bnd, bl) rmprints = [nbnd, bl] return rmprints
def test(): bnd = dpr.square(10,20,dpv.vector(5,10,0)) g = sgraph(boundary = bnd).fun() g.plot() plt.show()
def block(self,bnd): bl = (tuple(dpr.square(5,10,dpv.vector(2.5,5,0))),()) nbnd = dtl.polygon_difference(bnd,bl) rmprints = [nbnd,bl] return rmprints
def test(): bnd = dpr.square(10, 20, dpv.vector(5, 10, 0)) g = sgraph(boundary=bnd).fun() g.plot() plt.show()