<!doctype html>
<html>
<head>
<title>Missing Two - RJM Programming - December, 2018 ... Thanks to https://www.igismap.com/formula-to-find-bearing-or-heading-angle-between-two-points-latitude-longitude/</title>
<script type='text/javascript'>

var eles=['latf','longf','brg','dist','latt','longt'];
var cwhat=[false,false,false,false,true,true];
var decided=false;

function great_circle_distance(talis, gnolis, latis, longis) {
var ourdist=0.0;
var rgnol=eval((gnolis) * Math.PI / 180.0);
var rtal=eval((talis) * Math.PI / 180.0);
var rlong=eval((longis) * Math.PI / 180.0);
var rlat=eval((latis) * Math.PI / 180.0);
var deltalong = Math.abs(eval(((gnolis)-(longis)) * Math.PI / 180.0));
var acof = eval(Math.sin(rtal) * Math.sin(rlat)) + (Math.cos(rtal) * Math.cos(rlat) * Math.cos(deltalong)); // via http://en.wikipedia.org/wiki/Great-circle_distance ... thanks
ourdist = eval(Math.round((Math.acos(acof) * 6371000.0) + 0.00001) * 100) / 100;
return ourdist;
}

function nextplease() {
var i;


for (i=0; i<eles.length; i++) {
document.getElementById(eles[i]).value='0.0000000';
document.getElementById(eles[i]).style.backgroundColor='white';
}
eles=['latf','longf','brg','dist','latt','longt'];
cwhat=[false,false,false,false,true,true];
decided=false;
}

function calcit() {
var i, ourbrg=0.0, ourdist=0.0, j;
if (!cwhat[0] && !cwhat[1] && !cwhat[2] && !cwhat[3] && !cwhat[4] && !cwhat[5]) {
if (Math.abs(eval('' + document.getElementById(eles[4]).value)) < 0.00000004 && Math.abs(eval('' + document.getElementById(eles[5]).value)) < 0.00000004) {
cwhat[4]=true;
cwhat[5]=true;
} else if (Math.abs(eval('' + document.getElementById(eles[2]).value)) < 0.00000004 && Math.abs(eval('' + document.getElementById(eles[3]).value)) < 0.00000004) {
cwhat[2]=true;
cwhat[3]=true;
}
}
//alert(('' + cwhat[0]) + ('' + cwhat[1]) + ('' + cwhat[2]) + ('' + cwhat[3]) + ('' + cwhat[4]) + ('' + cwhat[5]));
if (cwhat[0] && cwhat[1] || (!cwhat[0] && !cwhat[1] && !cwhat[2] && !cwhat[3] && !cwhat[4] && !cwhat[5])) {
if (('' + document.getElementById('mysel').value) == '1') {
ourbrg=eval(eval(540.0 + eval('' + document.getElementById(eles[2]).value)) % 360.0);
} else {
ourbrg=eval('' + document.getElementById(eles[2]).value);
}
for (j=eval(('' + document.getElementById('mysel').value)); j>=1; j--) {
ourdist=eval('' + document.getElementById(eles[3]).value);

document.getElementById(eles[0]).value='' +
eval(eval(eval(180.0 / Math.PI) * Math.asin(
eval(eval('' + Math.sin(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[4]).value))) *
eval('' + Math.cos(eval(eval('' + ourdist) / 6371000.0)))) +
eval(eval('' + Math.cos(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[4]).value))) *
eval('' + Math.sin(eval(eval('' + ourdist) / 6371000.0))) *
eval('' + Math.cos(eval(Math.PI / 180.0) * eval('' + ourbrg)))))));

document.getElementById(eles[1]).value=eval(eval(180.0 / Math.PI) * eval(eval(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[5]).value)) +
Math.atan2(
eval(eval('' + Math.sin(eval(Math.PI / 180.0) * eval('' + ourbrg)) *
eval('' + Math.sin(eval(eval('' + ourdist) / 6371000.0)))) *
eval('' + Math.cos(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[4]).value)))),
eval(eval('' + Math.cos(eval(eval('' + ourdist) / 6371000.0))) -
eval(eval('' + Math.sin(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[4]).value)))) *
eval('' + Math.sin(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[0]).value)))))));

