From a121c703ee5549b3e77be5ff6cc4f29fae0a3be6 Mon Sep 17 00:00:00 2001 From: "Michael J. Roberts" Date: Thu, 2 May 2024 16:39:34 +0100 Subject: [PATCH] feat: add ConvertEquatorialToHorizontalCoordinate(datetime time.Time) to coordinates module in @observerly/sidera. feat: add ConvertEquatorialToHorizontalCoordinate(datetime time.Time) to coordinates module in @observerly/sidera. --- pkg/coordinates/coordinates.go | 41 +++++++++++++++++++++++++++++ pkg/coordinates/coordinates_test.go | 24 +++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/pkg/coordinates/coordinates.go b/pkg/coordinates/coordinates.go index dfb2df2..bb9d755 100644 --- a/pkg/coordinates/coordinates.go +++ b/pkg/coordinates/coordinates.go @@ -57,3 +57,44 @@ func ConvertEclipticToEquatorialCoordinate( } /*****************************************************************************************************************/ + +/* +converts equatorial to horizontal coordinates + +The equatorial coordinate system is a celestial coordinate system widely used to specify the positions of +celestial objects. It may be implemented in spherical or rectangular coordinates, both defined by an +origin at the center of Earth, a fundamental plane consisting of the projection of Earth's equator onto +the celestial sphere (forming the celestial equator), a primary direction towards the vernal equinox, + +The horizontal coordinate system is a celestial coordinate system that uses the observer's local horizon +as the fundamental plane. The horizontal coordinate system is widely used in astronomy to specify the +positions of celestial objects in the sky. +*/ +func ConvertEquatorialToHorizontalCoordinate( + datetime time.Time, + observer common.GeographicCoordinate, + target common.EquatorialCoordinate, +) (horizontal common.HorizontalCoordinate) { + δ := common.Radians(target.Declination) + + φ := common.Radians(observer.Latitude) + + ha := common.Radians(astrometry.GetHourAngle(datetime, observer, target)) + + // calculate the altitude in radians. + alt := math.Asin(math.Sin(δ)*math.Sin(φ) + math.Cos(δ)*math.Cos(φ)*math.Cos(ha)) + + // calculate the azimuth in radians. + az := common.Degrees(math.Acos((math.Sin(δ) - math.Sin(alt)*math.Sin(φ)) / (math.Cos(alt) * math.Cos(φ)))) + + if math.Sin(ha) > 0 { + az = 360 - az + } + + return common.HorizontalCoordinate{ + Azimuth: math.Mod(az, 360), + Altitude: common.Degrees(alt), + } +} + +/*****************************************************************************************************************/ diff --git a/pkg/coordinates/coordinates_test.go b/pkg/coordinates/coordinates_test.go index 4702815..2cc5306 100644 --- a/pkg/coordinates/coordinates_test.go +++ b/pkg/coordinates/coordinates_test.go @@ -23,6 +23,21 @@ var datetime time.Time = time.Date(2021, 5, 14, 0, 0, 0, 0, time.UTC) /*****************************************************************************************************************/ +var observer common.GeographicCoordinate = common.GeographicCoordinate{ + Latitude: 19.8207, + Longitude: -155.468094, + Elevation: 4205, +} + +/*****************************************************************************************************************/ + +var betelgeuse common.EquatorialCoordinate = common.EquatorialCoordinate{ + RightAscension: 88.7929583, + Declination: 7.4070639, +} + +/*****************************************************************************************************************/ + func TestConvertEclipticToEquatorialCoordinate(t *testing.T) { venus := common.EclipticCoordinate{ Longitude: 245.79403406596947, @@ -36,3 +51,12 @@ func TestConvertEclipticToEquatorialCoordinate(t *testing.T) { } /*****************************************************************************************************************/ + +func TestConvertEquatorialToHorizontalCoordinate(t *testing.T) { + hz := ConvertEquatorialToHorizontalCoordinate(datetime, observer, betelgeuse) + + assert.Equal(t, hz.Altitude, 72.7850383767226) + assert.Equal(t, hz.Azimuth, 134.4479059877678) +} + +/*****************************************************************************************************************/