Skip to content

Commit afb96d6

Browse files
small code fixups
1 parent 9877f3f commit afb96d6

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

js/tracker.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ function calculate_lookangles(a, b) {
120120

121121
var directions = ['N','E','S','W'];
122122
var idx = Math.floor(bearing / 90);
123-
var str_bearing = "" + directions[idx] + " " + Math.round(bearing % 90) + '° ' + directions[(idx+1)%4];
124-
123+
var str_bearing = "" + directions[idx%4] + " " + Math.round(bearing % 90) + '° ' + directions[(idx+1)%4];
125124

126125
return {
127126
'elevation': elevation,
@@ -428,15 +427,13 @@ function updateVehicleInfo(index, newPosition) {
428427
if(vehicle.subhorizon_circle) {
429428
// see: http://ukhas.org.uk/communication:lineofsight
430429
var el = 5.0; // elevation above horizon
431-
var rad = 6378.10; // radius of earth
432-
var h = newPosition.gps_alt / 1000; // height above ground
430+
var h = parseFloat(newPosition.gps_alt); // height above ground
433431

434-
var elva = el * Math.PI / 180.0;
435-
var slant = rad*(Math.cos(Math.PI/2+elva)+Math.sqrt(Math.pow(Math.cos(Math.PI/2+elva),2)+h*(2*rad+h)/Math.pow(rad,2)));
436-
var x = Math.acos((Math.pow(rad,2)+Math.pow(rad+h,2)-Math.pow(slant,2))/(2*rad*(rad+h)))*rad;
432+
var elva = el * DEG_TO_RAD;
433+
var slant = EARTH_RADIUS*(Math.cos(Math.PI/2+elva)+Math.sqrt(Math.pow(Math.cos(Math.PI/2+elva),2)+h*(2*EARTH_RADIUS+h)/Math.pow(EARTH_RADIUS,2)));
434+
var subhorizon_km = Math.acos((Math.pow(EARTH_RADIUS,2)+Math.pow(EARTH_RADIUS+h,2)-Math.pow(slant,2))/(2*EARTH_RADIUS*(EARTH_RADIUS+h)))*EARTH_RADIUS;
437435

438-
var subhorizon_km = x;
439-
vehicle.subhorizon_circle.setRadius(Math.round(subhorizon_km)*1000);
436+
vehicle.subhorizon_circle.setRadius(Math.round(subhorizon_km));
440437
}
441438

442439
// indicates whenever a payload has landed

0 commit comments

Comments
 (0)