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.
66 lines (65 loc) • 4.23 kB
JavaScript
;
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.getConjunctionInLongitude = exports.getConjunctionInRightAscension = void 0;
const time_1 = require("../../time");
const interpolationCalc_1 = require("../../utils/interpolationCalc");
const PlanetTypes_1 = require("../types/PlanetTypes");
function getConjunctionInRightAscension(obj1Constructor, obj2Constructor, jd0) {
return __awaiter(this, void 0, void 0, function* () {
const raEphemerisObj1 = yield (0, interpolationCalc_1.getRightAscensionInterpolationArray)(obj1Constructor, jd0, 2);
const raEphemerisObj2 = yield (0, interpolationCalc_1.getRightAscensionInterpolationArray)(obj2Constructor, jd0, 2);
const raEphemerisDiff = _getEphemerisDiff(raEphemerisObj1, raEphemerisObj2);
if (!_isConjunctionPossible(raEphemerisDiff)) {
throw new Error('No conjunction in right ascension possible for given objects at ' + jd0);
}
const n = (0, interpolationCalc_1.tabularInterpolation5)(raEphemerisDiff);
const decEphemerisObj1 = yield (0, interpolationCalc_1.getDeclinationInterpolationArray)(obj1Constructor, jd0, 2);
const decEphemerisObj2 = yield (0, interpolationCalc_1.getDeclinationInterpolationArray)(obj2Constructor, jd0, 2);
const decEphemerisDiff = _getEphemerisDiff(decEphemerisObj1, decEphemerisObj2);
const declination = (0, interpolationCalc_1.getInterpolateValue5)(decEphemerisDiff, n);
return {
toi: time_1.createTimeOfInterest.fromJulianDay(jd0 + n),
position: declination >= 0 ? PlanetTypes_1.Position.North : PlanetTypes_1.Position.South,
angularDistance: Math.abs(declination),
};
});
}
exports.getConjunctionInRightAscension = getConjunctionInRightAscension;
function getConjunctionInLongitude(obj1Constructor, obj2Constructor, jd0) {
return __awaiter(this, void 0, void 0, function* () {
const lonEphemerisObj1 = yield (0, interpolationCalc_1.getLongitudeInterpolationArray)(obj1Constructor, jd0, 2);
const lonEphemerisObj2 = yield (0, interpolationCalc_1.getLongitudeInterpolationArray)(obj2Constructor, jd0, 2);
const lonEphemerisDiff = _getEphemerisDiff(lonEphemerisObj1, lonEphemerisObj2);
if (!_isConjunctionPossible(lonEphemerisDiff)) {
throw new Error('No conjunction in longitude possible for given objects at ' + jd0);
}
const n = (0, interpolationCalc_1.tabularInterpolation5)(lonEphemerisDiff);
const latEphemerisObj1 = yield (0, interpolationCalc_1.getLatitudeInterpolationArray)(obj1Constructor, jd0, 2);
const latEphemerisObj2 = yield (0, interpolationCalc_1.getLatitudeInterpolationArray)(obj2Constructor, jd0, 2);
const latEphemerisDiff = _getEphemerisDiff(latEphemerisObj1, latEphemerisObj2);
const latitude = (0, interpolationCalc_1.getInterpolateValue5)(latEphemerisDiff, n);
return {
toi: time_1.createTimeOfInterest.fromJulianDay(jd0 + n),
position: latitude >= 0 ? PlanetTypes_1.Position.North : PlanetTypes_1.Position.South,
angularDistance: Math.abs(latitude),
};
});
}
exports.getConjunctionInLongitude = getConjunctionInLongitude;
function _isConjunctionPossible(diffArray) {
const ra1 = diffArray[2];
const ra2 = diffArray[3];
return ra1 < 0 && ra2 >= 0 || ra1 >= 0 && ra2 < 0;
}
function _getEphemerisDiff(ephemeris1, ephemeris2) {
return ephemeris1.map((value1, key) => value1 - ephemeris2[key]);
}