-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.html
More file actions
74 lines (59 loc) · 2.43 KB
/
Copy pathpython.html
File metadata and controls
74 lines (59 loc) · 2.43 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bearing Calculator</title>
<link rel="stylesheet" href="https://pyscript.net/releases/2024.5.1/core.css" />
<script type="module" src="https://pyscript.net/releases/2024.5.1/core.js"></script>
</head>
<body>
<label for="rad">Radius:</label>
<input type="text" id="rad" name="rad" value="6372.795"><br><br>
<label for="lat1">Latitude 1:</label>
<input type="text" id="lat1" name="lat1" value="48.85836"><br><br>
<label for="lon1">Longitude 1:</label>
<input type="text" id="lon1" name="lon1"value="2.29449"><br><br>
<label for="lat1">Latitude 2:</label>
<input type="text" id="lat2" name="lat2"value="14.74578"><br><br>
<label for="lon1">Longitude 2:</label>
<input type="text" id="lon2" name="lon2"value="-17.52819"><br><br>
<input type="submit" id="submit" value="Submit" onClick="window.location.reload()"><br><br>
<script type="py">
from pyscript import window, document
import math
from pyscript import display
rad_earth = 6372.795
rad = float(document.querySelector("#rad").value)
llat1 = float(document.querySelector("#lat1").value)
llong1 = float(document.querySelector("#lon1").value)
llat2 = float(document.querySelector("#lat2").value)
llong2 = float(document.querySelector("#lon2").value)
lat1 = llat1 * math.pi / 180.
lat2 = llat2 * math.pi / 180.
long1 = llong1 * math.pi / 180.
long2 = llong2 * math.pi / 180.
cl1 = math.cos(lat1)
cl2 = math.cos(lat2)
sl1 = math.sin(lat1)
sl2 = math.sin(lat2)
delta = long2 - long1
cdelta = math.cos(delta)
sdelta = math.sin(delta)
y = math.sqrt(math.pow(cl2 * sdelta, 2) + math.pow(cl1 * sl2 - sl1 * cl2 * cdelta, 2))
x = sl1 * sl2 + cl1 * cl2 * cdelta
ad = math.atan2(y, x)
dist = ad * rad
x = (cl1 * sl2) - (sl1 * cl2 * cdelta)
y = sdelta * cl2
z = math.degrees(math.atan(-y / x))
if (x < 0):
z = z + 180.
z2 = (z + 180.) % 360. - 180.
z2 = - math.radians(z2)
anglerad2 = z2 - ((2 * math.pi) * math.floor((z2 / (2 * math.pi))))
angledeg = (anglerad2 * 180.) / math.pi
display('Distance => %.3f' % dist + ' [km]')
display('Initial bearing => %.2f' % angledeg + ' [degrees]')
</script>
</body>
</html>