Created
December 2, 2011 17:30
-
-
Save pjeweb/1424089 to your computer and use it in GitHub Desktop.
Calculate Azimut
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var calcAzimut = function (p1, p2) { | |
'use strict'; | |
var toDeg = function (x) { | |
return x * 180 / Math.PI; | |
}, | |
dy = p2.latitude - p1.latitude, | |
dx = p2.longitude - p1.longitude; | |
return ( | |
(dx > 0) ? toDeg((Math.PI * 0.5) - Math.atan(dy / dx)) : | |
(dx < 0) ? toDeg((Math.PI * 1.5) - Math.atan(dy / dx)) : | |
(dy > 0) ? 0 : | |
(dy < 0) ? Math.PI : undefined | |
); | |
}; | |
var calcAzimut=function(e,d){var c=function(f){return f*180/Math.PI},a=d.latitude-e.latitude,b=d.longitude-e.longitude;return((b>0)?c((Math.PI*0.5)-Math.atan(a/b)):(b<0)?c((Math.PI*1.5)-Math.atan(a/b)):(a>0)?0:(a<0)?Math.PI:undefined)}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment