From 07cc6e86982fda4c7e0d12bcac171d483286cc2d Mon Sep 17 00:00:00 2001 From: "Michael J. Roberts" <84131395+michealroberts@users.noreply.github.com> Date: Mon, 28 Aug 2023 15:55:14 +0100 Subject: [PATCH] feat: Added getBodyTransit() to transit module in @observerly/astrometry. feat: Added getBodyTransit() to transit module in @observerly/astrometry. Includes associated test suite and expected API output. --- src/transit.ts | 66 ++++++++++++++++++++++++++++++++++++++++++- tests/transit.spec.ts | 32 ++++++++++++++++++--- 2 files changed, 93 insertions(+), 5 deletions(-) diff --git a/src/transit.ts b/src/transit.ts index fb4b28d..b4b0fd0 100644 --- a/src/transit.ts +++ b/src/transit.ts @@ -15,7 +15,11 @@ import { } from './common' import { convertEquatorialToHorizontal } from './coordinates' -import { getNormalizedInclinationDegree, convertDegreesToRadians as radians } from './utilities' +import { + getNormalizedInclinationDegree, + convertDegreesToRadians as radians, + convertRadiansToDegrees as degrees +} from './utilities' /*****************************************************************************************************************/ @@ -211,3 +215,63 @@ export const doesBodyRiseOrSet = ( } /*****************************************************************************************************************/ + +/** + * + * getBodyTransit() + * + * Determines the local sidereal time and azimuthal angle of rise and set for an object. + * + * @param observer - The geographic coordinate of the observer. + * @param target - The equatorial or horizontal coordinate of the observed object. + * @returns the transit for the body, or undefined if the body never rises or sets for the observer. + * + */ +export const getBodyTransit = ( + observer: GeographicCoordinate, + target: EquatorialCoordinate +): Transit | undefined => { + // Convert the right ascension to hours: + const ra = target.ra / 15 + + // Get the transit parameters: + const body = doesBodyRiseOrSet(observer, target) + + if (!body) { + return undefined + } + + // Extract the transit parameters from the body: + const { H1, Ar } = body + + const H2 = degrees(Math.acos(-H1)) / 15 + + // Get the azimuthal angle of rise: + const R = degrees(Math.acos(Ar)) + + // Get the azimuthal angle of set: + const S = 360 - R + + // The local sidereal time of rise: + let LSTr = 24 + ra - H2 + + if (LSTr > 24) { + LSTr -= 24 + } + + // The local sidereal time of set: + let LSTs = ra + H2 + + if (LSTs > 24) { + LSTs -= 24 + } + + return { + LSTr, + LSTs, + R, + S + } +} + +/*****************************************************************************************************************/ diff --git a/tests/transit.spec.ts b/tests/transit.spec.ts index 7da6a6a..9106f5d 100644 --- a/tests/transit.spec.ts +++ b/tests/transit.spec.ts @@ -15,7 +15,8 @@ import { isBodyCircumpolar, isBodyVisible, isBodyAboveHorizon, - doesBodyRiseOrSet + doesBodyRiseOrSet, + getBodyTransit } from '../src' /*****************************************************************************************************************/ @@ -34,7 +35,7 @@ export const longitude = -155.468094 const polaris: EquatorialCoordinate = { ra: 37.95456, dec: 89.264108 } // For testing -const betelgeuse: EquatorialCoordinate = { ra: 5.919529, dec: 7.407064 } +const betelgeuse: EquatorialCoordinate = { ra: 88.7929583, dec: 7.4070639 } // For testings const sigmaOctantis: EquatorialCoordinate = { ra: 21.07875, dec: -88.9569444 } @@ -266,8 +267,8 @@ describe('doesBodyRiseOrSet', () => { betelgeuse ) ).toEqual({ - Ar: 0.13703603027752978, - H1: 0.04685668461549029 + Ar: 0.13703602843777568, + H1: 0.04685668397579211 }) }) @@ -285,3 +286,26 @@ describe('doesBodyRiseOrSet', () => { }) /*****************************************************************************************************************/ + +describe('getBodyTransit', () => { + it('should be defined', () => { + expect(getBodyTransit).toBeDefined() + }) + + it('should return transit parameters for a northerm hemisphere object for a postive latitude', () => { + const { LSTr, LSTs, R, S } = getBodyTransit( + { + latitude, + longitude + }, + betelgeuse + ) + + expect(LSTr).toBe(23.740485646638913) + expect(LSTs).toBe(12.098575460027751) + expect(R).toBeCloseTo(82.12362992591511) + expect(S).toBeCloseTo(277.8763700740849) + }) +}) + +/*****************************************************************************************************************/