Viestikallion työkaluja: Maidenhead suunta ja etäisyys
 

Hostattuja

Tue toimintaamme!

Toimii kohtuullisen hyvin, kokeile ja raportoi!

Havaittu laskennan virhetaso etäisyyksissä lyhyisiin ortometrisiin matkoihin verrattuna on luokkaa 10 ppm. Syy toistaiseksi tuntematon. Tämä virhetaso on käytännössä merkityksetön Maidenhead etäisyyksien laskennassa, joka yleensä tehdään pallolla ja sisältää väärästä geodesiasta johtuvan 0.1-0.2 % virheen...

<?php     # -*- PHP -*-

$QTHMH  $HTTP_POST_VARS["QTH-MH"];
if (
$QTHMH == "") {
    
$QTHMH  $HTTP_GET_VARS["QTH-MH"];
}

$OTHERURI="mhbearing.php?LANG=other";
$NOCACHE=1;

require(
"../include/head1.inc");

langfilt('FI:
FI:Viestikallion työkaluja: Maidenhead suunta ja etäisyys
EN:Viestikallio Tools: Maidenhead Bearing and Distance'
);
require(
"../include/head2.inc");
langfilt('FI:
FI:Viestikallion työkaluja: Maidenhead suunta ja etäisyys
EN:Viestikallio Tools: Maidenhead Bearing and Distance'
);
require(
"../include/head3.inc");
require(
"../include/menu.inc");

langfilt('FI:

<TABLE><TR><TD>

<FONT COLOR=GREEN>
FI: Toimii kohtuullisen hyvin, kokeile ja raportoi!
FI:<P>
FI: Havaittu laskennan virhetaso etäisyyksissä lyhyisiin ortometrisiin
FI: matkoihin verrattuna on luokkaa 10 ppm.  Syy toistaiseksi tuntematon.
FI: Tämä virhetaso on käytännössä merkityksetön Maidenhead etäisyyksien
FI: laskennassa, joka yleensä tehdään pallolla ja sisältää väärästä
FI: geodesiasta johtuvan 0.1-0.2 % virheen...
EN: Works fairly well, try it and do report!
EN:<P>
EN: There is a residual computation error at level of about 10 ppm,
EN: reasons unknown.
EN: The residual error is practically meaningless when computing Maidenhead
EN: distances, which usually are computed with spheroid equations and thus
EN: can have about 0.1 - 0.2 % error due to wrong geodetics...
</FONT>
<P>
'
);

if (
$HTTP_GET_VARS["SOURCE"] != "" || $HTTP_GET_VARS["source"] != "") {
    echo(
"<FONT SIZE=1>\n");
    
highlight_file("mhbearing.php");
    echo(
"</FONT>\n");
    echo(
"</TD></TR></TABLE><P><HR><P>Matti Aarnio" .
         
" - OH2MQK &lt;matti.aarnio&#64;zmailer.org&gt;\n");
    include(
"../include/base.inc");
    include(
"../include/foot.inc"); 
    exit;
}

require(
"kkj-funcs.php");
require(
"geodinver.php");
require(
"maidenheadfuncs.php");



$DoTest 0;
if (
$HTTP_GET_VARS["TEST"] != "" || $HTTP_GET_VARS["test"] != "") {
    
$DoTest 1;
}

$DoKKJ  0;
$DoLaLo 0;
$DoLaLoWGS 0;
$Debug  0;
$DoMaidenhead 0;

if (
$HTTP_GET_VARS["DO-KKJ"] != "" || $HTTP_GET_VARS["do-kkj"] != "") {
    
$DoKKJ 1;
}
if (
$HTTP_POST_VARS["DO-KKJ"] != "" || $HTTP_POST_VARS["do-kkj"] != "") {
    
$DoKKJ 1;
}
if (
$HTTP_GET_VARS["DO-LALO"] != "" || $HTTP_GET_VARS["do-lalo"] != "") {
    
$DoLaLo 1;
}
if (
$HTTP_POST_VARS["DO-LALO"] != "" || $HTTP_POST_VARS["do-lalo"] != "") {
    
$DoLaLo 1;
}
if (
$HTTP_GET_VARS["DOWLALO"] != "" || $HTTP_GET_VARS["dowlalo"] != "") {
    
$DoLaLo 1;
    
$DoLaLoWGS 1;
}
if (
$HTTP_POST_VARS["DOWLALO"] != "" || $HTTP_POST_VARS["dowlalo"] != "") {
    
$DoLaLo 1;
    
$DoLaLoWGS 1;
}

if (
$HTTP_GET_VARS["DO-MH"] != "" || $HTTP_GET_VARS["do-mh"] != "") {
    
$DoMaidenhead 1;
}
if (
$HTTP_POST_VARS["DO-MH"] != "" || $HTTP_POST_VARS["do-mh"] != "") {
    
$DoMaidenhead 1;
}

$MHDIGITS $HTTP_POST_VARS["MHDIGITS"];
if (
$MHDIGITS == "") {
    
$MHDIGITS $HTTP_GET_VARS["MHDIGITS"];
}
if (
$MHDIGITS == "") {
    
$MHDIGITS $HTTP_GET_VARS["mhdigits"];
}

if (
$MHDIGITS == 0) {
    
$MHDIGITS 10;
}

