fix regex parse in sh/dx, add DXBearing::distance
[spider.git] / perl / DXBearing.pm
index 637a6aa889642b33d3a04c3b62656312b3f9e4c2..db6f4686d0a75ed89c32e0c32e28509ae233bb5a 100644 (file)
@@ -8,7 +8,7 @@
 #
 # Copyright (c) 1998 - Dirk Koopman G1TLH
 #
-# $Id$
+#
 #
 
 package DXBearing;
@@ -101,6 +101,20 @@ sub bdist
        return (rd($az), $dx);
 }
 
+# just the distance - parameters as above
+sub distance
+{
+       my $hn = dr(shift);
+       my $he = dr(shift);
+       my $n = dr(shift);
+       my $e = dr(shift);
+       return (0, 0) if $hn == $n && $he == $e;
+       my $co = cos($he-$e)*cos($hn)*cos($n)+sin($hn)*sin($n);
+       my $ca = $co ? atan(abs(sqrt(1-$co*$co)/$co)) : $pi;
+       $ca = $pi-$ca if $co < 0;
+       my $dx = 6367*$ca;
+}
+
 # turn a lat long string into floating point lat and long
 sub stoll
 {