UNPKG

astronomy-bundle

Version:

Bundle for astronomical calculations such as position of moon, sun and planets, sunrise, sunset or solar eclipses. Most of the calculations are based on Jean Meeus 'Astronomical Algorithms' book and the VSOP87 theory.

35 lines (34 loc) 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDistanceInKm = exports.km2au = exports.au2km = void 0; const dimensions_1 = require("../earth/constants/dimensions"); const angleCalc_1 = require("./angleCalc"); const math_1 = require("./math"); const AU_UNIT_OF_LENGTH = 149597870700.0; function au2km(R) { return R * (AU_UNIT_OF_LENGTH / 1000); } exports.au2km = au2km; function km2au(km) { return km / (AU_UNIT_OF_LENGTH / 1000); } exports.km2au = km2au; function getDistanceInKm(location1, location2) { const { lat: lat1, lon: lon1 } = location1; const { lat: lat2, lon: lon2 } = location2; const F = (lat1 + lat2) / 2; const G = (lat1 - lat2) / 2; const lambda = (lon2 - lon1) / 2; const FRad = (0, angleCalc_1.deg2rad)(F); const GRad = (0, angleCalc_1.deg2rad)(G); const lambdaRad = (0, angleCalc_1.deg2rad)(lambda); const S = (0, math_1.sin2)(GRad) * (0, math_1.cos2)(lambdaRad) + (0, math_1.cos2)(FRad) * (0, math_1.sin2)(lambdaRad); const C = (0, math_1.cos2)(GRad) * (0, math_1.cos2)(lambdaRad) + (0, math_1.sin2)(FRad) * (0, math_1.sin2)(lambdaRad); const omegaRad = Math.atan(Math.sqrt(S / C)); const R = Math.sqrt(S * C) / omegaRad; const D = 2 * omegaRad * dimensions_1.EARTH_RADIUS / 1000; const H1 = (3 * R - 1) / (2 * C); const H2 = (3 * R + 1) / (2 * S); return D * (1 + dimensions_1.EARTH_FLATTENING * H1 * (0, math_1.sin2)(FRad) * (0, math_1.cos2)(GRad) - dimensions_1.EARTH_FLATTENING * H2 * (0, math_1.cos2)(FRad) * (0, math_1.sin2)(GRad)); } exports.getDistanceInKm = getDistanceInKm;