|
发表于 2020-4-18 16:59:55
|
显示全部楼层
- def f(list1):
- def x(list1):
- return list1[0]
- def y(list1):
- return list1[1]
- list2 = []
- list1 = sorted(list1,key=x)
- xmin = list1[0][0]
- xmin_list = []
- xmax = list1[-1][0]
- xmax_list = []
- for each in list1:
- if each[0] == xmin:
- list2.append(each)
- xmin_list.append(each[1])
- elif each[0] == xmax:
- list2.append(each)
- xmax_list.append(each[1])
-
- list1 = sorted(list1,key=y)
- ymin = list1[0][1]
- ymin_list = []
- ymax = list1[-1][1]
- ymax_list = []
- for each in list1:
- if each[1] == ymin:
- list2.append(each)
- ymin_list.append(each[0])
- elif each[1] == ymax:
- list2.append(each)
- ymax_list.append(each[0])
- xmin_list.sort()
- xmax_list.sort()
- ymin_list.sort()
- ymax_list.sort()
- def f1(p1,p2,p3):
- if abs((p2[1]-p1[1])/(p2[0]-p1[0]))<abs((p3[1]-p1[1])/(p3[0]-p1[0])):
- return 2
- elif abs((p2[1]-p1[1])/(p2[0]-p1[0]))==abs((p3[1]-p1[1])/(p3[0]-p1[0])):
- return 1
- else:
- return 0
-
- leftup,leftdown,rightup,rightdown = list1[:],list1[:],list1[:],list1[:]
- p1,p2,p3,p4,p5,p6,p7,p8 = [xmin,xmin_list[-1]],[ymax_list[0],ymax],[ymax_list[-1],ymax],[xmax,xmax_list[-1]],[xmax,xmax_list[0]],[ymin_list[-1],ymin],[ymin_list[0],ymin],[xmin,xmin_list[0]]
- h1,h2,h3,h4 = [],[],[],[]
- while leftup != []:
- for each in leftup.copy():
- if each[0]>=p2[0] or each[1]<=p1[1]:
- leftup.remove(each)
- else:
- if f1(p1,p2,each)==2:
- h1 = []
- h1.append(each)
- p2 = each
- elif f1(p1,p2,each)==1:
- h1.append(each)
- if h1 != []:
- list2 += h1
- h1 = sorted(h1,key=y)
- p1 = h1[-1]
- p2 = [ymax_list[0],ymax]
- for m in h1:
- leftup.remove(m)
- else:
- break
- while rightup != []:
- for each in rightup.copy():
- if each[0]<=p3[0] or each[1]<=p4[1]:
- rightup.remove(each)
- else:
- if f1(p4,p3,each)==2:
- h2 = []
- h2.append(each)
- p3 = each
- elif f1(p4,p3,each)==1:
- h2.append(each)
- if h2 != []:
- list2 += h2
- h2 = sorted(h2,key=y)
- p4 = h2[-1]
- p3 = [ymax_list[-1],ymax]
- for m in h2:
- rightup.remove(m)
- else:
- break
- while leftdown != []:
- for each in leftdown.copy():
- if each[0]>=p7[0] or each[1]>=p8[1]:
- leftdown.remove(each)
- else:
- if f1(p8,p7,each)==2:
- h4 = []
- h4.append(each)
- p7 = each
- elif f1(p8,p7,each)==1:
- h4.append(each)
- if h4 != []:
- list2 += h4
- h4 = sorted(h4,key=x)
- p8 = h4[-1]
- p7 = [ymin_list[0],ymin]
- for m in h4:
- leftdown.remove(m)
- else:
- break
- while rightdown != []:
- for each in rightdown.copy():
- if each[0]<=p6[0] or each[1]>=p5[1]:
- rightdown.remove(each)
- else:
- if f1(p5,p6,each)==2:
- h3 = []
- h3.append(each)
- p6 = each
- elif f1(p5,p6,each)==1:
- h3.append(each)
- if h3 != []:
- list2 += h3
- h3 = sorted(h3,key=x)
- p5 = h3[0]
- p6 = [ymin_list[-1],ymin]
- for m in h3:
- rightdown.remove(m)
- else:
- break
- return list2
复制代码   |
评分
-
查看全部评分
|