Skip to content

Commit

Permalink
Merge pull request #90 from observerly/feature/moon/getLunarEclipticC…
Browse files Browse the repository at this point in the history
…oordinate

feat: Added getLunarEclipticCoordinate() to moon module in @observerly/astrometry.
  • Loading branch information
michealroberts authored Aug 31, 2023
2 parents 124fe7d + ce35793 commit 8f8d043
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
46 changes: 46 additions & 0 deletions src/moon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

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

import { type EclipticCoordinate } from './common'

import { getJulianDate } from './epoch'

import { getSolarMeanAnomaly, getSolarEclipticLongitude } from './sun'
Expand Down Expand Up @@ -372,3 +374,47 @@ export const getLunarEclipticLatitude = (datetime: Date): number => {
}

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

/**
*
* getLunarEclipticCoordinate()
*
* The ecliptic coordinates for the Moon are the angles between the ecliptic 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 ecliptic coordinates for.
* @returns The Moon's ecliptic coordinates in degrees.
*
*/
export const getLunarEclipticCoordinate = (datetime: Date): EclipticCoordinate => {
// Get the true ecliptic longitude:
const λt = getLunarTrueEclipticLongitude(datetime)

// Get the corrected ecliptic longitude of the ascending node:
const Ωcorr = getLunarCorrectedEclipticLongitudeOfTheAscendingNode(datetime)

// Get the Moon's orbital inclination:
const ι = radians(5.1453964)

// Calculate the ecliptic longitude of the Moon (in degrees):
let λ =
(Ωcorr +
degrees(
Math.atan2(Math.sin(radians(λt - Ωcorr)) * Math.cos(ι), Math.cos(radians(λt - Ωcorr)))
)) %
360

// Correct for negative angles
if (λ < 0) {
λ += 360
}

// Calculate the ecliptic latitude of the Moon (in degrees):
const β = degrees(Math.asin(Math.sin(radians(λt - Ωcorr)) * Math.sin(ι)))

return { λ, β }
}

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

/*****************************************************************************************************************/
Expand Down Expand Up @@ -188,3 +189,17 @@ describe('getLunarEclipticLatitude', () => {
})

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

describe('getLunarEclipticCoordinate', () => {
it('should be defined', () => {
expect(getLunarEclipticCoordinate).toBeDefined()
})

it('should return the correct Lunar ecliptic coordinate for the given date', () => {
const { λ, β } = getLunarEclipticCoordinate(datetime)
expect(λ).toBe(76.99043727540315)
expect(β).toBe(0.48745043387361126)
})
})

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

0 comments on commit 8f8d043

Please sign in to comment.