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.
186 lines (185 loc) • 9.24 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSunAltitude = exports.getSunrise = exports.getQuantities = exports.getPhysicalSelenographicLocation = exports.getOpticalSelenographicLocation = exports.getSelenographicLocation = void 0;
const sunCalc = __importStar(require("../../sun/calculations/sunCalc"));
const time_1 = require("../../time");
const angleCalc_1 = require("../../utils/angleCalc");
const calculations_1 = require("../constants/calculations");
const createMoon_1 = __importDefault(require("../createMoon"));
const moonCalc_1 = require("./moonCalc");
function getSelenographicLocation(coords, T) {
const { lon: lonOpt, lat: latOpt } = getOpticalSelenographicLocation(coords, T);
const { lon: lonPhy, lat: latPhy } = getPhysicalSelenographicLocation(coords, T);
return {
lon: lonOpt + lonPhy,
lat: latOpt + latPhy,
};
}
exports.getSelenographicLocation = getSelenographicLocation;
function getOpticalSelenographicLocation(coords, T) {
const F = (0, moonCalc_1.getArgumentOfLatitude)(T);
const { W, A } = getWA(coords, T);
const latMoonRad = (0, angleCalc_1.deg2rad)(coords.lat);
const WRad = (0, angleCalc_1.deg2rad)(W);
const IRad = (0, angleCalc_1.deg2rad)(calculations_1.INCLINATION_OF_MEAN_LUNAR_EQUATOR);
const lon = A - F;
const latRad = Math.asin(-1 * Math.sin(WRad) * Math.cos(latMoonRad) * Math.sin(IRad) - Math.sin(latMoonRad) * Math.cos(IRad));
const lat = (0, angleCalc_1.rad2deg)(latRad);
return { lon, lat };
}
exports.getOpticalSelenographicLocation = getOpticalSelenographicLocation;
function getPhysicalSelenographicLocation(coords, T) {
const { lat: latOpt } = getOpticalSelenographicLocation(coords, T);
const { A } = getWA(coords, T);
const { rho, sigma, tau } = getQuantities(T);
const latOptRad = (0, angleCalc_1.deg2rad)(latOpt);
const ARad = (0, angleCalc_1.deg2rad)(A);
const lon = -1 * tau + (rho * Math.cos(ARad) + sigma * Math.sin(ARad)) * Math.tan(latOptRad);
const lat = sigma * Math.cos(ARad) - rho * Math.sin(ARad);
return { lon, lat };
}
exports.getPhysicalSelenographicLocation = getPhysicalSelenographicLocation;
function getQuantities(T) {
const F = (0, moonCalc_1.getArgumentOfLatitude)(T);
const D = (0, moonCalc_1.getMeanElongation)(T);
const MSun = sunCalc.getMeanAnomaly(T);
const MMoon = (0, moonCalc_1.getMeanAnomaly)(T);
const O = (0, moonCalc_1.getMeanLongitudeOfAscendingNode)(T);
const FRad = (0, angleCalc_1.deg2rad)(F);
const DRad = (0, angleCalc_1.deg2rad)(D);
const MSunRad = (0, angleCalc_1.deg2rad)(MSun);
const MMoonRad = (0, angleCalc_1.deg2rad)(MMoon);
const ORad = (0, angleCalc_1.deg2rad)(O);
const K1 = 119.75 + 131.849 * T;
const K2 = 72.56 + 20.186 * T;
const K1Rad = (0, angleCalc_1.deg2rad)(K1);
const K2Rad = (0, angleCalc_1.deg2rad)(K2);
const E = 1 - 0.002516 * T - 0.0000074 * Math.pow(T, 2);
const rho = -0.02752 * Math.cos(MMoonRad)
- 0.02245 * Math.sin(FRad)
+ 0.00684 * Math.cos(MMoonRad - 2 * FRad)
- 0.00293 * Math.cos(2 * FRad)
- 0.00085 * Math.cos(2 * FRad - 2 * DRad)
- 0.00054 * Math.cos(MMoonRad - 2 * DRad)
- 0.00020 * Math.sin(MMoonRad + FRad)
- 0.00020 * Math.cos(MMoonRad + 2 * FRad)
- 0.00020 * Math.cos(MMoonRad - FRad)
+ 0.00014 * Math.cos(MMoonRad + 2 * FRad - 2 * DRad);
const sigma = 0
- 0.02816 * Math.sin(MMoonRad)
+ 0.02244 * Math.cos(FRad)
- 0.00682 * Math.sin(MMoonRad - 2 * FRad)
- 0.00279 * Math.sin(2 * FRad)
- 0.00083 * Math.sin(2 * FRad - 2 * DRad)
+ 0.00069 * Math.sin(MMoonRad - 2 * DRad)
+ 0.00040 * Math.cos(MMoonRad + FRad)
- 0.00025 * Math.sin(2 * MMoonRad)
- 0.00023 * Math.sin(MMoonRad + 2 * FRad)
+ 0.00020 * Math.cos(MMoonRad - FRad)
+ 0.00019 * Math.sin(MMoonRad - FRad)
+ 0.00013 * Math.sin(MMoonRad + 2 * FRad - 2 * DRad)
- 0.00010 * Math.cos(MMoonRad - 3 * FRad);
const tau = 0.02520 * E * Math.sin(MSunRad)
+ 0.00473 * Math.sin(2 * MMoonRad - 2 * FRad)
- 0.00467 * Math.sin(MMoonRad)
+ 0.00396 * Math.sin(K1Rad)
+ 0.00276 * Math.sin(2 * MMoonRad - 2 * DRad)
+ 0.00196 * Math.sin(ORad)
- 0.00183 * Math.cos(MMoonRad - FRad)
+ 0.00115 * Math.sin(MMoonRad - 2 * DRad)
- 0.00096 * Math.sin(MMoonRad - DRad)
+ 0.00046 * Math.sin(2 * FRad - 2 * DRad)
- 0.00039 * Math.sin(MMoonRad - FRad)
- 0.00032 * Math.sin(MMoonRad - MSunRad - DRad)
+ 0.00027 * Math.sin(2 * MMoonRad - MSunRad - 2 * DRad)
+ 0.00023 * Math.sin(K2Rad)
- 0.00014 * Math.sin(2 * DRad)
+ 0.00014 * Math.cos(2 * MMoonRad - 2 * FRad)
- 0.00012 * Math.sin(MMoonRad - 2 * FRad)
- 0.00012 * Math.sin(2 * MMoonRad)
+ 0.00011 * Math.sin(2 * MMoonRad - 2 * MSunRad - 2 * DRad);
return { rho, sigma, tau };
}
exports.getQuantities = getQuantities;
function getWA(coords, T) {
const omega = (0, moonCalc_1.getMeanLongitudeOfAscendingNode)(T);
const latMoonRad = (0, angleCalc_1.deg2rad)(coords.lat);
const IRad = (0, angleCalc_1.deg2rad)(calculations_1.INCLINATION_OF_MEAN_LUNAR_EQUATOR);
const W = (0, angleCalc_1.normalizeAngle)(coords.lon - omega);
const WRad = (0, angleCalc_1.deg2rad)(W);
const numerator = Math.sin(WRad) * Math.cos(latMoonRad) * Math.cos(IRad) - Math.sin(latMoonRad) * Math.sin(IRad);
const denominator = Math.cos(WRad) * Math.cos(latMoonRad);
const ARad = Math.atan2(numerator, denominator);
const A = (0, angleCalc_1.normalizeAngle)((0, angleCalc_1.rad2deg)(ARad));
return { W, A };
}
function getSunrise(selenographicLocation, T) {
return __awaiter(this, void 0, void 0, function* () {
let h;
do {
const { lon, lat } = yield _getSelenographicLocationOfSun(T);
const c0 = (0, angleCalc_1.normalizeAngle)(90 - lon);
h = getSunAltitude(selenographicLocation, lat, c0);
T -= _getCorrectionInDays(selenographicLocation, h) / 36525.0;
} while (Math.abs(h) > 0.001);
return T;
});
}
exports.getSunrise = getSunrise;
function _getSelenographicLocationOfSun(T) {
return __awaiter(this, void 0, void 0, function* () {
const toi = time_1.createTimeOfInterest.fromJulianCenturiesJ2000(T);
const moon = (0, createMoon_1.default)(toi);
const coords = yield moon.getHeliocentricEclipticSphericalDateCoordinates();
return getSelenographicLocation(coords, T);
});
}
function getSunAltitude(selenographicLocation, selenographicLatOfSun, c0) {
const { lon, lat } = selenographicLocation;
const lonRad = (0, angleCalc_1.deg2rad)(lon);
const latRad = (0, angleCalc_1.deg2rad)(lat);
const lat0Rad = (0, angleCalc_1.deg2rad)(selenographicLatOfSun);
const c0Rad = (0, angleCalc_1.deg2rad)(c0);
const hRad = Math.asin(Math.sin(lat0Rad) * Math.sin(latRad) + Math.cos(lat0Rad) * Math.cos(latRad) * Math.sin(c0Rad + lonRad));
return (0, angleCalc_1.rad2deg)(hRad);
}
exports.getSunAltitude = getSunAltitude;
function _getCorrectionInDays(selenographicLocation, h) {
const latRad = (0, angleCalc_1.deg2rad)(selenographicLocation.lat);
return h / (12.19075 * Math.cos(latRad));
}