forked from TheAlgorithms/JavaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoordinate.js
More file actions
Latest commit
19 lines (17 loc) · 744 Bytes
/
Copy pathCoordinate.js
File metadata and controls
19 lines (17 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
Calculate the mathematical properties involving coordinates
Calculate the Distance Between 2 Points on a 2 Dimensional Plane
Example: coorDistance(2,2,14,11) will return 15
Wikipedia reference: https://en.wikipedia.org/wiki/Geographical_distance#Flat-surface_formulae
*/
consteuclideanDistance=(longitude1,latitude1,longitude2,latitude2)=>{
constwidth=longitude2-longitude1
constheight=latitude2-latitude1
return(Math.sqrt(width*width+height*height))
}
constmanhattanDistance=(longitude1,latitude1,longitude2,latitude2)=>{
constwidth=Math.abs(longitude2-longitude1)
constheight=Math.abs(latitude2-latitude1)
returnwidth+height
}
export{euclideanDistance,manhattanDistance}