def slideNeighbor(self,poly,_type):
        print("检索类型",_type,"...")
        self.break_points_list=[]
        self.t_lists=[]

        self.getBreakPointList(self.horizontal_positive,self.slide_horizontal_positive,_type,-1)
        self.getBreakPointList(self.horizontal_negative,self.slide_horizontal_negative,_type,-1)
        self.getBreakPointList(self.horizontal_positive,self.slide_horizontal_negative,_type,1)
        self.getBreakPointList(self.horizontal_negative,self.slide_horizontal_positive,_type,1)

        # 计算面积的最合适位置
        self.t_lists=self.chooseFeasible(self.t_lists,_type)
        self.t_lists=self.deleteDuplicated(self.t_lists)
        min_area_t=self.overlapCompare()
        
        print("min_area_t:",min_area_t)
        if abs(min_area_t)<precision_error:
            print("0 未检索到更优位置")
            return False

        # 进行平移位置
        if _type=="vertical":
            GeoFunc.slidePoly(self.cur_polys[self.max_miu_index],0,min_area_t)
        else:
            GeoFunc.slidePoly(self.cur_polys[self.max_miu_index],min_area_t,0)

        # 更新PolyList、正负边、重合情况
        self.updatePolyList()
        self.updateEdgesPN()

        print("1 检索到更优位置")
        self.showResult(current=True)
        return True
 def shrink(self):
     self.new_height = self.height*0.95
     print("收缩边界%s" % self.new_height)
     for poly in self.cur_polys:
         top_index = GeoFunc.checkTop(poly)
         delta = self.new_height-poly[top_index][1]
         # 如果有重叠就平移
         if delta < 0:
             GeoFunc.slidePoly(poly,0,delta)
     self.updatePolyList()
예제 #3
0
def tryNFP():
    df = pd.read_csv("data/blaz1.csv")

    poly1 = json.loads(df['polygon'][1])
    poly2 = json.loads(df['polygon'][4])
    GeoFunc.normData(poly1, 50)
    GeoFunc.normData(poly2, 50)
    GeoFunc.slidePoly(poly1, 500, 500)

    nfp = NFP(poly1, poly2, show=True)
    print(nfp.nfp)
예제 #4
0
 def testGCS(self):
     # polygons=[]
     # polygons.append(self.getTestPolys()[0])
     # polygons.append(self.getTestPolys()[1])
     polygons=self.getTestPolys()
     num = 1  # 形状收缩
     for poly in polygons:
         for ver in poly:
             ver[0] = ver[0]*num
             ver[1] = ver[1]*num
     gcs = GCS(polygons)
     GeoFunc.slidePoly(polygons[0], 500, 500)
     gcs.showAll()
     gcs.GuidedCuckooSearch(1500, 10)
     gcs.showAll()
예제 #5
0
    def main(self):
        i=0
        if self.rectangle: # 若矩形则直接快速运算 点的index为左下角开始逆时针旋转
            width=self.sliding[1][0]-self.sliding[0][0]
            height=self.sliding[3][1]-self.sliding[0][1]
            self.nfp.append([self.stationary[0][0],self.stationary[0][1]])
            self.nfp.append([self.stationary[1][0]+width,self.stationary[1][1]])
            self.nfp.append([self.stationary[2][0]+width,self.stationary[2][1]+height])
            self.nfp.append([self.stationary[3][0],self.stationary[3][1]+height])
        else:
            while self.judgeEnd()==False and i<75: # 大于等于75会自动退出的,一般情况是计算出错
            # while i<7:
                # print("########第",i,"轮##########")
                touching_edges=self.detectTouching()
                all_vectors=self.potentialVector(touching_edges)
                if len(all_vectors)==0:
                    print("没有可行向量")
                    self.error=-2 # 没有可行向量
                    break

                vector=self.feasibleVector(all_vectors,touching_edges)
                if vector==[]:
                    print("没有计算出可行向量")
                    self.error=-5 # 没有计算出可行向量
                    break
                
                self.trimVector(vector)
                if vector==[0,0]:
                    print("未进行移动")
                    self.error=-3 # 未进行移动
                    break

                GeoFunc.slidePoly(self.sliding,vector[0],vector[1])
                self.nfp.append([self.sliding[self.locus_index][0],self.sliding[self.locus_index][1]])
                i=i+1
                inter=Polygon(self.sliding).intersection(Polygon(self.stationary))
                if GeoFunc.computeInterArea(inter)>1:
                    print("出现相交区域")
                    self.error=-4 # 出现相交区域
                    break                

        if i==75:
            print("超出计算次数")
            self.error=-1 # 超出计算次数
 def slideToBottomLeft(self):
     '''移到最左下角位置'''
     for poly in self.cur_polys:
         GeoFunc.slidePoly(poly, -self.border_left, -self.border_bottom)
예제 #7
0
 def placeFirstPoly(self):
     poly = self.polygons[0]
     left_index, bottom_index, right_index, top_index = GeoFunc.checkBound(
         poly)  # 获得边界
     GeoFunc.slidePoly(poly, -poly[left_index][0],
                       -poly[bottom_index][1])  # 平移到左下角
 def slideToPoint(poly,pt1,pt2):
     GeoFunc.slidePoly(poly,pt2[0]-pt1[0],pt2[1]-pt1[1])