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
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
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
def _regions(self): rpts = [] for eg in self.edges:rpts.extend([x.copy() for x in eg.rpts]) convexbnd = dpr.pts_to_convex_xy(rpts) convexbnd = dpr.inflate(convexbnd,50) eloops = self._edge_loop_boundaries() self.tpolygons = [(tuple(convexbnd),(tuple(eloops['king'][0]),))]+\ [(tuple(i),()) for i in eloops['interiors']] self.rpolygons = [(eloops['king'][0],tuple(eloops['interiors']))]
def model_rooms(self): ww = 0.75 # THIS IS THE NOT THE RIGHT VALUE... mpolys = [] for r in self.rooms: outlines = r #bbnd = [] #for x in outlines[0]: # nd = self.nodes[self.nodes_lookup[x]] # bbnd.append(nd.p.copy()) bbnd = self.get_node_points(outlines[0]) #tbnd = [] tbnd = self.get_node_points(outlines[-1]) for x in range(len(outlines[-1])): nd = self.nodes[self.nodes_lookup[outlines[-1][x]]] tbnd[x].translate_z(nd.height) dpr.inflate(bbnd, -ww / math.sqrt(2)) dpr.inflate(tbnd, -ww / math.sqrt(2)) mpolys.append((tuple(bbnd), ())) mpolys.append((tuple(tbnd), ())) return mpolys
def model_rooms(self): ww = 0.75 # THIS IS THE NOT THE RIGHT VALUE... mpolys = [] for r in self.rooms: outlines = r #bbnd = [] #for x in outlines[0]: # nd = self.nodes[self.nodes_lookup[x]] # bbnd.append(nd.p.copy()) bbnd = self.get_node_points(outlines[0]) #tbnd = [] tbnd = self.get_node_points(outlines[-1]) for x in range(len(outlines[-1])): nd = self.nodes[self.nodes_lookup[outlines[-1][x]]] tbnd[x].translate_z(nd.height) dpr.inflate(bbnd,-ww/math.sqrt(2)) dpr.inflate(tbnd,-ww/math.sqrt(2)) mpolys.append((tuple(bbnd),())) mpolys.append((tuple(tbnd),())) return mpolys
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 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() '''#