[QRA Library] Fixes #1117. This fixes bearing calculation. Distance was not calculcated if the locator was directly to the north or south of your own locator.

这个提交包含在:
Andreas 2021-07-31 12:01:14 +02:00
父节点 bad229dd09
当前提交 ea916d88c9

查看文件

@ -72,21 +72,10 @@ cos(deg2rad($theta));
} }
function bearing($lat1, $lon1, $lat2, $lon2, $unit = 'M') { function bearing($lat1, $lon1, $lat2, $lon2, $unit = 'M') {
if (round($lon1, 1) == round($lon2, 1)) { $dist = distance($lat1, $lon1, $lat2, $lon2, $unit);
if ($lat1 < $lat2) { $dist = round($dist, 0);
$bearing = 0;
} else { $bearing = get_bearing($lat1, $lon1, $lat2, $lon2);
$bearing = 180;
}
} else {
$dist = distance($lat1, $lon1, $lat2, $lon2, $unit);
$arad = acos((sin(deg2rad($lat2)) - sin(deg2rad($lat1)) * cos(deg2rad($dist / 60))) / (sin(deg2rad($dist
/ 60)) * cos(deg2rad($lat1))));
$bearing = $arad * 180 / pi();
if (sin(deg2rad($lon2 - $lon1)) < 0) {
$bearing = 360 - $bearing;
}
}
$dirs = array("N","E","S","W"); $dirs = array("N","E","S","W");
@ -99,7 +88,7 @@ function bearing($lat1, $lon1, $lat2, $lon2, $unit = 'M') {
#if ($rounded % 2 == 1) #if ($rounded % 2 == 1)
# $dir = $dirs[round_to_int($rounded/4) % 4] . "-" . $dir; # $dir = $dirs[round_to_int($rounded/4) % 4] . "-" . $dir;
} }
$var_dist = ""; $var_dist = "";
#return $dir; #return $dir;
if (isset($dist)) { if (isset($dist)) {
$var_dist = $dist; $var_dist = $dist;
@ -118,13 +107,17 @@ $var_dist = "";
return round($bearing, 0)."&#186; ".$dir." ".$var_dist; return round($bearing, 0)."&#186; ".$dir." ".$var_dist;
} }
function get_bearing($lat1, $lon1, $lat2, $lon2) {
return (rad2deg(atan2(sin(deg2rad($lon2) - deg2rad($lon1)) * cos(deg2rad($lat2)), cos(deg2rad($lat1)) * sin(deg2rad($lat2)) - sin(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($lon2) - deg2rad($lon1)))) + 360) % 360;
}
function qra2latlong($strQRA) function qra2latlong($strQRA)
{ {
if (strlen($strQRA) %2 == 0) { if (strlen($strQRA) %2 == 0) {
$strQRA = strtoupper($strQRA); $strQRA = strtoupper($strQRA);
if (strlen($strQRA) == 4) $strQRA .= "MM"; if (strlen($strQRA) == 4) $strQRA .= "MM";
if (!preg_match('/^[A-Z]{2}[0-9]{2}[A-Z]{2}$/',$strQRA)) return false; if (!preg_match('/^[A-R]{2}[0-9]{2}[A-X]{2}$/',$strQRA)) return false;
list($a,$b,$c,$d,$e,$f) = str_split($strQRA,1); list($a,$b,$c,$d,$e,$f) = str_split($strQRA,1);
$a = ord($a) - ord('A'); $a = ord($a) - ord('A');
$b = ord($b) - ord('A'); $b = ord($b) - ord('A');