This is a part of the code I am writing now in the 3.3 version of python.I have the "E" list,containing tuples of 2 elements(co ordinates of some points in a 2D level) and after I do some sorting I am trying to take the "y co-ordinate" in the first case,and the "x co-ordinate" in the second case,to create a center of the points in the 2D level.
I use turtle graphics to show this "new centre point" but sometimes it does not fit right in the image.Am I doing something wrong in the code or in the math I use?
- Code: Select all
sorted_E_by_y = sorted(E, key=lambda tup: tup)
lowest_py = (sorted_E_by_y)
highest_py = (sorted_E_by_y[length_of_E-1])
sorted_E_by_x = sorted(E, key=lambda tup: tup)
lowest_px = (sorted_E_by_x)
highest_px = (sorted_E_by_x[length_of_E-1])
centre_x = (highest_px-lowest_px)/2
centre_y = (highest_py-lowest_py)/2
Is there another way to calculate this plasmatic centre of the many points in a 2d level?