if (document.getElementById(eles[0]).value.indexOf('e-') != -1) { document.getElementById(eles[0]).value='0.0000000'; }
if (document.getElementById(eles[1]).value.indexOf('e-') != -1) { document.getElementById(eles[1]).value='0.0000000'; }

if (j != 1) {
ourbrg=eval(eval(360.0 + eval(eval(eval(180.0 / Math.PI) * Math.atan2(
eval(eval('' + Math.cos(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[4]).value))) *
eval('' + Math.sin(eval(Math.PI / 180.0) * eval(eval('' + document.getElementById(eles[5]).value) - eval('' + document.getElementById(eles[1]).value))))),
eval(eval('' + Math.cos(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[0]).value))) *
eval('' + Math.sin(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[4]).value)))) -
eval(eval('' + Math.sin(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[0]).value))) *
eval('' + Math.cos(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[4]).value))) *
eval('' + Math.cos(eval(Math.PI / 180.0) * eval(eval('' + document.getElementById(eles[5]).value) - eval('' + document.getElementById(eles[1]).value)))))
)))) % 360.0);
//ourbrg=eval(eval(540.0 + eval('' + document.getElementById(eles[2]).value)) % 360.0);
document.getElementById(eles[2]).value='' + ourbrg;
document.getElementById('mysel').value='1';
//alert(ourbrg);
}


}

document.getElementById(eles[0]).style.backgroundColor='lightgreen';
document.getElementById(eles[1]).style.backgroundColor='lightgreen';
document.getElementById('goagain').style.display='block'; // setTimeout(nextplease,10000);

} else if (cwhat[2] && cwhat[3]) {

ourdist=great_circle_distance(document.getElementById(eles[0]).value,document.getElementById(eles[1]).value,document.getElementById(eles[4]).value,document.getElementById(eles[5]).value);
document.getElementById(eles[3]).value='' + ourdist;


//Let ‘R’ be the radius of Earth,
//‘L’ be the longitude,
//‘θ’ be latitude,
//‘β‘ be Bearing.

//Bearing from point A to B, can be calculated as,

//β = atan2(X,Y),

//where, X and Y are two quantities and can be calculated as:

//X = cos θb * sin ∆L

//Y = cos θa * sin θb – sin θa * cos θb * cos ∆L

ourbrg=eval(eval(360.0 + eval(eval(eval(180.0 / Math.PI) * Math.atan2(
eval(eval('' + Math.cos(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[4]).value))) *
eval('' + Math.sin(eval(Math.PI / 180.0) * eval(eval('' + document.getElementById(eles[5]).value) - eval('' + document.getElementById(eles[1]).value))))),
eval(eval('' + Math.cos(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[0]).value))) *
eval('' + Math.sin(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[4]).value)))) -
eval(eval('' + Math.sin(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[0]).value))) *
eval('' + Math.cos(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[4]).value))) *
eval('' + Math.cos(eval(Math.PI / 180.0) * eval(eval('' + document.getElementById(eles[5]).value) - eval('' + document.getElementById(eles[1]).value)))))
)))) % 360.0);

document.getElementById('mysel').value='2';
document.getElementById(eles[2]).value='' + ourbrg;
document.getElementById(eles[2]).style.backgroundColor='lightgreen';
document.getElementById(eles[3]).style.backgroundColor='lightgreen';
document.getElementById('goagain').style.display='block'; // setTimeout(nextplease,10000);

} else if (cwhat[4] && cwhat[5]) {
if (('' + document.getElementById('mysel').value) == '2') {
ourbrg=eval(eval(540.0 + eval('' + document.getElementById(eles[2]).value)) % 360.0);
} else {
ourbrg=eval('' + document.getElementById(eles[2]).value);
}
for (j=eval(3 - eval(('' + document.getElementById('mysel').value))); j>=1; j--) {
ourdist=eval('' + document.getElementById(eles[3]).value);


//Let first point latitude be la1,
///longitude as lo1,
//d be distance,
//R as radius of Earth,
//Ad be the angular distance i.e d/R and
//θ be the bearing,

//Here is the formula to find the second point, when first point, bearing and distance is known:

//latitude of second point = la2 = asin(sin la1 * cos Ad + cos la1 * sin Ad * cos θ), and
//longitude of second point = lo2 = lo1 + atan2(sin θ * sin Ad * cos la1 , cos Ad – sin la1 * sin la2)

document.getElementById(eles[4]).value='' +
eval(eval(eval(180.0 / Math.PI) * Math.asin(
Math.sin(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[0]).value)) *
Math.cos(eval(eval('' + ourdist) / 6371000.0)) +
Math.cos(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[0]).value)) *
Math.sin(eval(eval('' + ourdist) / 6371000.0)) *
Math.cos(eval(Math.PI / 180.0) * eval('' + ourbrg)))));

