UNPKG

random-flight-generator

Version:
44 lines (43 loc) 1.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FlightMath = void 0; var FlightMath = /** @class */ (function () { function FlightMath() { } /** * Returns the distance in meters between two MapCoordinates * Source: https://www.movable-type.co.uk/scripts/latlong.html **/ FlightMath.getDistance = function (start, end) { var R = 6371e3; // metres var φ1 = (start.lat * Math.PI) / 180; // φ, λ in radians var φ2 = (end.lat * Math.PI) / 180; var Δφ = ((end.lat - start.lat) * Math.PI) / 180; var Δλ = ((end.lon - start.lon) * Math.PI) / 180; var a = Math.sin(Δφ / 2) * Math.sin(Δφ / 2) + Math.cos1) * Math.cos2) * Math.sin(Δλ / 2) * Math.sin(Δλ / 2); var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); var d = R * c; // in metres return d; }; /** * Returns the bearing in degrees between two MapCoordinates * Source: https://www.movable-type.co.uk/scripts/latlong.html **/ FlightMath.getBearing = function (start, end) { var φ1 = (start.lat * Math.PI) / 180; // φ, λ in radians var φ2 = (end.lat * Math.PI) / 180; var λ1 = (start.lon * Math.PI) / 180; // φ, λ in radians var λ2 = (end.lon * Math.PI) / 180; var y = Math.sin2 - λ1) * Math.cos2); var x = Math.cos1) * Math.sin2) - Math.sin1) * Math.cos2) * Math.cos2 - λ1); var θ = Math.atan2(y, x); return ((θ * 180) / Math.PI + 360) % 360; // in degrees }; FlightMath.metersToNauticalMiles = function (distance) { return distance / 1852; }; return FlightMath; }()); exports.FlightMath = FlightMath;