import math # 利用两个点的坐标计算直线斜率 def slope(point1, point2): return (point2[1]-point1[1])/(point2[0]-point1[0]) # 计算角度 def getAngle(pointsList): point1, point2, point3 = pointsList[-3:] slope1 = slope(point1, point2) slope2 = slope(point1, point3) #point1 ==center angR = math.atan((slope2-slope1)/(1+(slope2*slope1))) angD = round(math.degrees(angR)) if angD<0: angD = 180+angD if point3[1] > point1[1]: angD = 180 + angD return angD
#绕着圆心顺时针排序 print(points_data) points_data.sort(key=lambda c:getAngle((cneter_last,(0,cneter_last[1]), c))) print(points_data)