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 getSolarEclipticLongitude() to sun module in @observerly/astrometry. #47

Merged
merged 1 commit into from
Aug 21, 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
31 changes: 31 additions & 0 deletions src/sun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,34 @@ export const getSolarTrueGeometricLongitude = (datetime: Date): number => {
}

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

/**
*
* getSolarEclipticLongitude()
*
* The ecliptic longitude for the Sun is the angle between the perihelion and
* the current position of the Sun, as seen from the centre of the Earth,
* corrected for the equation of center and the Sun's ecliptic longitude at
* perigee at the epoch.
*
* @param date - The date to calculate the Sun's ecliptic longitude for.
* @returns The Sun's ecliptic longitude at the given date.
*
*/
export const getSolarEclipticLongitude = (datetime: Date): number => {
// Get the true anomaly:
const ν = getSolarTrueAnomaly(datetime)

// Correct the true anomaly with the Sun's ecliptic longitude
// at perigee at the epoch:
let λ = ν + (282.938346 % 360)

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

return λ
}

/*****************************************************************************************************************/
17 changes: 16 additions & 1 deletion tests/sun.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
getSolarEquationOfCenter,
getSolarMeanGeometricLongitude,
getSolarTrueAnomaly,
getSolarTrueGeometricLongitude
getSolarTrueGeometricLongitude,
getSolarEclipticLongitude
} from '../src'

/*****************************************************************************************************************/
Expand Down Expand Up @@ -90,3 +91,17 @@ describe('getSolarTrueGeometricLongitude', () => {
})

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

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

it('should return the correct Solar ecliptic longitude for the given date', () => {
const datetime = new Date('2015-02-05T12:00:00.000+00:00')
const λ = getSolarEclipticLongitude(datetime)
expect(λ).toBe(316.10388080739784)
})
})

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