-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoords.py
44 lines (38 loc) · 1.26 KB
/
coords.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from math import cos, pi, sin
EARTH_RADIUS = 6371000
def build_sector(azimuth, beam, lat, lon, length=150, parts=2):
"""Drawing sector displaying azimuth and horizontal beam of antenna"""
border_h = beam / 2
step = border_h / parts
azimuths = list(0 for i in range(parts * 2 + 1))
azimuths[len(azimuths) // 2] = azimuth
for part in range(parts):
angle = border_h - step * part
azimuths[part] = azimuth - angle
azimuths[len(azimuths) - 1 - part] = azimuth + angle
coords = [(lon, lat)]
for az in azimuths:
c_lat = round(
lat + length * cos(az * pi / 180) / (EARTH_RADIUS * pi / 180), 5
)
c_lon = round(
lon
+ length
* sin(az * pi / 180)
/ cos(lat * pi / 180)
/ (EARTH_RADIUS * pi / 180),
5,
)
coords.append((c_lon, c_lat))
coords.append(coords[0])
return coords
if __name__ == "__main__":
# EXAMPLE
ASSET_AZIMUTH = 140
H_BEAM = 59
LAT = 55.75254445
LON = 37.60566667
coords = build_sector(ASSET_AZIMUTH, H_BEAM, LAT, LON)
print(
",0 ".join(f"{i},{j}" for i, j in coords) + ",0"
) # format for kml with 0 height