diff --git a/pkg/solar/sun.go b/pkg/solar/sun.go index 7e4bfa5..4276917 100644 --- a/pkg/solar/sun.go +++ b/pkg/solar/sun.go @@ -143,10 +143,32 @@ Sun's position relative to the vernal equinox and calculate the time of sunrise, */ func GetEquatorialCoordinate(datetime time.Time) common.EquatorialCoordinate { // get the solar ecliptic coordinate: - ecliptic := GetEclipticCoordinate(datetime) + ec := GetEclipticCoordinate(datetime) // convert the solar ecliptic coordinate to the solar equatorial coordinate: - return coordinates.ConvertEclipticToEquatorialCoordinate(datetime, ecliptic) + return coordinates.ConvertEclipticToEquatorialCoordinate(datetime, ec) +} + +/*****************************************************************************************************************/ + +/* +the Horizontal Coordinate of the Sun for a given datetime + +The Solar Horizontal Coordinate is the position of the Sun in the sky relative to the observer's local horizon. + +The Solar Horizontal Coordinate is an important concept in solar astronomy, as it is used to calculate the position +of the Sun in the sky at any given time. By knowing the Solar Horizontal Coordinate, an observer can determine the +Sun's position relative to the vernal equinox and calculate the time of sunrise, sunset, and other solar events. +*/ +func GetHorizontalCoordinate( + datetime time.Time, + observer common.GeographicCoordinate, +) common.HorizontalCoordinate { + // get the solar equatorial coordinate: + eq := GetEquatorialCoordinate(datetime) + + // convert the solar equatorial coordinate to the solar horizontal coordinate: + return coordinates.ConvertEquatorialToHorizontalCoordinate(datetime, observer, eq) } /*****************************************************************************************************************/ diff --git a/pkg/solar/sun_test.go b/pkg/solar/sun_test.go index 55234a9..a653e12 100644 --- a/pkg/solar/sun_test.go +++ b/pkg/solar/sun_test.go @@ -25,6 +25,14 @@ 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, +} + +/*****************************************************************************************************************/ + func TestGetSolarMeanAnomaly(t *testing.T) { var got float64 = GetMeanAnomaly(datetime) @@ -94,3 +102,22 @@ func TestSolarEquatorialCoordinate(t *testing.T) { } /*****************************************************************************************************************/ + +func TestSolarHorizontalCoordinate(t *testing.T) { + var got = GetHorizontalCoordinate(datetime, observer) + + var want = common.HorizontalCoordinate{ + Azimuth: 271.018685, + Altitude: 72.7850383767226, + } + + if got.Azimuth-want.Azimuth > 0.0001 { + t.Errorf("got %f, wanted %f", got.Azimuth, want.Azimuth) + } + + if got.Altitude-want.Altitude > 0.0001 { + t.Errorf("got %f, wanted %f", got.Altitude, want.Altitude) + } +} + +/*****************************************************************************************************************/