if (
$HTTP_GET_VARS["Debug"] != "") {
    
$Debug 1;
}
if (
$HTTP_POST_VARS["Debug"] != "") {
    
$Debug 1;
}


if (
$Debug) {                   # TEST TEST!

    
echo("<FONT SIZE=1><PRE>\n");
    echo(
"---------- Headers  --------------\n");
    
$headers getallheaders();
    for(
reset($headers); $key key($headers); next($headers)) {
        echo(
"$key = $headers[$key]\n");
    }
    echo(
"---------- GET VARS --------------\n");
    
$headers $HTTP_GET_VARS;
    for(
reset($headers); $key key($headers); next($headers)) {
        echo(
"$key = $headers[$key]\n");
    }
    echo(
"---------- POST VARS -------------\n");
    
$headers $HTTP_POST_VARS;
    for(
reset($headers); $key key($headers); next($headers)) {
        echo(
"$key = $headers[$key]\n");
    }
    echo(
"----------------------------------\n");
    echo(
"</PRE></FONT>\n");
}


$KKJin[X] = $HTTP_POST_VARS["KKJP"];
$KKJin[Y] = $HTTP_POST_VARS["KKJI"];
if (
$KKJin[X] == "") {
    
$KKJin[X] = $HTTP_GET_VARS["KKJP"];
    
$KKJin[Y] = $HTTP_GET_VARS["KKJI"];
}

if (
$KKJin[X] == "") {
    
$KKJin[X] = "6500000.000";
    
$KKJin[Y] = "3500000.000";
}

$WGSMH  $HTTP_POST_VARS["WGSMH"];
if (
$WGSMH == "")
    
$WGSMH  $HTTP_GET_VARS["WGSMH"];

$KKJin[La] = $HTTP_POST_VARS["KKJLAT"];
$KKJin[Lo] = $HTTP_POST_VARS["KKJLONG"];

if (
$KKJin[La] == "") {
    
$KKJin[La] = $HTTP_GET_VARS["KKJLAT"];
    
$KKJin[Lo] = $HTTP_GET_VARS["KKJLONG"];
}

if (
$KKJin[La] == "") {
    
$KKJin[La] = "60  0  0.00000";
    
$KKJin[Lo] = "27  0  0.00000";
}

$WGSin[La] = $HTTP_POST_VARS["WGSLAT"];
$WGSin[Lo] = $HTTP_POST_VARS["WGSLONG"];

if (
$WGSin[La] == "") {
    
$WGSin[La] = $HTTP_GET_VARS["WGSLAT"];
    
$WGSin[Lo] = $HTTP_GET_VARS["WGSLONG"];
}

if (
$WGSin[La] == "") {
    
$WGSin[La] = "60  0  0.00000";
    
$WGSin[Lo] = "27  0  0.00000";
}



#
# Input:  This[La]      Source Latitude, in radians
#         This[Lo]      Source Longitude, in radians
#         That[La]      Destination Latitude, in radians
#         That[Lo]      Destination Longitude, in radians
# Output: R[s]          Distance, in kilometers
#

function maidenhead_km_distance($This$That) {

    
#Haversine Formula (from R.W. Sinnott, "Virtues of the Haversine", 
    #Sky and Telescope, vol. 68, no. 2, 1984, p. 159): 

    
$dlon $That[Lo] - $This[Lo];
    
$dlat $That[La] - $This[La];

    
$sinDlat2 sin($dlat/2);
    
$sinDlon2 sin($dlon/2);
    
$a = ($sinDlat2 $sinDlat2 +
          
cos($This[La]) * cos($That[La]) * $sinDlon2 $sinDlon2);

    
# The Haversine Formula can be expressed in terms of a two-argument 
    # inverse tangent function, atan2(y,x), instead of an inverse sine 
    # as follows (no bulletproofing is needed for an inverse tangent): 

    
$c 2.0 atan2sqrt($a), sqrt(1.0-$a) );
    
# $d = R * $c ; # Radius of ball times angle [radians] ...


    
$R[s] = rad2deg($c) * 111.2;

    return(
$R);

}

define("gm4anb_a"6378388.0); # Semi-major axis
define("gm4anb_b"6356912.0); # Semi-minor axis
define("gm4anb_b2pera2", (gm4anb_b gm4anb_b gm4anb_a gm4anb_a));
define("gm4anb_e"1.0 gm4anb_b2pera2); # Eccentricity squared

#
# Input:  This[La]      Source Latitude, in radians
#         This[Lo]      Source Longitude, in radians
#         That[La]      Destination Latitude, in radians
#         That[Lo]      Destination Longitude, in radians
# Output: R[s]          Distance, in kilometers
#

# Math explained:  http://www.kirsta.com/radio/dxrechow.doc

