Benutzer:Bk1 168/Luftlinie
Zur Navigation springen
Zur Suche springen
#!/usr/bin/ruby
include Math
us = ARGV[0] # Breite
vs = ARGV[1] # Länge
xs = nil
ys = nil
if (ARGV[2] == 'Visby')
xs = "57:38:20.0"
ys = "18:17:40.0"
elsif (ARGV[2] == "Hemse")
xs = "57:13:60.0"
ys= "18:22:0.0"
elsif (ARGV[2] == "Slite")
xs = "57:42:37.0"
ys = "18:47:58.0"
elsif (ARGV[2] == "Tingstäde")
xs = "57:44:01.0"
ys = "18:36:20.0"
elsif (ARGV[2] == "Klintehamn")
xs = "57:23:12.0"
ys = "18:12:10.0"
elsif (ARGV[2] == "Burgsvik")
xs = "57:01:52.0"
ys = "18:16:24.0"
else
xs = ARGV[2] # Breite
ys = ARGV[3] # Länge
end
class String
def to_cf
unless match /(\d+):(\d+):([0-9.]+)/
$stderr.puts "#{self} does not have correct format"
exit 1
end
alpha = ($1.to_f / 180 + $2.to_f / (180*60) + $3.to_f / (180*3600)) * PI
alpha
end
end
u = us.to_cf
v = vs.to_cf
x = xs.to_cf
y = ys.to_cf
zeta = acos(sin(u) * sin(x) + cos(u) * cos(x) * cos(y-v))
d = zeta * 6370
puts("d=#{d}")