Skip to content

Commit

Permalink
Merge pull request #92 from observerly/feature/moon/getLunarEquatoria…
Browse files Browse the repository at this point in the history
…lCoordinate

feat: Added getLunarEquatorialCoordinate() to moon module in @observerly/astrometry.
  • Loading branch information
michealroberts authored Aug 31, 2023
2 parents d5a5829 + 560da09 commit 79ad56a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
47 changes: 46 additions & 1 deletion src/moon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

/*****************************************************************************************************************/

import { type EclipticCoordinate } from './common'
import { getObliquityOfTheEcliptic } from './astrometry'

import { type EclipticCoordinate, type EquatorialCoordinate } from './common'

import { getJulianDate } from './epoch'

Expand Down Expand Up @@ -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
}
}

/*****************************************************************************************************************/
18 changes: 17 additions & 1 deletion tests/moon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
getLunarCorrectedEclipticLongitudeOfTheAscendingNode,
getLunarEclipticLongitude,
getLunarEclipticLatitude,
getLunarEclipticCoordinate
getLunarEclipticCoordinate,
getLunarEquatorialCoordinate
} from '../src'

/*****************************************************************************************************************/
Expand Down Expand Up @@ -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)
})
})

/*****************************************************************************************************************/

0 comments on commit 79ad56a

Please sign in to comment.