''' mbinary ######################################################################### # File : min_distance_of_n_points.py # Author: mbinary # Mail: zhuheqin1@gmail.com # Blog: https://mbinary.xyz # Github: https://github.com/mbinary # Created Time: 2018-11-24 22:03 # Description: ######################################################################### ''' from random import randint from time import time from functools import total_ordering @total_ordering class point: def __init__(self,x,y): self.x=x self.y=y def __neg__(self): return pont(-self.x, -self.y) def __len__(self): return self.norm(2) def __lt__(self,p): return self.xd2: minD = d2 p,q = pts[1], pts[2] d2 = pts[0].distance(pts[2]) if minD>d2: return d2, pts[0],pts[2] else : return minD, p,q n2 = n//2 mid = (pts[n2].x +pts[n2-1].x)/2 s1 = pts[:n2] s2 = pts[n2:] minD ,p,q = _min(s1) d2, p2, q2 = _min(s2) #print('\n\n',minD,p,q,s1) #print(d2,p2,q2,s2) if minD> d2: minD,p,q = d2, p2, q2 linePoints = findif(s1,lambda pt:floatEql(pt.x,mid),reverse=True) linePoints += findif(s2,lambda pt:floatEql(pt.x,mid)) n = len(linePoints) if n>1: for i in range(1,n): dis = linePoints[i].y -linePoints[i-1].y if dis= mid-minD,reverse=True) rightPoints = findif(s2,lambda pt:pt.x<= mid+minD) for lp in leftPoints: y1,y2 = lp.y-minD, lp.y+minD for rp in rightPoints: if y1< rp.y