function gm4anb_km_distance($This$That) {

    
# double e, si, co, th, ca, a1, a2, l1, l2, ep; /* Locals */

    # Convert latitudes to geocentric

    
$This[La] = atan(gm4anb_b2pera2 tan($This[La]));
    
$That[La] = atan(gm4anb_b2pera2 tan($That[La]));

    
# lat1 = atan((b * b) / (a * a) * tan(lat1));
    # lat2 = atan((b * b) / (a * a) * tan(lat2));

    # Calculate central angle 
    #ca = acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon2-lon1));

    
$ca acos(sin($This[La])*sin($That[La]) +
           
cos($This[La])*cos($That[La])*cos($That[Lo]-$This[Lo]));


#    #Haversine Formula (from R.W. Sinnott, "Virtues of the Haversine", 
#    #Sky and Telescope, vol. 68, no. 2, 1984, p. 159): 
#
#    $dlon = $That[Lo] - $This[Lo];
#    $dlat = $That[La] - $This[La];
#
#    $sinDlat2 = sin($dlat/2);
#    $sinDlon2 = sin($dlon/2);
#    $a = ($sinDlat2 * $sinDlat2 +
#          cos($This[La]) * cos($That[La]) * $sinDlon2 * $sinDlon2);
#
#    # The Haversine Formula can be expressed in terms of a two-argument 
#    # inverse tangent function, atan2(y,x), instead of an inverse sine 
#    # as follows (no bulletproofing is needed for an inverse tangent): 
#
#    $ca = 2.0 * atan2( sqrt($a) , sqrt(1.0 - $a) );


    
$lat1 $This[La];
    
$lat2 $That[La];

    
# Calculate angles along great ellipse from equator
    
if ($lat1 $lat2) {
       
$t $lat2;  $lat2 $lat1;  $lat1 $t;
    }

    
$si sin($lat1) * sin($ca);
    
$co sin($lat2) - sin($lat1) * cos($ca);
    
$a1 atan2($si$co);
    
$a2 $a1 $ca;

    
# Calculate ellipticity (squared) of great circle */

    
$th sin($lat2) / sin($a2);
    
$ep gm4anb_e $th $th;

    
# Calculate great circle distance from equator for each */
    
$l1 gm4anb_a * ($a1 $ep $a1 4.0 $ep sin(2.0 $a1) / 8.0);
    
$l2 gm4anb_a * ($a2 $ep $a2 4.0 $ep sin(2.0 $a2) / 8.0);

    
$R[s] = ($l2 $l1) * 0.001# Station distance is difference

    
return($R);
}


