Skip to content
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
28 changes: 28 additions & 0 deletions pkg/solar/sun.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"math"
"time"

"github.com/observerly/sidera/pkg/common"
"github.com/observerly/sidera/pkg/epoch"
)

Expand Down Expand Up @@ -47,3 +48,30 @@ func GetMeanAnomaly(datetime time.Time) float64 {
}

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

/*
the Equation of Center of the Sun for a given datetime

The Solar Equation of Center is the difference between the true anomaly of the Sun and its mean anomaly.

The Equation of Center 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 Equation of Center, 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 GetEquationOfCenter(datetime time.Time) float64 {
// get the Julian Date for the current epoch:
JD := epoch.GetJulianDate(datetime)

// calculate the number of centuries since J2000.0:
T := (JD - 2451545.0) / 36525

// get the solar mean anomaly:
M := GetMeanAnomaly(datetime)

// calculate the equation of center:
return (1.914602-0.004817*math.Pow(T, 2)-0.000014*math.Pow(T, 3))*math.Sin(common.Radians(M)) +
(0.019993-0.000101*math.Pow(T, 2))*math.Sin(2*common.Radians(M)) +
0.000289*math.Sin(3*common.Radians(M))
}

/*****************************************************************************************************************/
12 changes: 12 additions & 0 deletions pkg/solar/sun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,15 @@ func TestGetSolarMeanAnomaly(t *testing.T) {
}

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

func TestGetSolarEquationOfCenter(t *testing.T) {
var got float64 = GetEquationOfCenter(datetime)

var want float64 = 1.4754839423594457

if got-want > 0.0001 {
t.Errorf("got %f, wanted %f", got, want)
}
}

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