| 1 | package Geo::Coordinates::VandH; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use Math::Trig; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Math::Complex; #fixes a few one-off problems with negative square roots | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use vars qw($VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | |||||||||||
| 8 | |||||||||||
| 9 | 1 | $VERSION = '1.11'; | |||||||||
| 10 | |||||||||||
| 11 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 12 | 0 | my $package = shift; | |||||||||
| 13 | 0 | return bless({}, $package); | |||||||||
| 14 | }; | ||||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | sub distance { | ||||||||
|
Subroutine
distance: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||
| 17 | 0 | my $self = shift; | |||||||||
| 18 | 0 | my $v1; | |||||||||
| 19 | my $h1; | ||||||||||
| 20 | 0 | my $v2; | |||||||||
| 21 | 0 | my $h2; | |||||||||
| 22 | 0 | my $miles; | |||||||||
| 23 | 0 | my $vd; | |||||||||
| 24 | 0 | my $hd; | |||||||||
| 25 | 0 | my $sum; | |||||||||
| 26 | 0 | my $count; | |||||||||
| 27 | 0 | ($v1,$h1,$v2,$h2) = @_; | |||||||||
| 28 | 0 | $vd=$v1-$v2; | |||||||||
| 29 | 0 | ▶ | if ($vd < 0) { $vd=$vd*-1; }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 0 | $hd=$h1-$h2; | |||||||||
| 31 | 0 | ▶ | if ($hd < 0) { $hd=$hd*-1; }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 0 | $vd=$vd/3; | |||||||||
| 33 | 0 | $hd=$hd/3; | |||||||||
| 34 | 0 | $count=1; | |||||||||
| 35 | 0 | ▶ | while (($vd**2+$hd**2) > 1777) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 0 | $vd=$vd/3; | |||||||||
| 37 | 0 | $hd=$hd/3; | |||||||||
| 38 | 0 | $count++; | |||||||||
| 39 | }; | ||||||||||
| 40 | 0 | $sum=$vd**2+$hd**2; | |||||||||
| 41 | 0 | $sum = $sum * ( 0.1 * (9**$count)); | |||||||||
| 42 | 0 | $miles=sqrt($sum); | |||||||||
| 43 | #round up to next greatest mile | ||||||||||
| 44 | 0 | ▶ | if (($miles-int($miles)) > 0) { $miles=int($miles)+1; }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | return $miles; | |||||||||
| 46 | }; | ||||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | sub vh2ll { | ||||||||
|
Subroutine
vh2ll: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||
| 49 | 0 | my $self = shift; | |||||||||
| 50 | #Constants shamelessly stolen from vh2ll.c | ||||||||||
| 51 | 0 | my $m_pi=3.14159265358979323846; | |||||||||
| 52 | 0 | my $transv=6363.235; | |||||||||
| 53 | 0 | my $transh=2250.7; | |||||||||
| 54 | 0 | my $rotc=0.23179040; | |||||||||
| 55 | 0 | my $rots=0.97276575; | |||||||||
| 56 | 0 | my $radius=12481.103; | |||||||||
| 57 | 0 | my $ex=0.40426992; | |||||||||
| 58 | 0 | my $ey=0.68210848; | |||||||||
| 59 | 0 | my $ez=0.60933887; | |||||||||
| 60 | 0 | my $wx=0.65517646; | |||||||||
| 61 | 0 | my $wy=0.37733790; | |||||||||
| 62 | 0 | my $wz=0.65449210; | |||||||||
| 63 | 0 | my $px=-0.555977821730048699; | |||||||||
| 64 | 0 | my $py=-0.345728488161089920; | |||||||||
| 65 | 0 | my $pz=0.755883902605524030; | |||||||||
| 66 | 0 | my $gx=0.216507961908834992; | |||||||||
| 67 | 0 | my $gy=-0.134633014879368199; | |||||||||
| 68 | 0 | my $a=0.151646645621077297; | |||||||||
| 69 | 0 | my $q=-0.294355056616412800; | |||||||||
| 70 | 0 | my $q2=0.0866448993556515751; | |||||||||
| 71 | 0 | my @bi = ( 1.00567724920722457, -0.00344230425560210245, 0.000713971534527667990, -0.0000777240053499279217, 0.00000673180367053244284, -0.000000742595338885741395, 0.0000000905058919926194134 ); | |||||||||
| 72 | 0 | my $x; | |||||||||
| 73 | my $y; | ||||||||||
| 74 | 0 | my $z; | |||||||||
| 75 | 0 | my $v; | |||||||||
| 76 | 0 | my $h; | |||||||||
| 77 | 0 | my $delta; | |||||||||
| 78 | 0 | ($v,$h) = @_; | |||||||||
| 79 | 0 | my $t1 = ($v - $transv) / $radius; | |||||||||
| 80 | 0 | my $t2 = ($h - $transh) / $radius; | |||||||||
| 81 | 0 | my $vhat = $rotc*$t2 - $rots*$t1; | |||||||||
| 82 | 0 | my $hhat = $rots*$t2 + $rotc*$t1; | |||||||||
| 83 | 0 | my $e = cos(sqrt($vhat*$vhat + $hhat*$hhat)); | |||||||||
| 84 | 0 | my $w = cos(sqrt($vhat*$vhat + ($hhat-0.4)*($hhat-0.4))); | |||||||||
| 85 | 0 | my $fx = $ey*$w - $wy*$e; | |||||||||
| 86 | 0 | my $fy = $ex*$w - $wx*$e; | |||||||||
| 87 | 0 | my $b = $fx*$gx + $fy*$gy; | |||||||||
| 88 | 0 | my $c = $fx*$fx + $fy*$fy - $q2; | |||||||||
| 89 | 0 | my $disc = $b*$b - $a*$c; #discriminant | |||||||||
| 90 | 0 | ▶ | if ($disc == 0.0) { #It's right on the E-W axis | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | 0 | $z = $b/$a; | |||||||||
| 92 | 0 | $x = ($gx*$z - $fx)/$q; | |||||||||
| 93 | 0 | $y = ($fy - $gy*$z)/$q; | |||||||||
| 94 | } else { | ||||||||||
| 95 | 0 | $delta = sqrt($disc); | |||||||||
| 96 | 0 | $z = ($b + $delta)/$a; | |||||||||
| 97 | 0 | $x = ($gx*$z - $fx)/$q; | |||||||||
| 98 | 0 | $y = ($fy - $gy*$z)/$q; | |||||||||
| 99 | 0 | ▶ | if ( $vhat * ( $px*$x + $py*$y + $pz*$z) < 0 ) { #wrong direction | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | 0 | $z = ($b - $delta)/$a; | |||||||||
| 101 | 0 | $x = ($gx*$z - $fx)/$q; | |||||||||
| 102 | 0 | $y = ($fy - $gy*$z)/$q; | |||||||||
| 103 | }; | ||||||||||
| 104 | }; | ||||||||||
| 105 | 0 | my $lat=asin($z); | |||||||||
| 106 | #Use polynomial approximation for inverse mapping | ||||||||||
| 107 | #(sphere to spheroid) | ||||||||||
| 108 | 0 | my $lat2 = $lat*$lat; | |||||||||
| 109 | 0 | my $earthlat = 0; | |||||||||
| 110 | 0 | ▶ | for (my $i=6; $i>=0 ; $i--) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | 0 | ▶ | $earthlat = ($earthlat + $bi[$i]) * ($i? $lat2 : $lat); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 112 | }; | ||||||||||
| 113 | 0 | $earthlat *= 180/$m_pi; | |||||||||
| 114 | # Adjust Longitude by 52 degrees | ||||||||||
| 115 | 0 | my $lon = atan2($x,$y) * 180/$m_pi; | |||||||||
| 116 | 0 | my $earthlon = $lon + 52.0000000000000000; | |||||||||
| 117 | 0 | return ($earthlat,$earthlon); | |||||||||
| 118 | }; | ||||||||||
| 119 | 1 | 1; | |||||||||
| 120 | __END__ | ||||||||||