function 
printbearingdistance($R$POINT$Az0) {

    global 
$LANG;

    
printf(" %s "$POINT);

    
langfilt('FI:Etäisyys
EN:Distance'
);

    if (
$R[dist] >= 10000.0)
        
printf(" = %3.3f km"$R[dist]/1000.0 );
    else
        
printf(" = %4.3f m",   $R[dist] );

    
printf("  Az %3.3f°",   rad2deg($R[Az]));

    if (
$Az0 0.0)
        
printf(" RevAz %3.3f°"rad2deg($R[rAz]));
    else {
        
$dK $R[Az] - $Az0;
        if (
$dK >  M_PI$dK -= M_PI M_PI;
        if (
$dK < -M_PI$dK += M_PI M_PI;
        if (
$LANG == "fi")
            
printf(" dK   %4.3f°"rad2deg($dK));
        else
            
printf(" dM   %4.3f°"rad2deg($dK));
    }
    
printf("\n");

}


function 
bearingdistanceMH($MyWGS1$ThatWGS1$MyWGS2$ThatWGS2) {

    
langfilt('**:
FI:MH: Etäisyys Maidenhead laskentasäännöillä:
EN:MH: Distance with Maidenhead computing rules:

FI:R1: Etäisyys Region-1/GM4ANB:n ennätyslaskentasäännöillä:
EN:R1: Distance with Region-1/GM4ANB\'s distance record computing rules:

'
);

    if (
$MyWGS1[MH] != "" && $ThatWGS1[MH] != "") {
        
printf("  %-10s -&gt; %-10s"$MyWGS1[MH], $ThatWGS1[MH]);

    
$R maidenhead_km_distance($MyWGS1,$ThatWGS1);
    
printf(" MH Distance: %4.3f km\n"$R[s]);
    
$RR[0] = $R[s];

    
$R gm4anb_km_distance($MyWGS1,$ThatWGS1);
        
printf("  %-10s -&gt; %-10s"$MyWGS1[MH], $ThatWGS1[MH]);
    
printf(" R1 Distance: %4.3f km\n"$R[s]);

    }

    if (
$MyWGS2[MH] != "" && $ThatWGS2[MH] != "") {
        
printf("  %-10s -&gt; %-10s"$MyWGS2[MH], $ThatWGS2[MH]);

    
$R maidenhead_km_distance($MyWGS2,$ThatWGS2);
    
printf(" MH Distance: %4.3f km\n"$R[s]);
    
$RR[1] = $R[s];

    
$R gm4anb_km_distance($MyWGS2,$ThatWGS2);
        
printf("  %-10s -&gt; %-10s"$MyWGS2[MH], $ThatWGS2[MH]);
    
printf(" R1 Distance: %4.3f km\n"$R[s]);
    }

    return(
$RR);
}


function 
bearingdistance($MyWGS$ThatWGS$MHdist) {

    global 
$LANG;

    
# GRS80 ellipsoid:
    
$EL[a] = 6378137.0;
    
$EL[f] = 1.0/298.25722210088;

    
$ELw[a] = 6378137.0;
    
$ELw[f] = 1.0/298.257223563;
    
#    a.k.a. "WGS84"

    
$ELh[a] = 6378388.0;        # Hayford ellipsoid
    
$ELh[f] = 1/297.0;

    
$ELs[a] = 6378388.0;        # "ball"
    
$ELs[f] = 0;


    if (
$MyWGS[MH] != $ThatWGS[MH]) {
        
$R    ellipsoidal_great_circle($MyWGS$ThatWGS$EL);
        
# $Rw = ellipsoidal_great_circle($MyWGS, $ThatWGS, $ELw);
        # $Rh = ellipsoidal_great_circle($MyWGS, $ThatWGS, $ELh);
        # $Rs = ellipsoidal_great_circle($MyWGS, $ThatWGS, $ELs);
    
}


    if (
$MyWGS[MH] != "" && $ThatWGS[MH] != "") {
        
printf("\n%s -&gt; %s\n"$MyWGS[MH], $ThatWGS[MH]);
    }

    if (
$LANG == "fi") {
        
printf("<I><FONT SIZE=1>Globaali GSR80  ellipsoidi (~ WGS84):</FONT></I>\n");
        
printbearingdistance($R,  "K ", -1);
        
# printbearingdistance($Rw, "Kw", -1);
        # printf("<I><FONT SIZE=1>Hayford ellipsoidilla ja pallolla laskien:</FONT></I>\n");
        # printbearingdistance($Rh, "Kh", -1);
        # printbearingdistance($Rs, "Kp", -1);
    
} else {
        
printf("<I><FONT SIZE=1>GSR80 global ellipsoid (~ WGS84):</FONT></I>\n");
        
printbearingdistance($R,  "M ", -1);
        
# printbearingdistance($Rw, "Mw", -1);
        # printf("<I><FONT SIZE=1>Computing at Hayford ellipsoid and at sphere:</FONT></I>\n");
        # printbearingdistance($Rh, "Mh", -1);
        # printbearingdistance($Rs, "Ms", -1);
    
}

    if (
$ThatWGS[dLo]) {

        
$Wsw[La] = $ThatWGS[La] - $ThatWGS[dLa];
        
$Wsw[Lo] = $ThatWGS[Lo] - $ThatWGS[dLo];

        
$Wse[La] = $ThatWGS[La] - $ThatWGS[dLa];
        
$Wse[Lo] = $ThatWGS[Lo] + $ThatWGS[dLo];

        
$Wne[La] = $ThatWGS[La] + $ThatWGS[dLa];
        
$Wne[Lo] = $ThatWGS[Lo] + $ThatWGS[dLo];

        
$Wnw[La] = $ThatWGS[La] + $ThatWGS[dLa];
        
$Wnw[Lo] = $ThatWGS[Lo] - $ThatWGS[dLo];

        
$Rsw ellipsoidal_great_circle($MyWGS$Wsw$EL);
        
$Rse ellipsoidal_great_circle($MyWGS$Wse$EL);
        
$Rne ellipsoidal_great_circle($MyWGS$Wne$EL);
        
$Rnw ellipsoidal_great_circle($MyWGS$Wnw$EL);

        
# $Rsw[Az] -= $R[Az];
        # $Rse[Az] -= $R[Az];
        # $Rne[Az] -= $R[Az];
        # $Rnw[Az] -= $R[Az];

        
if ($LANG == "fi")
            
printf("<I><FONT SIZE=1>Ruudun nurkkapisteisiin:</FONT></I>\n");
        else
            
printf("<I><FONT SIZE=1>Square corner points:</FONT></I>\n");

        
printbearingdistance($Rsw"SW"$R[Az]);
        
printbearingdistance($Rse"SE"$R[Az]);
        
printbearingdistance($Rne"NE"$R[Az]);
        
printbearingdistance($Rnw"NW"$R[Az]);
    }
}



#
# Converts WGS84 Lat/Long/Alt pair into geocentric GSR80  X/Y/Z coordinates
#
# Inputs:
#   $lat    =  Latitude, Radians
#   $long   =  Longitude, Radians
#   $alt    =  Altitude, meters relative to GSR80 geoid
#
# Outputs:
#   $R[X]   =  Geocentric X coordinate, meters
#   $R[Y]   =  Geocentric Y coordinate, meters
#   $R[Z]   =  Geocentric Z coordinate, meters
#


function latlong2xyz($lat,$long,$alt) {
    
$a 6378137.0;
    
$b 6356752.0;

    
$aa $a $a;
    
$bb $b $b;
    
$coslat cos($lat);
    
$sinlat sin($lat);

    
$N $aa sqrt($aa $coslat $coslat $bb $sinlat $sinlat);

    
$R[X] = ($N $alt) * $coslat cos($long);
    
$R[Y] = ($N $alt) * $coslat sin($long);
    
$R[Z] = ($bb/$aa $N $alt) * $sinlat;

    return (
$R);
}


#
# Distance in between two XYZ coordinates
#
# Inputs:  $This[X]  Geocentric X coordinate
#          $This[Y]  Geocentric Y coordinate
#          $This[Z]  Geocentric Z coordinate
#          $That[X]  Geocentric X coordinate
#          $That[Y]  Geocentric Y coordinate
#          $That[Z]  Geocentric Z coordinate
#
# Outputs: $R[s]      Direct line distance, same units as inputs
#

function xyzdistance($This$That) {
    
$dX $That[X] - $This[X];
    
$dY $That[Y] - $This[Y];
    
$dZ $That[Z] - $This[Z];

    
$R[dX] = $dX;
    
$R[dY] = $dY;
    
$R[dZ] = $dZ;

    
$R[s] = sqrt$dX $dX $dY $dY $dZ $dZ );

    return (
$R);
}


########  TEST STUFF ########

function KKJ_LaLo_test($la1,$la2,$la3,
                       
$lo1,$lo2,$lo3,$P0,$I0) {
    
    
$WGS[La]  = deg2rad(dms2deg($la1,$la2,$la3));
    
$WGS[Lo]  = deg2rad(dms2deg($lo1,$lo2,$lo3));
    
    
printf("\nTEST CASE:  %s  %s\n",
           
fmtdms($WGS[La],1), fmtdms($WGS[Lo],0));
    
    global 
$Long0;
    global 
$ZoneNumber;
    
    
$ED5w WGSLaLo_to_WGSxy($WGS$ZoneNumber$Long0);
    
$KKJ  WGSxy_to_KKJ($ED5w);
    
#         $ED5w = KKJLaLo_to_KKJxy($WGS,$Long0);
#         $KKJ  = ED50xy_to_KKJ($ED5w);
    
    
printf("   ED50w   P = %8.1f    I = %8.1f\n",
           
$ED5w[X], $ED5w[Y]);
    
printf("   KKJ     P = %8.1f    I = %8.1f\n",
           
$KKJ[X],  $KKJ[Y]);
    
    
printf("Should be: P =  %.3f  I =  %.3f\n",
           
$P0,$I0);
    
printf("          dP = %8.3f dI = %8.3f\n",
           
$KKJ[X]-$P0,$KKJ[Y]-$I0);
    
}

if (
$DoTest) {

    echo(
"<PRE>\n\n");
    echo(
"  Testing the algorithms:\n");
    
printf("TEST CASE:  N  60°44'25.5072\"".
           
"  E 26°10'35.6438\"\n");


    
$ED50[La] = deg2rad(dms2deg60,44,25.5072));
    
$ED50[Lo] = deg2rad(dms2deg26,10,35.6438));
    