//Let first point latitude be la1,
//longitude as lo1,
//d be distance,
//R as radius of Earth,
//Ad be the angular distance i.e d/R and
//θ be the bearing,
// longitude of second point = lo2 = lo1 + atan2(sin θ * sin Ad * cos la1 , cos Ad – sin la1 * sin la2)

document.getElementById(eles[5]).value=eval(eval(180.0 / Math.PI) * eval(eval(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[1]).value)) +
Math.atan2(
eval(eval('' + Math.sin(eval(Math.PI / 180.0) * eval('' + ourbrg)) *
eval('' + Math.sin(eval(eval('' + ourdist) / 6371000.0)))) *
eval('' + Math.cos(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[0]).value)))),
eval(eval('' + Math.cos(eval(eval('' + ourdist) / 6371000.0))) -
eval(eval('' + Math.sin(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[0]).value)))) *
eval('' + Math.sin(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[4]).value)))))));


if (j != 1) {
ourbrg=eval(eval(360.0 + eval(eval(eval(180.0 / Math.PI) * Math.atan2(
eval(eval('' + Math.cos(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[0]).value))) *
eval('' + Math.sin(eval(Math.PI / 180.0) * eval(eval('' + document.getElementById(eles[1]).value) - eval('' + document.getElementById(eles[5]).value))))),
eval(eval('' + Math.cos(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[4]).value))) *
eval('' + Math.sin(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[0]).value)))) -
eval(eval('' + Math.sin(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[4]).value))) *
eval('' + Math.cos(eval(Math.PI / 180.0) * eval('' + document.getElementById(eles[0]).value))) *
eval('' + Math.cos(eval(Math.PI / 180.0) * eval(eval('' + document.getElementById(eles[1]).value) - eval('' + document.getElementById(eles[5]).value)))))
)))) % 360.0);
//ourbrg=eval(eval(540.0 + eval('' + document.getElementById(eles[2]).value)) % 360.0);
document.getElementById(eles[2]).value='' + ourbrg;
document.getElementById('mysel').value='2';
//alert(ourbrg);
}



}

if (document.getElementById(eles[4]).value.indexOf('e-') != -1) { document.getElementById(eles[4]).value='0.0000000'; }
if (document.getElementById(eles[5]).value.indexOf('e-') != -1) { document.getElementById(eles[5]).value='0.0000000'; }

document.getElementById(eles[4]).style.backgroundColor='lightgreen';
document.getElementById(eles[5]).style.backgroundColor='lightgreen';
document.getElementById('goagain').style.display='block'; // setTimeout(nextplease,10000);

} else {
alert('Oops! Cannot calculate this mix, sorry.');
nextplease();
}

}

// 38.627089
// -90.200203
// 96.51262423499941 279.26239975009173
// 382900

</script>
</head>
<body>
<h1>Missing Two in a Table Column</h1>
<h3>RJM Programming - December, 2018</h3>
<h3>Thanks to <a target=_blank title='Thanks' href='//www.igismap.com/formula-to-find-bearing-or-heading-angle-between-two-points-latitude-longitude/'>https://www.igismap.com/formula-to-find-bearing-or-heading-angle-between-two-points-latitude-longitude/</a></title>

