示例#1
0
文件: nfp.py 项目: Trixter9994/lazero
def tryNFP():
    df = pd.read_csv("./data/blaz1.csv")

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

    nfp = NFP(poly1, poly2, show=True)
    print(nfp.nfp)
示例#2
0
    def placeFirstPoly(self):
        '''
        放置第一个形状进去,并平移到left-bottom
        '''
        poly = self.polygons[0]
        poly_index = geoFunc.checkTop(poly)
        left_index, bottom_index, right_index, top_index = geoFunc.checkBound(
            poly)

        move_x = poly[left_index][0]
        move_y = poly[bottom_index][1]
        geoFunc.slidePoly(poly, 0, -move_y)
示例#3
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()
示例#4
0
文件: nfp.py 项目: Trixter9994/lazero
    def main(self):
        i = 0
        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(mapping(inter)) > 1:
                print("出现相交区域")
                self.error = -4  # 出现相交区域
                break

        if i == 75:
            print("超出计算次数")
            self.error = -1  # 超出计算次数
示例#5
0
    def getInnerFitRectangle(self, poly):
        '''
        获得IFR,同时平移到left-bottom
        '''
        poly_index = geoFunc.checkTop(poly)
        left_index, bottom_index, right_index, top_index = geoFunc.checkBound(
            poly)

        move_x = poly[left_index][0]
        move_y = poly[bottom_index][1]
        geoFunc.slidePoly(poly, -move_x, -move_y)

        refer_pt = [poly[poly_index][0], poly[poly_index][1]]
        width = self.width - poly[right_index][0]
        height = self.height - poly[top_index][1]

        IFR = [
            refer_pt, [refer_pt[0] + width, refer_pt[1]],
            [refer_pt[0] + width, refer_pt[1] + height],
            [refer_pt[0], refer_pt[1] + height]
        ]

        return IFR