diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2024-02-13 09:49:36 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2024-02-13 09:49:36 +0100 |
commit | fe846b6fe98ed766bd316642a13ff484e57fe035 (patch) | |
tree | 45594ff2ca48d89b1c40fe6f13430e37502461ee | |
parent | 5f4443bbecae1b3fc907cba6116b219036793d68 (diff) | |
download | ISS_Above-fe846b6fe98ed766bd316642a13ff484e57fe035.tar.gz |
First experiments with the shell script
-rw-r--r-- | .gitmodules | 3 | ||||
-rwxr-xr-x | harvesin.sh | 84 | ||||
-rwxr-xr-x | iss_above.sh | 42 | ||||
m--------- | mirkarte | 0 |
4 files changed, 129 insertions, 0 deletions
diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..6f45feb --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "mirkarte"] + path = mirkarte + url = https://git.cepl.eu/cgit/mirkarte diff --git a/harvesin.sh b/harvesin.sh new file mode 100755 index 0000000..3aad71d --- /dev/null +++ b/harvesin.sh @@ -0,0 +1,84 @@ +#!/bin/sh +#- +# © 2021 mirabilos Ⓕ CC0; implementation of Haversine GCD from public sources +# +# now developed online: +# https://evolvis.org/plugins/scmgit/cgi-bin/gitweb.cgi?p=useful-scripts/mirkarte.git;a=blob;f=geo.sh;hb=HEAD + +if test "$#" -ne 4; then + echo >&2 "E: syntax: $0 lat1 lon1 lat2 lon2" + exit 1 +fi + +set -e + +# make GNU bc use POSIX mode and shut up +BC_ENV_ARGS=-qs +export BC_ENV_ARGS + +# assignment of constants, variables and functions +# p: multiply with to convert from degrees to radians (π/180) +# r: earth radius in metres +# d: distance +# h: haversine intermediate +# i,j: (lat,lon) point 1 +# x,y: (lat,lon) point 2 +# k: delta lat +# l: delta lon +# m: sin(k/2) (square root of hav(k)) +# n: sin(l/2) ( partial haversine ) +# n(x): arcsin(x) +# r(x,n): round x to n decimal digits +# v(x): sign (Vorzeichen) +# w(x): min(1, sqrt(x)) (Wurzel) + +bc -l <<-EOF +scale=64 +define n(x) { + if (x == -1) return (-2 * a(1)) + if (x == 1) return (2 * a(1)) + return (a(x / sqrt(1 - x*x))) +} +define v(x) { + if (x < 0) return (-1) + if (x > 0) return (1) + return (0) +} +define r(x, n) { + auto o + o = scale + if (scale < (n + 1)) scale = (n + 1) + x += v(x) * 0.5 * A^-n + scale = n + x /= 1 + scale = o + return (x) +} +define w(x) { + if (x >= 1) return (1) + return (sqrt(x)) +} +/* WGS84 reference ellipsoid: große Halbachse (metres), Abplattung */ +i = 6378137.000 +x = 1/298.257223563 +/* other axis */ +j = i * (1 - x) +/* mean radius resulting */ +r = (2 * i + j) / 3 +/* coordinates */ +p = (4 * a(1) / 180) +i = (p * $1) +j = (p * $2) +x = (p * $3) +y = (p * $4) +/* calculation */ +k = (x - i) +l = (y - j) +m = s(k / 2) +n = s(l / 2) +h = ((m * m) + (c(i) * c(x) * n * n)) +d = 2 * r * n(w(h)) +r(d, 3) +EOF + +# output is in metres, rounded to millimetres, error < ¼% in WGS84 diff --git a/iss_above.sh b/iss_above.sh new file mode 100755 index 0000000..c5857ab --- /dev/null +++ b/iss_above.sh @@ -0,0 +1,42 @@ +#!/bin/bash +set -eux + +API_URL='http://api.open-notify.org/iss-now.json' + +API_data=$(curl -s "$API_URL") + +latitude="$(echo $API_data|jq -r '. | .iss_position.latitude')" +longitude="$(echo $API_data|jq -r '. | .iss_position.longitude')" + +my_lat="50.0769160" +my_long="14.4740344" + +. "mirkarte/geo.sh" + +# distance lat1 lon1 lat2 lon2 → metres (rounded to millimetres), error < ¼% +echo "$(distance $latitude $longitude $my_lat $my_long)" + +## +## processResult: function() { +## this.task_queue--; +## +## if (this.task_queue === 0) { +## // print('our location: ' + this.current_location.toSource()); +## // print('iss coordinates: ' + this.iss_coords.toSource()); +## +## let dist = this.get_distance(this.current_location.Latitude, +## this.current_location.Longitude, +## this.iss_coords.iss_position.latitude, +## this.iss_coords.iss_position.longitude) +## +## print('ISS is ' + dist + ' km away.'); +## +## Mainloop.quit(); +## } +## } +##}); +## +##let client = new ISS_Above(); +##client.run(); +## +##Mainloop.run(); diff --git a/mirkarte b/mirkarte new file mode 160000 +Subproject a313bef5de8330bea504a41480ca858f6ad1148 |