Skip to content

Instantly share code, notes, and snippets.

@pjeweb
Created December 2, 2011 17:30
Show Gist options
  • Save pjeweb/1424089 to your computer and use it in GitHub Desktop.
Save pjeweb/1424089 to your computer and use it in GitHub Desktop.
Calculate Azimut
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