Skip to content

Commit

Permalink
Merge pull request #31 from observerly/feature/solar/GetHorizontalCoo…
Browse files Browse the repository at this point in the history
…rdinate

feat: add GetHorizontalCoordinate(datetime time.Time, ...) to coordinates module in @observerly/sidera.
  • Loading branch information
michealroberts authored May 3, 2024
2 parents 67a91c3 + b0c79a3 commit 3680576
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
26 changes: 24 additions & 2 deletions pkg/solar/sun.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/*****************************************************************************************************************/
27 changes: 27 additions & 0 deletions pkg/solar/sun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
}
}

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

0 comments on commit 3680576

Please sign in to comment.