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.

138 lines (137 loc) 5.79 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDeclinationInterpolationArray = exports.getRightAscensionInterpolationArray = exports.getLatitudeInterpolationArray = exports.getLongitudeInterpolationArray = exports.getInterpolateValue5 = exports.tabularInterpolation5 = exports.tabularInterpolation3 = void 0; const time_1 = require("../time"); function tabularInterpolation3(values, n = 0.0) { const y2 = values[1]; const A = values[1] - values[0]; const B = values[2] - values[1]; const C = B - A; return y2 + 0.5 * n * (A + B + n * C); } exports.tabularInterpolation3 = tabularInterpolation3; function tabularInterpolation5(values, n = 0.0) { const y3 = values[2]; const A = values[1] - values[0]; const B = values[2] - values[1]; const C = values[3] - values[2]; const D = values[4] - values[3]; const E = B - A; const F = C - B; const G = D - C; const H = F - E; const J = G - F; const K = J - H; while (true) { const numerator = -24 * y3 + Math.pow(n, 2) * (K - 12 * F) - 2 * Math.pow(n, 3) * (H + J) - Math.pow(n, 4) * K; const denominator = 2 * (6 * B + 6 * C - H - J); const nNew = numerator / denominator; if (nNew === n) { return n; } n = nNew; } } exports.tabularInterpolation5 = tabularInterpolation5; function getInterpolateValue5(values, n = 0.0) { const y3 = values[2]; const A = values[1] - values[0]; const B = values[2] - values[1]; const C = values[3] - values[2]; const D = values[4] - values[3]; const E = B - A; const F = C - B; const G = D - C; const H = F - E; const J = G - F; const K = J - H; return y3 + n / 2 * (B + C) + Math.pow(n, 2) / 2 * F + n * (Math.pow(n, 2) - 1) / 12 * (H + J) + Math.pow(n, 2) * (Math.pow(n, 2) - 1) / 24 * K; } exports.getInterpolateValue5 = getInterpolateValue5; function getLongitudeInterpolationArray(ObjConstructor_1, jd0_1) { return __awaiter(this, arguments, void 0, function* (ObjConstructor, jd0, nMax = 1.0) { const result = []; for (let n = -1 * nMax; n <= nMax; n++) { const jd = jd0 + n; const toi = time_1.createTimeOfInterest.fromJulianDay(jd); const object = new ObjConstructor(toi); const { lon } = yield object.getApparentGeocentricEclipticSphericalCoordinates(); result.push(lon); } return _fix360Crossing(result); }); } exports.getLongitudeInterpolationArray = getLongitudeInterpolationArray; function getLatitudeInterpolationArray(ObjConstructor_1, jd0_1) { return __awaiter(this, arguments, void 0, function* (ObjConstructor, jd0, nMax = 1.0) { const result = []; for (let n = -1 * nMax; n <= nMax; n++) { const jd = jd0 + n; const toi = time_1.createTimeOfInterest.fromJulianDay(jd); const object = new ObjConstructor(toi); const { lat } = yield object.getApparentGeocentricEclipticSphericalCoordinates(); result.push(lat); } return result; }); } exports.getLatitudeInterpolationArray = getLatitudeInterpolationArray; function getRightAscensionInterpolationArray(ObjConstructor_1, jd0_1) { return __awaiter(this, arguments, void 0, function* (ObjConstructor, jd0, nMax = 1.0) { const result = []; for (let n = -1 * nMax; n <= nMax; n++) { const jd = jd0 + n; const toi = time_1.createTimeOfInterest.fromJulianDay(jd); const object = new ObjConstructor(toi); const { rightAscension } = yield object.getApparentGeocentricEquatorialSphericalCoordinates(); result.push(rightAscension); } return _fix360Crossing(result); }); } exports.getRightAscensionInterpolationArray = getRightAscensionInterpolationArray; function getDeclinationInterpolationArray(ObjConstructor_1, jd0_1) { return __awaiter(this, arguments, void 0, function* (ObjConstructor, jd0, nMax = 1.0) { const result = []; for (let n = -1 * nMax; n <= nMax; n++) { const jd = jd0 + n; const toi = time_1.createTimeOfInterest.fromJulianDay(jd); const object = new ObjConstructor(toi); const { declination } = yield object.getApparentGeocentricEquatorialSphericalCoordinates(); result.push(declination); } return result; }); } exports.getDeclinationInterpolationArray = getDeclinationInterpolationArray; function _fix360Crossing(raArray) { const result = []; let add = 0; let previousValue = 0; for (const [i, currentValue] of raArray.entries()) { if (i > 0 && previousValue - currentValue > 270) { add += 360; } if (i > 0 && currentValue - previousValue > 270) { add -= 360; } result.push(currentValue + add); previousValue = currentValue; } if (add < 0) { return result.map((entry) => entry + 360); } return result; }