Haversine formula: Difference between revisions
Content added Content deleted
m (→{{header|Haskell}}: (Tidied)) |
No edit summary |
||
Line 3,735: | Line 3,735: | ||
The approximate distance between airports LNZ: (48.233, 14.183) and N/A: (48.233, 14.188) is 370.34 m. |
The approximate distance between airports LNZ: (48.233, 14.183) and N/A: (48.233, 14.188) is 370.34 m. |
||
The uncertainty is under 0.5%, or 1.9 m.</pre>Looking at the altitude difference between the last two airports, (299 - 96 = 203), the reported distance of 370 meters ought to be around 422 meters if you actually went there and saw it for yourself. |
The uncertainty is under 0.5%, or 1.9 m.</pre>Looking at the altitude difference between the last two airports, (299 - 96 = 203), the reported distance of 370 meters ought to be around 422 meters if you actually went there and saw it for yourself. |
||
=={{header|Vlang}}== |
|||
{{trans|go}} |
|||
<lang vlang>import math |
|||
fn haversine(h f64) f64 { |
|||
return .5 * (1 - math.cos(h)) |
|||
} |
|||
struct Pos { |
|||
lat f64 // latitude, radians |
|||
long f64 // longitude, radians |
|||
} |
|||
fn deg_pos(lat f64, lon f64) Pos { |
|||
return Pos{lat * math.pi / 180, lon * math.pi / 180} |
|||
} |
|||
const r_earth = 6372.8 // km |
|||
fn hs_dist(p1 Pos, p2 Pos) f64 { |
|||
return 2 * r_earth * math.asin(math.sqrt(haversine(p2.lat-p1.lat)+ |
|||
math.cos(p1.lat)*math.cos(p2.lat)*haversine(p2.long-p1.long))) |
|||
} |
|||
fn main() { |
|||
println(hs_dist(deg_pos(36.12, -86.67), deg_pos(33.94, -118.40))) |
|||
}</lang> |
|||
{{out}} |
|||
<pre>2887.2599506071</pre> |
|||
=={{header|Wren}}== |
=={{header|Wren}}== |