[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.
这个提交包含在:
父节点
bad229dd09
当前提交
ea916d88c9
共有 1 个文件被更改,包括 15 次插入 和 22 次删除
|
|
@ -72,21 +72,10 @@ cos(deg2rad($theta));
|
|||
}
|
||||
|
||||
function bearing($lat1, $lon1, $lat2, $lon2, $unit = 'M') {
|
||||
if (round($lon1, 1) == round($lon2, 1)) {
|
||||
if ($lat1 < $lat2) {
|
||||
$bearing = 0;
|
||||
} else {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
$dist = round($dist, 0);
|
||||
|
||||
$bearing = get_bearing($lat1, $lon1, $lat2, $lon2);
|
||||
|
||||
$dirs = array("N","E","S","W");
|
||||
|
||||
|
|
@ -118,13 +107,17 @@ $var_dist = "";
|
|||
return round($bearing, 0)."º ".$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)
|
||||
|
||||
{
|
||||
if (strlen($strQRA) %2 == 0) {
|
||||
$strQRA = strtoupper($strQRA);
|
||||
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);
|
||||
$a = ord($a) - ord('A');
|
||||
$b = ord($b) - ord('A');
|
||||
|
|
|
|||
正在加载…
在新工单中引用