Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ConvertEquatorialToHorizontalCoordinate(datetime time.Time) to coordinates module in @observerly/sidera. #29

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
41 changes: 41 additions & 0 deletions pkg/coordinates/coordinates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

/*****************************************************************************************************************/
24 changes: 24 additions & 0 deletions pkg/coordinates/coordinates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}

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