$WGS[La]  = deg2rad(dms2deg60,44,26.6   ));
    
$WGS[Lo]  = deg2rad(dms2deg26,10,24.2   ));

    
printf("  fmt:      %s  %s\n",
           
fmtdms($ED50[La],1), fmtdms($ED50[Lo],0));
    
printf("  fmt:      %s  %s\n",
           
fmtdms($WGS[La],1),  fmtdms($WGS[Lo],0));

    
$ED5  KKJLaLo_to_KKJxy($ED50$ZoneNumber$Long0);
    
$ED5w WGSLaLo_to_WGSxy($WGS,  $ZoneNumber$Long0);
    
$KKJ  ED50xy_to_KKJ($ED5);

    
printf("   WGSxy   P = %8.1f    I = %8.1f\n",
           
$ED5w[X], $ED5w[Y]);
    
printf("   KKJ     P = %8.1f    I = %8.1f\n",
           
$KKJ[X],  $KKJ[Y]);
    
printf("   ED50xy  P = %8.1f    I = %8.1f\n",
           
$ED5[X],  $ED5[Y]);
    
$P0 6737009.924$I0 3455081.597;
    
printf("Should be: P =  %.3f  I =  %.3f\n",
           
$P0,$I0);
    
printf("          dP = %8.3f dI = %8.3f\n",
           
$ED5[X]-$P0,$ED5[Y]-$I0);


    
KKJ_LaLo_test(63,464.707127,38,30.58307074280.4053531837.668);
    
KKJ_LaLo_test(60,132.876024,23,40.18806681284.0223355761.859);

    
KKJ_LaLo_test(6000.00012000.00006674883.03,  3110054.63 );
    
KKJ_LaLo_test(6000.00012700.00006654203.70,  3500168.98 );
    
KKJ_LaLo_test(6000.00013200.00006664747.91,  3778993.05 );


    
KKJ_LaLo_test(7000.00012000.00007784451.51,  3233376.02 );
    
KKJ_LaLo_test(7000.00012700.00007769113.61,  3500171.81 );
    
KKJ_LaLo_test(7000.00013200.00007776941.00,  3690918.66 );

    echo(
"\n</PRE>\n");

    
printf("</TD></TR></TABLE><P><HR><P>Matti Aarnio" .
         
" - OH2MQK &lt;matti.aarnio&#64;zmailer.org&gt;\n");
    include(
"../include/base.inc");
    include(
"../include/foot.inc"); 
    exit;
}                               
# end of '$DoTest'

?>


<P>

