Javascript maths question

  • Thread starter Thread starter ~J~
  • Start date Start date

~J~

~J~

Soldato
Joined
20 Oct 2003
Posts
7,558
Location
London
I'm USELESS at maths! :o

Can anyone help with the following:

function DoCalc1(form) {
Orig[1] = form.Longitude.value;
Orig[2] = form.Latitude.value;
Sat[0] = form.SatPosition.value;

if ((Orig[1]=="" )||(Orig[2]=="")||(Sat[0]=="")) {
alert("Please Enter Latitude, Longitude, position values");
}
else
{
latangle = Degrees2Radian(Orig[2]);
longangle = Degrees2Radian(Orig[1]);
satangle = Degrees2Radian(Sat[0]);
diff = Math.abs(Sat[0] - Orig[1]);

diff = Degrees2Radian(diff);
F1 = (Math.cos(latangle) * Math.cos(diff));
Y = Math.acos(F1); //Y in Radian

Azimuth = Math.acos(-Math.tan(latangle)/Math.tan(Y)) * 180 /Math.PI;
Elevation = Math.atan( (Math.cos(Y) - 0.15116) / Math.sin(Y)) * 180 / Math.PI;
if (Sat[0] - Orig[1] > 0) {
Azimuth = 360 - Azimuth;
}
Azimuth = RoundNum(Azimuth,1);
Elevation = RoundNum(Elevation, 1);
form.Azimuth.value = Azimuth;
form.Elevation.value = Elevation;

//message = ("Latitude : " + Orig[1] + "\n");
//message += ("Longitude: " + Orig[2] + "\n\n");
//message += ("Azimuth : " + Azimuth + "\n");
//message += ("Elevation: " + Elevation + "\n");
//alert(message);
}
}

That converts a latitude and longitude into an azimuth and elevation.

But I now want to REVERSE the calculation so that if I enter an azimuth and elevation, it gives a latitude and longitude!

The code above was NOT done by me, but a colleague (who's more clued up than I am!!)

Anyone have any ideas where to start? Do I simply reverse the maths? Make a / into a * and a + into a -? What about SIN's, COS's and TAN's though?
 
Back
Top Bottom