Skip to content

Commit

Permalink
Merge pull request #27 from observerly/feature/coordinates/ConvertEcl…
Browse files Browse the repository at this point in the history
…ipticToEquatorial

feat: add ConvertEclipticToEquatorialCoordinate(datetime time.Time) to coordinates module in @observerly/sidera.
  • Loading branch information
michealroberts authored May 2, 2024
2 parents f865a2c + 9d128f5 commit 2ee47ec
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
59 changes: 59 additions & 0 deletions pkg/coordinates/coordinates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*****************************************************************************************************************/

// @author Michael Roberts <michael@observerly.com>
// @package @observerly/sidera
// @license Copyright © 2021-2024 observerly

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

package coordinates

import (
"math"
"time"

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

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

/*
converts ecliptic to equatorial 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,
and a right-handed convention.
The ecliptic coordinate system is a celestial coordinate system that uses the ecliptic for its fundamental
plane. The ecliptic is the plane of Earth's orbit around the Sun, and is defined by the projection of the
Earth's orbit onto the celestial sphere. The ecliptic coordinate system is widely used in astronomy to
specify the positions of celestial objects in the sky.
*/
func ConvertEclipticToEquatorialCoordinate(
datetime time.Time,
target common.EclipticCoordinate,
) (equatorial common.EquatorialCoordinate) {
ε := common.Radians(astrometry.GetObliquityOfTheEcliptic(datetime))

λ := common.Radians(target.Longitude)

β := common.Radians(target.Latitude)

α := common.Degrees(math.Atan2(math.Sin(λ)*math.Cos(ε)-math.Tan(β)*math.Sin(ε), math.Cos(λ)))

δ := common.Degrees(math.Asin(math.Sin(β)*math.Cos(ε) + math.Cos(β)*math.Sin(ε)*math.Sin(λ)))

if α < 0 {
α += 360
}

return common.EquatorialCoordinate{
RightAscension: math.Mod(α, 360),
Declination: δ,
}
}

/*****************************************************************************************************************/
38 changes: 38 additions & 0 deletions pkg/coordinates/coordinates_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*****************************************************************************************************************/

// @author Michael Roberts <michael@observerly.com>
// @package @observerly/sidera
// @license Copyright © 2021-2024 observerly

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

package coordinates

import (
"testing"
"time"

"github.com/observerly/sidera/pkg/common"
"github.com/stretchr/testify/assert"
)

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

// We define a datetime as some arbitrary date and time for testing purposes:
var datetime time.Time = time.Date(2021, 5, 14, 0, 0, 0, 0, time.UTC)

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

func TestConvertEclipticToEquatorialCoordinate(t *testing.T) {
venus := common.EclipticCoordinate{
Longitude: 245.79403406596947,
Latitude: 1.8937944394473665,
}

eq := ConvertEclipticToEquatorialCoordinate(datetime, venus)

assert.Equal(t, eq.RightAscension, 244.24810079259953)
assert.Equal(t, eq.Declination, -19.405047833538664)
}

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

0 comments on commit 2ee47ec

Please sign in to comment.