<table border=10 cellspacing=10 cellpadding=10>
<tr><th>From</th><th> ... On The Way ...</th><th>To</th></tr>
<tr><td id='from'>
Latitude (decimal degrees):&nbsp; <input onchange='this.style.backgroundColor="pink";cwhat[0]=false; cwhat[1]=false; if (!decided) { if (!cwhat[5]) { cwhat[5]=true; } if (!cwhat[4]) { cwhat[4]=true; } decided=true; } ' onblur='this.style.backgroundColor="pink";cwhat[0]=false; cwhat[1]=false; if (!decided) { if (!cwhat[5]) { cwhat[5]=true; } if (!cwhat[4]) { cwhat[4]=true; } decided=true; } ' id=latf type=number min=-90.0000000 max=90.0000000 step=0.0000010 value='0.0000000'></input><br>
Longitude (decimal degrees): <input onchange='this.style.backgroundColor="pink"; cwhat[0]=false; cwhat[1]=false; if (!decided) { if (!cwhat[5]) { cwhat[5]=true; } if (!cwhat[4]) { cwhat[4]=true; } decided=true; } ' onblur='this.style.backgroundColor="pink"; cwhat[0]=false; cwhat[1]=false; if (!decided) { if (!cwhat[5]) { cwhat[5]=true; } if (!cwhat[4]) { cwhat[4]=true; } decided=true; } ' id=longf type=number min=-180.0000000 max=180.0000000 step=0.0000010 value='0.0000000'></input>
</td><td id='ontheway'>
Bearing <select id=mysel><option value='2'>From -> To</option><option value='1'>To -> From</option></select> (decimal degrees): <input onchange='this.style.backgroundColor="pink"; cwhat[3]=false; cwhat[2]=false; if (!decided) { decided=true; } ' onblur='this.style.backgroundColor="pink"; cwhat[3]=false; cwhat[2]=false; if (!decided) { decided=true; } ' id=brg type=number min=-360.0000000 max=360.0000000 step=0.0000010 value='0.0000000'></input><br>
Distance (metres): <input onchange='this.style.backgroundColor="pink"; cwhat[3]=false; cwhat[2]=false; if (!decided) { decided=true; } ' onblur='this.style.backgroundColor="pink"; cwhat[3]=false; cwhat[2]=false; if (!decided) { decided=true; } ' id=dist type=number min=0.000 step=0.001 value='0.000'></input>
</td><td id='to'>
Latitude (decimal degrees):&nbsp; <input onchange='this.style.backgroundColor="pink"; cwhat[4]=false; cwhat[5]=false; if (!decided) { if (!cwhat[1]) { cwhat[1]=true; } if (!cwhat[0]) { cwhat[0]=true; } decided=true; } ' onblur='this.style.backgroundColor="pink"; cwhat[4]=false; cwhat[5]=false; if (!decided) { if (!cwhat[1]) { cwhat[1]=true; } if (!cwhat[0]) { cwhat[0]=true; } decided=true; } ' id=latt type=number min=-90.0000000 max=90.0000000 step=0.0000010 value='0.0000000'></input><br>
Longitude (decimal degrees): <input onchange='this.style.backgroundColor="pink"; cwhat[5]=false; cwhat[4]=false; if (!decided) { if (!cwhat[1]) { cwhat[1]=true; } if (!cwhat[0]) { cwhat[0]=true; } decided=true; } ' onblur='this.style.backgroundColor="pink"; cwhat[4]=false; cwhat[5]=false; if (!decided) { if (!cwhat[1]) { cwhat[1]=true; } if (!cwhat[0]) { cwhat[0]=true; } decided=true; } ' id=longt type=number min=-90.0000000 max=90.0000000 step=0.0000010 value='0.0000000'></input>
</td></tr>
<tr><td><input style='background-color:yellow;font-size:24px;' onclick='calcit();' type=button value='Calculate'></input></td><td></td><td><input id=goagain style='display:none;background-color:lightgreen;font-size:24px;' onclick="nextplease(); this.style.display='none';" type=button value='Go Again'></input></td></tr>
</table>
<input style='position:absolute;top:-200px;left:-200px;' type='text' value=''></input>
</body>
</html>