angle.js 715 Bytes
Newer Older
Athanasios's avatar
Athanasios committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const RADIANS_PER_DEGREE = Math.PI / 180.0;
const METERS_PER_LONGITUDE_DEGREE_AT_EQUATOR = 111321;
const METERS_PER_LATITUDE_DEGREE = 111130;

const degreesToRadians = (degrees) => {
  return degrees * RADIANS_PER_DEGREE;
}

/**
 * Surface is considered planar. This simplifies the calculations.
 */
const roughDistanceToLongitude = (latitude, distance) => {
  let metersPerLongitude = Math.cos(degreesToRadians(latitude)) * METERS_PER_LONGITUDE_DEGREE_AT_EQUATOR;
  return distance / metersPerLongitude;
}

const roughDistanceToLatitude = (distance) => {
  return distance / METERS_PER_LATITUDE_DEGREE;
}

module.exports = { degreesToRadians, roughDistanceToLongitude, roughDistanceToLatitude }