def minkowski_difference(A, B): """ 两个多边形的相切空间 http://www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Functions/MinkowskiDiff.htm :param A: :param B: :return: """ #print("AC和Bc",A['points'],B['points']) Ac = [[ p['x'] , p['y']] for p in A['points']] Bc = [[ p['x'] * -1,p['y'] * -1] for p in B['points']] solution = pyclipper.MinkowskiSum(Ac, Bc, True) largest_area = None clipper_nfp = None for p in solution: p = [{'x': i[0], 'y':i[1]} for i in p] sarea = nfp_utls.polygon_area(p) if largest_area is None or largest_area > sarea: clipper_nfp = p largest_area = sarea clipper_nfp = [{ 'x': clipper_nfp[i]['x'] + Bc[0][0] * -1, 'y':clipper_nfp[i]['y'] + Bc[0][1] * -1 } for i in range(0, len(clipper_nfp))] #print("结果",clipper_nfp) return [clipper_nfp]
def minkowski_difference(A, B): """ 两个多边形的相切空间 ff.htm. :param A: :param B: :return: """ Ac = [[p['x'], p['y']] for p in A['points']] Bc = [[p['x'] * -1, p['y'] * -1] for p in B['points']] solution = pyclipper.MinkowskiSum(Ac, Bc, True) # print('DDD') # print(A) # print(B) largest_area = None clipper_nfp = None for p in solution: p = [{'x': i[0], 'y': i[1]} for i in p] sarea = nfp_utls.polygon_area(p) if largest_area is None or largest_area > sarea: clipper_nfp = p largest_area = sarea clipper_nfp = [{ 'x': clipper_nfp[i]['x'] + Bc[0][0] * -1, 'y': clipper_nfp[i]['y'] + Bc[0][1] * -1 } for i in range(0, len(clipper_nfp))] #print(clipper_nfp) return [clipper_nfp]
def store_to_gd(gerber_data, tracks, pads, regions, apertures, tracksize, isDark): # Stores the existing set of layer data as polygonal data points # This is the equivalent of rasterisation of the draw commands li = len(gerber_data.layers) / 3 # Expand tracks from centrelines based on aperture track_outlines = [] for seg in range(len(tracks)): for vert in range(len(tracks[seg]) - 1): xstart = tracks[seg][vert][0] xend = tracks[seg][vert + 1][0] ystart = tracks[seg][vert][1] yend = tracks[seg][vert + 1][1] singletrack = pyclipper.MinkowskiSum(apertures[tracksize[seg]], \ [[xstart, ystart], [xend, yend]], -1) if len(singletrack) > 1: biggest = [] myarea = 0 for mypath in singletrack: newarea = pyclipper.Area(mypath) if newarea > myarea: biggest = mypath myarea = newarea singletrack = [[]] singletrack[0] = (biggest) track_outlines.extend(singletrack) mergedBounds = union_boundary(track_outlines + pads, regions) # Store data into layers. gerber_data.layers.append( GerberLayer(isDark, str(li) + "_Tracks", track_outlines, type=GerberLayer.TYPE_TRACK)) gerber_data.layers.append( GerberLayer(isDark, str(li) + "_Boundaries", mergedBounds, False, False, "blue", GerberLayer.TYPE_BOUNDARY)) # gerber_data.layers.append(GerberLayer(isDark, str(li) + "_Boundaries", track_outlines + pads, False, False, "blue")) gerber_data.layers.append( GerberLayer(isDark, str(li) + "_Regions", regions, type=GerberLayer.TYPE_REGION)) gerber_data.layers.append( GerberLayer(isDark, str(li) + "_Pads", pads, type=GerberLayer.TYPE_PAD, color="#009000"))
def minkow(A, B): Ac = [[p['x'], p['y']] for p in A] Bc = [[p['x'] * -1, p['y'] * -1] for p in B] solution = pyclipper.MinkowskiSum(Ac, Bc, True) largest_area = None clipper_nfp = None for p in solution: p = [{'x': i[0], 'y': i[1]} for i in p] sarea = nfp_utls.polygon_area(p) if largest_area is None or largest_area > sarea: clipper_nfp = p largest_area = sarea clipper_nfp = [{ 'x': clipper_nfp[i]['x'] + Bc[0][0] * -1, 'y': clipper_nfp[i]['y'] + Bc[0][1] * -1 } for i in range(0, len(clipper_nfp))] return clipper_nfp
def test_minkowski_sum(self): solution = pyclipper.MinkowskiSum(PATTERN, PATH_SIGMA, False) self.assertGreater(len(solution), 0)
def test_minkowski_sum(self): with self.assertWarns(DeprecationWarning): pyclipper.MinkowskiSum(PATTERN, PATH_SIGMA, False)