Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
11
Task/Haversine-formula/JavaScript/haversine-formula.js
Normal file
11
Task/Haversine-formula/JavaScript/haversine-formula.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
function haversine() {
|
||||
var radians = Array.prototype.map.call(arguments, function(deg) { return deg/180.0 * Math.PI; });
|
||||
var lat1 = radians[0], lon1 = radians[1], lat2 = radians[2], lon2 = radians[3];
|
||||
var R = 6372.8; // km
|
||||
var dLat = lat2 - lat1;
|
||||
var dLon = lon2 - lon1;
|
||||
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.asin(Math.sqrt(a));
|
||||
return R * c;
|
||||
}
|
||||
console.log(haversine(36.12, -86.67, 33.94, -118.40));
|
||||
Loading…
Add table
Add a link
Reference in a new issue