centralize the earth radius
This commit is contained in:
		| @@ -1,5 +1,7 @@ | |||||||
| import { Angle } from './angle'; | import { Angle } from './angle'; | ||||||
|  |  | ||||||
|  | const EarthRadius = 6371000; | ||||||
|  |  | ||||||
| export class WGS84 { | export class WGS84 { | ||||||
|   /// @brief Calculates the Haversine distance |   /// @brief Calculates the Haversine distance | ||||||
|   /// @param coordinate0 The first coordinate |   /// @param coordinate0 The first coordinate | ||||||
| @@ -13,13 +15,12 @@ export class WGS84 { | |||||||
|     const lon0 = Angle.deg2rad(coordinate0.lon); |     const lon0 = Angle.deg2rad(coordinate0.lon); | ||||||
|     const lat1 = Angle.deg2rad(coordinate1.lat); |     const lat1 = Angle.deg2rad(coordinate1.lat); | ||||||
|     const lon1 = Angle.deg2rad(coordinate1.lon); |     const lon1 = Angle.deg2rad(coordinate1.lon); | ||||||
|     const earthRadius = 6371000; |  | ||||||
|  |  | ||||||
|     const a = |     const a = | ||||||
|       0.5 - |       0.5 - | ||||||
|       Math.cos(lat1 - lat0) * 0.5 + |       Math.cos(lat1 - lat0) * 0.5 + | ||||||
|       Math.cos(lat0) * Math.cos(lat1) * (1 - Math.cos(lon1 - lon0) * 0.5); |       Math.cos(lat0) * Math.cos(lat1) * (1 - Math.cos(lon1 - lon0) * 0.5); | ||||||
|  |  | ||||||
|     return 2 * earthRadius * Math.asin(Math.sqrt(a)); |     return 2 * EarthRadius * Math.asin(Math.sqrt(a)); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user