-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
21 lines (16 loc) · 728 Bytes
/
Copy pathindex.js
File metadata and controls
21 lines (16 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
'use strict';
const toRadians = degrees => degrees * (Math.PI / 180);
const toDegrees = radians => radians * (180 / Math.PI);
function determineAngleDeviationFromNorth(from, to) {
const toLat = toRadians(to.latitude);
const fromLat = toRadians(from.latitude);
let dLon = toRadians(to.longitude - from.longitude);
const dPhi = Math.log(Math.tan(toLat / 2 + Math.PI / 4) / Math.tan(fromLat / 2 + Math.PI / 4));
// if dLon over 180° take shorter rhumb across 180° meridian:
if (Math.abs(dLon) > Math.PI) {
dLon = dLon > 0 ? -(2 * Math.PI - dLon) : 2 * Math.PI + dLon;
}
const result = toDegrees(Math.atan2(dLon, dPhi));
return (result + 360) % 360;
}
module.exports = determineAngleDeviationFromNorth;