Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added getLunarEclipticCoordinate() to moon module in @observerly/astrometry. #90

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
})

/*****************************************************************************************************************/
Loading