-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from observerly/feature/coordinates/ConvertEcl…
…ipticToEquatorial feat: add ConvertEclipticToEquatorialCoordinate(datetime time.Time) to coordinates module in @observerly/sidera.
- Loading branch information
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: δ, | ||
} | ||
} | ||
|
||
/*****************************************************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
/*****************************************************************************************************************/ |