将圆的点/坐标排序为逻辑顺序

时间:2013-12-10 22:29:44

标签: python sorting coordinates geometry

基本上,我有一个从csv文件中读取的x,y,z坐标列表,它形成一个粗略的圆圈而不是[[82.41657257, 0.863095999, -5400.0], [82.4160614, 0.0, -5400.0], [82.41255188, -0.863053977, -5400.0], [82.40731812, 1.726186991, -5400.0],......。我有圆心,但无法弄清楚如何对点进行排序。有没有办法将这些点分类为逻辑顺序(顺时针)?

import csv
coorinput=[]
#open and read file
with open("test.csv","rb") as readfile:
reader = csv.reader(readfile, dialect = 'excel',skipinitialspace = True)
for row in reader:
    coorinput.append(map(float, row))

#call sort function here

1 个答案:

答案 0 :(得分:2)

您可以使用三角学来查找每个点与X轴的角度:

from math import atan2
coorinput.sort(key=lambda c:atan2(c[0], c[1]))