<HR><A NAME="QTH-MH"></A>
<?php intlinks(); ?>
<P>
<FORM ACTION="mhbearing.php#QTH-MH" METHOD=POST>
<?php langfilt('FI:
FI: <H3>Tarkka Maidenhead koordinaatti QTH:llesi:</H3>
FI: Käytä <A HREF="kkj-wgs84.php">KKJ/WGS/MH</A> työkalua tämän määrittämiseen.
FI:<P>
FI: Lyhyille matkoille ja äärimmäisen teräville mikroaaltokeiloille
FI: tarvitaan tarkemmat (10-12 merkkiä) MH koodit, kuin pitkille matkoille.
FI: VHF:llä ja muutamaa kymmenentä kilometriä pidemmät matkat toimii vallan
FI: hyvin 6 merkillä. HF:llä parin suur-ruudun päähän riittää 4 merkkiä
FI: kyllin tarkan suunnan saamiseksi jopa suunta-antenneille.
FI: (16-18 merkin koodit ovat puhtaasti käytetyn matematiikan tarkistuksiin
FI:  -- maanmittauksen keinoilla.)
FI:<P>
FI: Oma QTH sijaintisi pitäisi joka tapauksessa merkitä tähän mahdollisimman
FI: tarkkaan, ainakin 20 metrin (10 merkin) tarkkuudella.
EN: <H3>High-resolution Maidenhead coordinate for your QTH:</H3>
EN: Use <A HREF="kkj-wgs84.php">KKJ/WGS/MH</A> tool to find this out.
EN:<P>
EN: Short distances and extremely narrow microwave beam-widths need
EN: longer MH codes (10-12 chars) than long distances.
EN: At VHF and for over few tens of kilometers the 6 character code
EN: works just fine. For HF and for couple major squares distance, 4 characters
EN: are enough for the bearing for the best directional antennas.
EN: (The 16-18 character codes are purely for verifying the used mathematics
EN:  -- with geodetics, of course.)
EN:<P>
EN: Your own QTH should, still, be entered here as accurately as you
EN: know it. Preferrably at least 20 meters (10 chars) resolution.
<P>
FI: <I>Maailmanlaajuinen ruudukko.</I><P>
FI:<A HREF="maidenheadfuncs.php?source=1">[A-R][A-R][0-9][0-9][A-X][A-X][0-9][0-9][A-X][A-X]...<BR>
FI:<I>([Pit][Lev][Pit][Lev][Pit][Lev]...)</I></A>
EN: <I>Global scope grid.</I><P>
EN:<A HREF="maidenheadfuncs.php?source=1">[A-R][A-R][0-9][0-9][A-X][A-X][0-9][0-9][A-X][A-X]...<BR>
EN:<I>([Lon][Lat][Lon][Lat][Lon][Lat]...)</I></A>
**:    <I>&nbsp;&nbsp;
FI:Esimerkkejä
EN:Examples
**: 
"KP30" / "KP30CR" / "KP30CR56" / "KP30CR56HF"</I>
<P>

&nbsp;&nbsp; Maidenhead:
  <INPUT TYPE="text" NAME="QTH-MH" SIZE=18
         VALUE="'
.$QTHMH.'">
<P>


FI: <H3>Vasta-aseman Maidenhead ruutukoodi:</H3>
EN: <H3>Remote station Maidenhead grid code:</H3>
**:&nbsp;&nbsp;
Maidenhead:

  <INPUT TYPE="text" NAME="WGSMH" SIZE=18
         VALUE="'
.$WGSMH.'");
<P>
<!--  &nbsp;&nbsp;&nbsp;&nbsp;MH code: <?php  form_mh_digits($MHDIGITS); ?> -->
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  Debug:
'
); ?>
  <INPUT TYPE="checkbox" NAME="Debug"<?php if($Debug)echo(" CHECKED"); ?>>
<BR>
<INPUT TYPE="submit" NAME="DO-MH" VALUE="<?php
if($LANG == "fi") {echo ("Laske MH-MH etäisyyksiä");
}else{echo(
"Calculate MH-MH distances");} ?>">
</FORM>
<P>



