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 updateSearchStatus(self): # 计算重叠情况 self.overlap_pair=[[0]*len(self.cur_polys) for i in range(len(self.cur_polys))] self.overlap_each=[0 for i in range(len(self.cur_polys))] for i in range(0,len(self.cur_polys)-1): for j in range(i+1,len(self.cur_polys)): Pi=Polygon(self.cur_polys[i]) Pj=Polygon(self.cur_polys[j]) overlap_area=GeoFunc.computeInterArea(Pi.intersection(Pj)) if overlap_area>precision_error: self.overlap_pair[i][j]=self.overlap_pair[i][j]+overlap_area self.overlap_pair[j][i]=self.overlap_pair[i][j] self.overlap_each[i]=self.overlap_each[i]+overlap_area self.overlap_each[j]=self.overlap_each[j]+overlap_area # 更新是否重叠 self.overlap=False for area in self.overlap_each: if area>0: self.overlap=True # 计算对应的Miu max_miu_pair=0 self.max_miu_pair_indx=[0,0] for i in range(0,len(self.cur_polys)): for j in range(0,len(self.cur_polys)): miu=self.overlap_pair[i][j]/(1+self.phi[i][j]) self.miu_each[i]=self.miu_each[i]+miu if miu>max_miu_pair: self.max_miu_pair_indx=[i,j] # 获得最大的Miu值 self.max_miu=0 self.max_miu_index=-1 for index,miu in enumerate(self.miu_each): if miu>self.max_miu: self.max_miu=miu self.max_miu_index=index