I'm trying to make a program to get azimuth value from two points using this code:
import math
def azimuth(x1, x2, y1, y2):
temp = (y2 - y1) / (x2 - x1)
res = math.degrees(abs(math.atan(temp)))
if x2 > x1 and y2 > y1: #Q1
res = 90 - res
elif x2 < x1 and y2 > y1: #Q2
res = (90 - res) * -1
elif x2 < x1 and y2 < y1: #Q3
res = (90 + res) * -1
elif x2 > x1 and y2 < y1: #Q4
res += 90
else:
raise ValueError('No point difference.')
return res
I've been able to get azimuth value with range (-180)-180. Next, I need to split it into two groups of azimuth value equaly based on range of value. The goal is to get two group which get the closest azimuth value.
The problem is that pairs of points on quadrant III ((-180)-(-90)) and quadrant IV (90-180) logically can be consider as close (e.g:(-179) and 179). About how to split it equally, I've been thinking of using sorted list of azimuth and using index idx = int(math.ceil((len(lst)-1)/2))
as the median to split the list. This is how I do it on code:
lst = [-60, -50, -40, -30, -20, -10, 10, 20, 30, 40, 50, 60]
def split_list(lst):
lst.sort()
idx = int(math.ceil((len(lst)-1)/2))
left = []
right = []
for i in lst:
if i < lst[idx]:
left.append(i)
else:
right.append(i)
print(left)
print(right)
return left, right
split_list(lst)
The code above will return list [-60, -50, -40, -30, -20, -10] and [10, 20, 30, 40, 50, 60] as the result.
Is there any idea of how to do this? With the current condition, I don't have any idea of how to make quadrant III and IV considered as close.