From 014cbc5a8a40e0a3f4648cc62cce7898607ec7c9 Mon Sep 17 00:00:00 2001 From: vv01f Date: Mon, 15 Jul 2019 21:44:29 +0200 Subject: [PATCH] draft --- position.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 position.py diff --git a/position.py b/position.py new file mode 100755 index 0000000..9be9249 --- /dev/null +++ b/position.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +import math + +def arc_to_deg(arc): + """convert spherical arc length [m] to great circle distance [deg]""" + return float(arc)/6371/1000 * 180/math.pi + +def deg_to_arc(deg): + """convert great circle distance [deg] to spherical arc length [m]""" + return float(deg)*6371*1000 * math.pi/180 + +def latlon_to_xyz(lat,lon): + """Convert angluar to cartesian coordiantes + + latitude is the 90deg - zenith angle in range [-90;90] + lonitude is the azimuthal angle in range [-180;180] + """ + r = 6371 # https://en.wikipedia.org/wiki/Earth_radius + theta = math.pi/2 - math.radians(lat) + phi = math.radians(lon) + x = r * math.sin(theta) * math.cos(phi) # bronstein (3.381a) + y = r * math.sin(theta) * math.sin(phi) + z = r * math.cos(theta) + return [x,y,z] + +def xyz_to_latlon (x,y,z): + """Convert cartesian to angular lat/lon coordiantes""" + r = math.sqrt(x**2 + y**2 + z**2) + theta = math.asin(z/r) # https://stackoverflow.com/a/1185413/4933053 + phi = math.atan2(y,x) + lat = math.degrees(theta) + lon = math.degrees(phi) + return [lat,lon]