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 getPlanetaryHeliocentricEclipticLatitude() to planets module in @observerly/astrometry. #124

Merged
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
24 changes: 23 additions & 1 deletion src/planets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { J2000 } from './constants'

import { getJulianDate } from './epoch'

import { convertDegreesToRadians as radians } from './utilities'
import { convertDegreesToRadians as radians, convertRadiansToDegrees as degrees } from './utilities'

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

Expand Down Expand Up @@ -333,3 +333,25 @@ export const getPlanetaryHeliocentricEclipticLongitude = (
}

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

/**
*
* getPlanetaryHeliocentricEclipticLatitude()
*
* @param date - The date to calculate the Sun's mean anomaly for.
* @param planet - The planet to calculate the mean anomaly for.
* @returns a planet's heliocentric ecliptic latitude at a given datetime
*
*/
export const getPlanetaryHeliocentricEclipticLatitude = (
datetime: Date,
planet: Planet
): number => {
const L = getPlanetaryHeliocentricEclipticLongitude(datetime, planet)

const Ω = planet.Ω || 0

return degrees(Math.asin(Math.sin(radians(L - Ω)) * Math.sin(radians(planet.i)))) % 360
}

/*****************************************************************************************************************/
16 changes: 16 additions & 0 deletions tests/planets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getPlanetaryMeanAnomaly,
getPlanetaryTrueAnomaly,
getPlanetaryHeliocentricEclipticLongitude,
getPlanetaryHeliocentricEclipticLatitude,
planets
} from '../src'

Expand Down Expand Up @@ -86,3 +87,18 @@ describe('getPlanetaryHeliocentricEclipticLongitude', () => {
})

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

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

it('should return the correct value for Venus at the datetime prescribed', () => {
const venus = planets.find(planet => planet.name === 'Venus')
expect(venus).toBeDefined()
const Λ = getPlanetaryHeliocentricEclipticLatitude(new Date('2016-01-04T03:00:00+00:00'), venus)
expect(Λ).toBeCloseTo(3.119613)
})
})

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