<?php

    
# Input mode:  MAIDENHEAD

    
if ($DoMaidenhead) {

    
$QTHMH strtoupper($QTHMH);

    
$WGSQTH  parsemaidenhead($QTHMH);
    
$WGSQTH4 parsemaidenhead(substr($QTHMH,0,4));
    
$WGSQTH6 parsemaidenhead(substr($QTHMH,0,6));

    if (
$WGSQTH[La] && $WGSQTH[Lo] && $WGSQTH[dLa] && $WGSQTH[dLo]) {

        
langfilt('FI:
FI:Lähtö QTH Ruudun keskikohta:
EN:Origination QTH Grid square center:'
);

        echo(
"<PRE>\n");

        
printf("  WGS84:  %s  %s\n",
           
fmtdms($WGSQTH[La],1), fmtdms($WGSQTH[Lo],0));
        
printf("  WGS84:  %s  %s\n",
           
fmtdmm($WGSQTH[La],1), fmtdmm($WGSQTH[Lo],0));
        
printf("  WGS84:  %s  %s\n",
           
fmtddd($WGSQTH[La],1), fmtddd($WGSQTH[Lo],0));


        
$ThisXYZ latlong2xyz($WGSQTH[La],$WGSQTH[Lo],0.0);

        
printf("  WGS84: X: %9.3fm\n"$ThisXYZ[X]);
        
printf("         Y: %9.3fm\n"$ThisXYZ[Y]);
        
printf("         Z: %9.3fm\n"$ThisXYZ[Z]);

        echo(
"</PRE>\n");

        
langfilt('FI:
FI:Lähtö QTH Ruudun puolikorkeus/puolileveys:
EN:Origination QTH Grid square half-height/half-width:'
);

        echo(
"<PRE>\n");

        
printf("  Delta:  %s  %s\n",
           
fmtdms($WGSQTH[dLa],1), fmtdms($WGSQTH[dLo],0));
        
printf("  Delta:  %s  %s\n",
           
fmtdmm($WGSQTH[dLa],1), fmtdmm($WGSQTH[dLo],0));
        
printf("  Delta:  %s  %s\n",
           
fmtddd($WGSQTH[dLa],1), fmtddd($WGSQTH[dLo],0));

        echo(
"\n");

        
$KKJtest[La] = $WGSQTH[La];
        
$KKJtest[Lo] = deg2rad(27.0);
        
$KKJ3 KKJLaLo_to_KKJxy($KKJtest3deg2rad(27.0));
        
$KKJtestP[La] = $KKJtest[La] + $WGSQTH[dLa];
        
$KKJtestP[Lo] = $KKJtest[Lo];
        
$KKJtest3 KKJLaLo_to_KKJxy($KKJtest3deg2rad(27.0));
        
$KKJtestI[La] = $KKJtest[La];
        
$KKJtestI[Lo] = $KKJtest[Lo] + $WGSQTH[dLo];
        
$KKJtest3P KKJLaLo_to_KKJxy($KKJtestP3deg2rad(27.0));
        
$KKJtest3I KKJLaLo_to_KKJxy($KKJtestI3deg2rad(27.0));

        
printmhdimensions($KKJtest3P[X] - $KKJ3[X],
                  
$KKJtest3I[Y] - $KKJ3[Y]);

        if (
$LANG == "fi")
        
printf("<P ALIGN=CENTER><IMG SRC=\"mh-ruutu.gif\"></P>\n");
        else
        
printf("<P ALIGN=CENTER><IMG SRC=\"mh-square.gif\"></P>\n");

        echo(
"</PRE>\n");

    } else {
        echo(
"  ** INVALID QTH-MH INPUT ??? **\n\n");
    }



        echo(
"<HR WIDTH=\"49%\" ALIGN=CENTER>");

        echo(
"MAIDENHEAD -&gt; WGS84 / KKJ\n");
        echo(
"<PRE>\n\n");

        if (
$LANG == "fi")
            
printf("Syöte: '%s'\n\n"$WGSMH);
        else
            
printf("Input: '%s'\n\n"$WGSMH);

        
$MH  parsemaidenhead($WGSMH);
        
$MH4 parsemaidenhead(substr($WGSMH,0,4));
        
$MH6 parsemaidenhead(substr($WGSMH,0,6));

        if (
$MH[La] && $MH[Lo] && $MH[dLa] && $MH[dLo]) {


        
langfilt('FI:
FI:Kohde QTH Ruudun keskikohta:
EN:Destination QTH Grid square midpoint:'
);
            echo(
"\n");

            
printf("  WGS84:  %s  %s\n",
                   
fmtdms($MH[La],1), fmtdms($MH[Lo],0));
            
printf("  WGS84:  %s  %s\n",
                   
fmtdmm($MH[La],1), fmtdmm($MH[Lo],0));
            
printf("  WGS84:  %s  %s\n",
                   
fmtddd($MH[La],1), fmtddd($MH[Lo],0));

        
$ThatXYZ latlong2xyz($MH[La],$MH[Lo],0.0);

        
printf("  WGS84: X: %9.3fm\n"$ThatXYZ[X]);
        
printf("         Y: %9.3fm\n"$ThatXYZ[Y]);
        
printf("         Z: %9.3fm\n"$ThatXYZ[Z]);

        
$XYZdist xyzdistance($ThisXYZ$ThatXYZ);

        
printf("         XYZdistance = %9.3fm\n"$XYZdist[s]);
        
printf("                  dX = %9.3fm\n"$XYZdist[dX]);
        
printf("                  dY = %9.3fm\n"$XYZdist[dY]);
        
printf("                  dZ = %9.3fm\n"$XYZdist[dZ]);

            echo(
"\n");

        
langfilt('FI:
FI:Kohde QTH Ruudun puolikorkeus/puolileveys:
EN:Destination QTH Grid square half-height/half-width:'
);
            echo(
"\n");

            
printf("  Delta:  %s  %s\n",
                   
fmtdms($MH[dLa],1), fmtdms($MH[dLo],0));
            
printf("  Delta:  %s  %s\n",
                   
fmtdmm($MH[dLa],1), fmtdmm($MH[dLo],0));
            
printf("  Delta:  %s  %s\n",
                   
fmtddd($MH[dLa],1), fmtddd($MH[dLo],0));

            echo(
"\n");

            
$KKJtest[La] = $MH[La];
            
$KKJtest[Lo] = deg2rad(27.0);
            
$KKJ3 KKJLaLo_to_KKJxy($KKJtest3deg2rad(27.0));
            
$KKJtestP[La] = $KKJtest[La] + $MH[dLa];
            
$KKJtestP[Lo] = $KKJtest[Lo];
            
$KKJtest3 KKJLaLo_to_KKJxy($KKJtest3deg2rad(27.0));
            
$KKJtestI[La] = $KKJtest[La];
            
$KKJtestI[Lo] = $KKJtest[Lo] + $MH[dLo];
            
$KKJtest3P KKJLaLo_to_KKJxy($KKJtestP3deg2rad(27.0));
            
$KKJtest3I KKJLaLo_to_KKJxy($KKJtestI3deg2rad(27.0));

            
printmhdimensions($KKJtest3P[X] - $KKJ3[X],
                              
$KKJtest3I[Y] - $KKJ3[Y]);

        
langfilt('FI:
FI:<P ALIGN=CENTER><IMG SRC=mh-ruutu.gif></P>
EN:<P ALIGN=CENTER><IMG SRC=mh-square.gif></P>'
);

            echo(
"\n");

            
mh_edge_distance($MH$WGSMH); # WARNING!
        # DIFFERENT TO ALL OTHER INSTANCES!

            
echo("</PRE>\n");

            
langfilt("FI:
FI: Kilpailujen säännöt sanovat, että kilpailuissa
FI: etäisyydet lasketaan oleskeluruudun keskipisteestä
FI: kohderuudun keskipisteeseen <B>pallofunktioilla</B>
FI: ja että etäisyys <I>asteina</I> muunnetaan
FI: kilometreiksi käyttäen kerrointa ``111.2''
FI: Lillehammerin kokouksen -99 päätöksen mukaan ruudun
FI: sisäiset yhteydet saavat 1km.
FI: Etäisyysvirhe suhteessa geodeettiseen laskentaan
FI: on helposti havaittava.
EN: Radio-amateur competition rules say that
EN: distances are to be calculated from the mid-point
EN: of the QTH locator grid square to destination's
EN: similarly derived locator square mid-point.
EN: This distance is calculated with <I>spherical
EN: functions</I> with classical cosine equation
EN: (or with Haversine variant of it), and the distance
EN: in <I>degrees</I> is then multiplied with ``111.2''
EN: to get kilometers.
EN: Per Lillehammer -99 meeting, contacts within a square
EN: will be scored at 1km.
EN: The error in distances is observable, although not
EN: excessively large."
);

            echo(
"<PRE>\n");

        
$RR bearingdistanceMH($WGSQTH4$MH4$WGSQTH6$MH6);

            
bearingdistance($WGSQTH,  $MH,  -);
            
bearingdistance($WGSQTH,  $MH4, -1);
            
bearingdistance($WGSQTH4$MH4$RR[0]);
            
bearingdistance($WGSQTH,  $MH6, -1);
            
bearingdistance($WGSQTH6$MH6$RR[1]);

            echo(
"\n");

        } else {
            echo(
"  ** INVALID DESTINATION MH INPUT ??? **\n\n");
        }

        echo(
"</PRE>\n");
    }

