| 1 | # Copyright Infomation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Author : Dr. Ahmed Amin Elsheshtawy, Ph.D. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Website: http://www.mewsoft.com | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Email : support@mewsoft.com | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # Copyrights (c) 2000-2015 Mewsoft Corporation. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | package Religion::Islam::Qibla; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Math::Trig; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | our $VERSION = '4.0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # Default destination point is the Kabah Lat=21 Deg N, Long 40 Deg E | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | $self->{DestLat} = $args{DestLat}? $args{DestLat}: 21.423333; # 21.423333; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | $self->{DestLong} = $args{DestLong}? $args{DestLong}: 39.823333; # 39.823333; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub DestLat { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DestLat: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my ($self) = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | $self->{DestLat} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | return $self->{DestLat}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub DestLong { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DestLong: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my ($self) = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | $self->{DestLong} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | return $self->{DestLong}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | #Converting from Degrees, Minutes and Seconds to Decimal Degrees | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub DegreeToDecimal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DegreeToDecimal: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my ($self, $degrees, $minutes, $seconds) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | return $degrees + ($minutes / 60) + ($seconds / 3600); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | #Converting from Decimal Degrees to Degrees, Minutes and Seconds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub DecimalToDegree { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DecimalToDegree: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my ($self, $decimal_degree) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my ($degrees, $minutes, $seconds, $ff); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $degrees = int($decimal_degree); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $ff = $decimal_degree - $degrees; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $minutes = int(60 * $ff); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | $seconds = 60 * ((60 * $ff) - $minutes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | return ($degrees, $minutes, $seconds); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # The shortest distance between points 1 and 2 on the earth's surface is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # d = arccos{cos(Dlat) - [1 - cos(Dlong)]cos(lat1)cos(lat2)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # Dlat = lab - lat2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # Dlong = 10ng - long2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # lati, = latitude of point i | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # longi, = longitude of point i | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | #Conversion of grad to degrees is as follows: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | #Grad=400-degrees/0.9 or Degrees=0.9x(400-Grad) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | #Latitude is determined by the earth's polar axis. Longitude is determined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | #by the earth's rotation. If you can see the stars and have a sextant and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | #a good clock set to Greenwich time, you can find your latitude and longitude. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # one nautical mile equals to: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # 6076.10 feet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # 2027 yards | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # 1.852 kilometers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # 1.151 statute mile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # Calculates the distance between any two points on the Earth | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub GreatCircleDistance { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
GreatCircleDistance: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my ($self, $orig_lat , $dest_lat, $orig_long, $dest_long) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my ($d, $l1, $l2, $i1, $i2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | $l1 = deg2rad($orig_lat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $l2 = deg2rad($dest_lat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $i1 = deg2rad($orig_long); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $i2 = deg2rad($dest_long); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $d = acos(cos($l1 - $l2) - (1 - cos($i1 - $i2)) * cos($l1) * cos($l2)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # One degree of such an arc on the earth's surface is 60 international nautical miles NM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | return rad2deg($d * 60); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | #Calculates the direction from one point to another on the Earth | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # a = arccos{[sin(lat2) - cos(d + lat1 - 1.5708)]/cos(lat1)/sin(d) + 1} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # Great Circle Bearing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub GreatCircleDirection { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
GreatCircleDirection: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my ($self, $orig_lat, $dest_lat, $orig_long, $dest_long, $distance) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my ($a, $b, $d, $l1, $l2, $i1, $i2, $result, $dlong); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $l1 = deg2rad($orig_lat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $l2 = deg2rad($dest_lat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $d = deg2rad($distance / 60); # divide by 60 for nautical miles NM to degree | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $i1 = deg2rad($orig_long); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $i2 = deg2rad($dest_long); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $dlong = $i1 - $i2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $a = sin($l2) - cos($d + $l1 - pi / 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $b = acos($a / (cos($l1) * sin($d)) + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ((abs($dlong) < pi && $dlong < 0) || (abs($dlong) > pi && $dlong > 0) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
abs $dlong < "3.14159265358979" and $dlong < 0 or abs $dlong > "3.14159265358979" and $dlong > 0
abs $dlong < "3.14159265358979" and $dlong < 0
abs $dlong > "3.14159265358979" and $dlong > 0
MC/DC0%0/4
abs $dlong < "3.14159265358979" and $dlong < 0 or abs $dlong > "3.14159265358979" and $dlong > 0
abs $dlong < "3.14159265358979"
$dlong < 0
abs $dlong > "3.14159265358979"
$dlong > 0
Truth table0%0/7
A and B or C and D
A= abs $dlong < "3.14159265358979"B= $dlong < 0C= abs $dlong > "3.14159265358979"D= $dlong > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | #$b = (2 * pi) - $b; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $result = rad2deg($b); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | #The Equivalent Earth redius is 6,378.14 Kilometers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # Calculates the direction of the Qibla from any point on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # the Earth From North Clocklwise | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub QiblaDirection_ { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
QiblaDirection_: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my ($self, $orig_lat, $orig_long) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my ($distance, $bearing); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # Kabah Lat=21 Deg N, Long 40 Deg E | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $distance = $self->GreatCircleDistance($orig_lat, $self->{DestLat}, $orig_long, $self->{DestLong}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $bearing = $self->GreatCircleDirection($orig_lat, $self->{DestLat}, $orig_long, $self->{DestLong}, $distance); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ($orig_lat > $self->{DestLat}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | #$bearing += 180; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | return $bearing; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # Determine Qibla direction using basic spherical trigonometric formula | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # Return float Qibla Direction from the north direction in degrees | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub QiblaDirection__ { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
QiblaDirection__: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my ($self, $orig_lat, $orig_long) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | #$orig_lat = 35.3833; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | #$orig_long = 119.0166; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | #Saudi Arabia, Riyadh Qibla = 245, Qibla Direction: 244.53 degees from true North, Distance from Ka'bah in Makkah: 790.18 km | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my $numerator = sin(deg2rad($self->{DestLong} - $orig_long)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | my $denominator = (cos(deg2rad($orig_lat)) * tan(deg2rad($self->{DestLat}))) - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | (sin(deg2rad($orig_lat)) * cos(deg2rad($self->{DestLong} - $orig_long))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my $q = rad2deg(atan($numerator / $denominator)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | if ($orig_lat > $self->{DestLat}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | #$q += 180; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # Yemen, Sanaa = -35.57 from North = 324.43 from North | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | if ($q < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | #$q += 360; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | return $q; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # This is the only algorithm working with all other confirmed calculations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # See JS code source at http://www.moonsighting.com/qibla.html | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | sub QiblaDirection { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
QiblaDirection: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my ($self, $lat, $lon) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | #$orig_lat = 35.3833; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | #$orig_long = 119.0166; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | #Saudi Arabia, Riyadh Qibla = 245, Qibla Direction: 244.53 degees from true North, Distance from Ka'bah in Makkah: 790.18 km | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my $latk = deg2rad($self->{DestLat}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | my $longk = deg2rad($self->{DestLong}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | my $phi = deg2rad($lat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | my $lambda = deg2rad($lon); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my $qiblad = rad2deg(atan2(sin($longk - $lambda), cos($phi)*tan($latk)-sin($phi)*cos($longk-$lambda))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if ($qiblad < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $qiblad += 360; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | return $qiblad; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | =cuts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | public function getQibla () | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | // The geographical coordinates of the Ka'ba | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | $K_latitude = 21.423333; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | $K_longitude = 39.823333; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | $latitude = $this->lat; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | $longitude = $this->long; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | $numerator = sin(deg2rad($K_longitude - $longitude)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | $denominator = (cos(deg2rad($latitude)) * tan(deg2rad($K_latitude))) - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | (sin(deg2rad($latitude)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | * cos(deg2rad($K_longitude - $longitude))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | $q = atan($numerator / $denominator); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | $q = rad2deg($q); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | if ($this->lat > 21.423333) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | $q += 180; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | return $q; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | <script><!-- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | PI = Math.PI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | var win = null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | function calculate(lat, lon) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | if (isNaN(lat+0.0) || isNaN(lon+0.0)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | alert("Non-numeric entry/entries"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | return "???"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | if ((lat-0.0)>(90.0-0.0) || (lat-0.0)<(-90.0-0.0)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | alert("Latitude must be between -90 and 90 degrees"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | return "???"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | if ((lon-0.0)>(180.0-0.0) || (lon-0.0)<(-180.0-0.0)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | alert("Longitude must be between -180 and 180 degrees"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | return "???"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | if ((lat+0.0==21.4) && (lon+0.0==39.8)) return "Any Direction"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | latk = 21.4225*PI/180.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | longk = 39.8264*PI/180.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | phi = lat*PI/180.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | lambda = lon*PI/180.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | qiblad = 180.0/PI*Math.atan2(Math.sin(longk-lambda), Math.cos(phi)*Math.tan(latk)-Math.sin(phi)*Math.cos(longk-lambda)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | return (qiblad); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | Religion::Islam::Qibla - Calculates the Muslim Qiblah Direction, Great Circle Distance, and Great Circle Direction | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | use Religion::Islam::Qibla; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | #create new object with default options, Destination point is Kabah Lat=21 Deg N, Long 40 Deg E | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | my $qibla = Religion::Islam::Qibla->new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # OR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | #create new object and set your destination point Latitude and/or Longitude | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | my $qibla = Religion::Islam::Qibla->new(DestLat => 21, DestLong => 40); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # Calculate the Qibla direction From North Clocklwise for Cairo : Lat=30.1, Long=31.3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | my $Latitude = 30.1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | my $Longitude = 31.3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | my $QiblaDirection = $qibla->QiblaDirection($Latitude, $Longitude); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | print "The Qibla Direction for $Latitude and $Longitude From North Clocklwise is: " . $QiblaDirection ."\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | # Calculates the distance between any two points on the Earth | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | my $orig_lat = 31; my $dest_lat = 21; my $orig_long = 31.3; $dest_long = 40; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | my $distance = $qibla->GreatCircleDistance($orig_lat , $dest_lat, $orig_long, $dest_long); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | print "The distance is: $distance \n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # Calculates the direction from one point to another on the Earth. Great Circle Bearing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | my $direction = $qibla->GreatCircleDirection($orig_lat, $dest_lat, $orig_long, $dest_long, $distance); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | print "The direction is: $direction \n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # You can get and set the distination point Latitude and Longitude | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # $qibla->DestLat(21); # set distination Latitude | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # $qibla->DestLong(40); # set distincatin Longitude | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | print "Destination Latitude:" . $qibla->DestLat(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | print "Destination Longitude:" . $qibla->DestLong(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | This module calculates the Qibla direction where muslim prayers directs their face. It | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | also calculates and uses the Great Circle Distance and Great Circle Direction. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | L<Date::HijriDate> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | L<Religion::Islam::Quran> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | L<Religion::Islam::PrayTime> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | L<Religion::Islam::PrayerTimes> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | Ahmed Amin Elsheshtawy, <support@islamware.com> <support@mewsoft.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | Website: http://www.islamware.com http://www.mewsoft.com | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | Copyright (C) 2006-2015 by Ahmed Amin Elsheshtawy support@islamware.com, support@mewsoft.com | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | L<http://www.islamware.com> L<http://www.mewsoft.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||