diff --git a/src/moon.ts b/src/moon.ts index be56e67..43a7788 100644 --- a/src/moon.ts +++ b/src/moon.ts @@ -6,7 +6,9 @@ /*****************************************************************************************************************/ -import { type EclipticCoordinate } from './common' +import { getObliquityOfTheEcliptic } from './astrometry' + +import { type EclipticCoordinate, type EquatorialCoordinate } from './common' import { getJulianDate } from './epoch' @@ -418,3 +420,46 @@ export const getLunarEclipticCoordinate = (datetime: Date): EclipticCoordinate = } /*****************************************************************************************************************/ + +/** + * + * getLunarEquatorialCoordinate() + * + * The equatorial coordinates for the Moon are the angles between the equator and + * the current position of the Moon, as seen from the centre of the Earth, + * corrected for the equation of center and the Moon's ecliptic longitude at + * perigee at the epoch. + * + * @param date - The date to calculate the Moon's equatorial coordinates for. + * @returns The Moon's equatorial coordinates in degrees. + * + */ +export const getLunarEquatorialCoordinate = (datetime: Date): EquatorialCoordinate => { + // Get the ecliptic coordinates for the Moon: + const { λ, β } = getLunarEclipticCoordinate(datetime) + + // Get the ecliptic obliquity: + const ε = radians(getObliquityOfTheEcliptic(datetime)) + + // Calculate the right ascension of the Moon: + const ra = degrees( + Math.atan2( + Math.sin(radians(λ)) * Math.cos(ε) - Math.tan(radians(β)) * Math.sin(ε), + Math.cos(radians(λ)) + ) + ) + + // Calculate the declination of the Moon: + const dec = degrees( + Math.asin( + Math.sin(radians(β)) * Math.cos(ε) + Math.cos(radians(β)) * Math.sin(ε) * Math.sin(radians(λ)) + ) + ) + + return { + ra, + dec + } +} + +/*****************************************************************************************************************/ diff --git a/tests/moon.spec.ts b/tests/moon.spec.ts index 739e65e..d1b682f 100644 --- a/tests/moon.spec.ts +++ b/tests/moon.spec.ts @@ -23,7 +23,8 @@ import { getLunarCorrectedEclipticLongitudeOfTheAscendingNode, getLunarEclipticLongitude, getLunarEclipticLatitude, - getLunarEclipticCoordinate + getLunarEclipticCoordinate, + getLunarEquatorialCoordinate } from '../src' /*****************************************************************************************************************/ @@ -203,3 +204,18 @@ describe('getLunarEclipticCoordinate', () => { }) /*****************************************************************************************************************/ + +describe('getLunarEquatorialCoordinate', () => { + it('should be defined', () => { + expect(getLunarEquatorialCoordinate).toBeDefined() + }) + + it('should return the correct Lunar equatorial coordinate for the given date', () => { + const datetime = new Date('2015-01-02T03:00:00.000+00:00') + const { ra, dec } = getLunarEquatorialCoordinate(datetime) + expect(ra).toBe(63.85408978307256) + expect(dec).toBe(17.246094608898055) + }) +}) + +/*****************************************************************************************************************/