mirror of
https://github.com/Ekokumppanit/Lentolaskuri.git
synced 2026-02-12 22:46:38 +00:00
Initial commit
This commit is contained in:
26
app/scripts/libs/math.js
Normal file
26
app/scripts/libs/math.js
Normal file
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
define([
|
||||
'config',
|
||||
'libs/airports'
|
||||
], function (cfg, airports) {
|
||||
var toRad = function toRad(n) {
|
||||
return n * Math.PI / 180;
|
||||
};
|
||||
|
||||
var haversine = function haversine(from, to) {
|
||||
var dLat = toRad(to.get('lat') - from.get('lat'));
|
||||
var dLon = toRad(to.get('long') - from.get('long'));
|
||||
var lat1 = toRad(from.get('lat'));
|
||||
var lat2 = toRad(to.get('lat'));
|
||||
|
||||
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
|
||||
Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
|
||||
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
||||
return cfg.R * c;
|
||||
};
|
||||
|
||||
return {
|
||||
toRad: toRad,
|
||||
haversine: haversine
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user