Skip to content

Commit 3788dfc

Browse files
authored
Create Coordinate.js
This is a new file that should serve as a future collection of algorithms involving solutions for coordinates. The first algorithm is a function to calculate the distance between 2 coordinates on a 2D plane.
1 parent ff1d209 commit 3788dfc

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Maths/Coordinate.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
Calculate the mathematical properties involving coordinates
3+
4+
Calculate the Distance Between 2 Points on a 2 Dimensional Plane
5+
Example: coorDistance(2,2,14,11) will return 15
6+
Wikipedia reference: https://en.wikipedia.org/wiki/Geographical_distance#Flat-surface_formulae
7+
*/
8+
const distance2points = (longitude1, latitude1, longitude2, latitude2) => {
9+
const width = longitude2 - longitude1;
10+
const height = latitude2 - latitude1;
11+
return (Math.sqrt(width * width + height * height));
12+
};
13+
14+
export { distance2points };

0 commit comments

Comments
 (0)