## } # end of if(!$DoTest) ...
## if (! $DoTest) {

?>

<P>
<HR>
<P>

<?php require("selitykset.php"); ?>

<P>
<HR>
<P>

<?php langfilt('

FI:<H3>Tämä työkalu koostuu useista lähdekoodimoduleista:</H3>
EN:<H3>This tool consists of following source components:</H3>
<UL>
FI: <LI><A HREF="mhbearing.php?source=1">mhbearing.php</A>:
FI:        Pääkoodi
EN: <LI><A HREF="mhbearing.php?source=1">mhbearing.php</A>:
EN:        The main code itself

FI: <LI><A HREF="kkj-funcs.php?source=1">kkj-funcs.php</A>:
FI:        Koordinaatistokäsittelyä, yms. yhteisiä juttuja
EN: <LI><A HREF="kkj-funcs.php?source=1">kkj-funcs.php</A>:
EN:        Common stuff, coordinate transformations, HTML things, etc.

FI: <LI><A HREF="maidenheadfuncs.php?source=1">maidenheadfuncs.php</A>:
FI:        Maidenhead hilan käsittelyä
EN: <LI><A HREF="maidenheadfuncs.php?source=1">maidenheadfuncs.php</A>:
EN:        Maidenhead grid coordinate processing

FI: <LI><A HREF="geodinver.php?source=1">geodinver.php</A>:
FI:        Geodeettisen käänteistehtävän matematiikka (Haetaan
FI:        etäisyys ja atsimuutit kahdelle annetulle pisteelle
FI:        ellipsoidilla.)
EN: <LI><A HREF="geodinver.php?source=1">geodinver.php</A>:
EN:        Mathematics for the "geodetic inverse" problem.
EN:        (Finding distance and Azimuth between two points
EN:         on an ellipsoid.)

FI: <LI><A HREF="selitykset.php?source=1">selitykset.php</A>:
FI:        Yllä näkyvät selitystekstit.
EN: <LI><A HREF="selitykset.php?source=1">selitykset.php</A>:
EN:        Explanations seen above...

</UL>
<P>
<HR>
<P>
'
);

require(
"../include/sign-oh2mqk.inc");

printf("<P></TD></TR></TABLE>\n");

require(
"../include/base.inc");
require(
"../include/foot.inc");

?>


Matti Aarnio - OH2MQK <matti.aarnio@zmailer.org>

 

Valid HTML 4.01!   Z Elisa Communications
This page is Links enhanced for additional browsing pleasure.