Issue
Basically, I have a list of x,y,z coordinates read from a csv file that forms a rough circle and are not in order [[82.41657257, 0.863095999, -5400.0], [82.4160614, 0.0, -5400.0], [82.41255188, -0.863053977, -5400.0], [82.40731812, 1.726186991, -5400.0],......
. I have the centre of the circle but cannot work out how to sort the points. Is there any way of sorting these points into a logical order (clockwise)?
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
Solution
You can use trigonometry to find the angle each point makes with the X axis:
from math import atan2
coorinput.sort(key=lambda c:atan2(c[0], c[1]))
Answered By - Hardmath123
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.