Skip to content

Commit

Permalink
Updated Ecliptic to return ECL in all languages.
Browse files Browse the repository at this point in the history
  • Loading branch information
cosinekitty committed Dec 11, 2022
1 parent d4660de commit 1a4f842
Show file tree
Hide file tree
Showing 29 changed files with 324 additions and 260 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</td>
<td style="text-align: center;"><a href="demo/c/">Examples</a></td>
<td style="text-align: center;">
<div><a href="source/c/"><img src="https://img.shields.io/badge/C%20%2f%20C%2b%2b-v2.1.12-blue" /></a></div>
<div><a href="source/c/"><img src="https://img.shields.io/badge/C%20%2f%20C%2b%2b-v2.1.13-blue" /></a></div>
<div><a href="source/c/">Code &amp; Docs</a></div>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion demo/java/correct/lunar_eclipse.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
1988-08-27T12:01:33.171Z Partial eclipse ends.

1989-02-20T13:43:24.717Z Partial eclipse begins.
1989-02-20T14:55:34.838Z Total eclipse begins.
1989-02-20T14:55:34.839Z Total eclipse begins.
1989-02-20T15:35:19.955Z Peak of total eclipse.
1989-02-20T16:15:05.072Z Total eclipse ends.
1989-02-20T17:27:15.193Z Partial eclipse ends.
Expand Down
20 changes: 10 additions & 10 deletions demo/java/correct/moonphase.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
2019-06-15T09:15:32.987Z : Moon's illuminated fraction = 95.63%.

The next 10 lunar quarters are:
2019-06-17T08:31:17.934Z : Full Moon
2019-06-25T09:47:07.624Z : Third Quarter
2019-07-02T19:16:46.550Z : New Moon
2019-07-09T10:55:28.848Z : First Quarter
2019-07-16T21:38:53.690Z : Full Moon
2019-07-25T01:18:42.696Z : Third Quarter
2019-08-01T03:12:26.151Z : New Moon
2019-08-07T17:31:35.716Z : First Quarter
2019-08-15T12:29:57.164Z : Full Moon
2019-08-23T14:56:46.202Z : Third Quarter
2019-06-17T08:31:17.942Z : Full Moon
2019-06-25T09:47:05.866Z : Third Quarter
2019-07-02T19:16:46.599Z : New Moon
2019-07-09T10:55:27.398Z : First Quarter
2019-07-16T21:38:53.592Z : Full Moon
2019-07-25T01:18:41.310Z : Third Quarter
2019-08-01T03:12:25.793Z : New Moon
2019-08-07T17:31:34.799Z : First Quarter
2019-08-15T12:29:56.276Z : Full Moon
2019-08-23T14:56:45.684Z : Third Quarter
2 changes: 1 addition & 1 deletion demo/kotlin/correct/lunar_eclipse.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
1988-08-27T12:01:33.171Z Partial eclipse ends.

1989-02-20T13:43:24.717Z Partial eclipse begins.
1989-02-20T14:55:34.838Z Total eclipse begins.
1989-02-20T14:55:34.839Z Total eclipse begins.
1989-02-20T15:35:19.955Z Peak of total eclipse.
1989-02-20T16:15:05.072Z Total eclipse ends.
1989-02-20T17:27:15.193Z Partial eclipse ends.
Expand Down
20 changes: 10 additions & 10 deletions demo/kotlin/correct/moonphase.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
2019-06-15T09:15:32.987Z : Moon's illuminated fraction = 95.63%.

The next 10 lunar quarters are:
2019-06-17T08:31:17.934Z : Full Moon
2019-06-25T09:47:07.624Z : Third Quarter
2019-07-02T19:16:46.550Z : New Moon
2019-07-09T10:55:28.848Z : First Quarter
2019-07-16T21:38:53.690Z : Full Moon
2019-07-25T01:18:42.696Z : Third Quarter
2019-08-01T03:12:26.151Z : New Moon
2019-08-07T17:31:35.716Z : First Quarter
2019-08-15T12:29:57.164Z : Full Moon
2019-08-23T14:56:46.202Z : Third Quarter
2019-06-17T08:31:17.942Z : Full Moon
2019-06-25T09:47:05.866Z : Third Quarter
2019-07-02T19:16:46.599Z : New Moon
2019-07-09T10:55:27.398Z : First Quarter
2019-07-16T21:38:53.592Z : Full Moon
2019-07-25T01:18:41.310Z : Third Quarter
2019-08-01T03:12:25.793Z : New Moon
2019-08-07T17:31:34.799Z : First Quarter
2019-08-15T12:29:56.276Z : Full Moon
2019-08-23T14:56:45.684Z : Third Quarter
30 changes: 20 additions & 10 deletions demo/python/astronomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5084,34 +5084,44 @@ def SunPosition(time):
true_obliq = math.radians(adjusted_time._etilt().tobl)
return _RotateEquatorialToEcliptic(sun_ofdate, true_obliq, time)

def Ecliptic(equ):
"""Converts J2000 equatorial Cartesian coordinates to J2000 ecliptic coordinates.
def Ecliptic(eqj):
"""Converts a J2000 mean equator (EQJ) vector to a true ecliptic of date (ETC) vector and angles.
Given coordinates relative to the Earth's equator at J2000 (the instant of noon UTC
on 1 January 2000), this function converts those coordinates to J2000 ecliptic coordinates,
on 1 January 2000), this function converts those coordinates to true ecliptic coordinates of date,
which are relative to the plane of the Earth's orbit around the Sun.
Parameters
----------
equ : Equatorial
eqj : Equatorial
Equatorial coordinates in the J2000 frame of reference.
You can call #GeoVector to obtain suitable equatorial coordinates.
Returns
-------
EclipticCoordinates
Ecliptic coordinates in the J2000 frame of reference.
Spherical and vector coordinates expressed in true ecliptic coordinates of date (ECT).
"""
# Based on NOVAS functions equ2ecl() and equ2ecl_vec().
ob2000 = 0.40909260059599012 # mean obliquity of the J2000 ecliptic in radians
return _RotateEquatorialToEcliptic([equ.x, equ.y, equ.z], ob2000, equ.t)
# Calculate nutation and obliquity for this time.
# As an optimization, the nutation angles are cached in `eqj.t`,
# and reused below when the `nutation` function is called.
et = _e_tilt(eqj.t)

# Convert J2000 mean equator (EQJ) to true equator of date (EQD).
mean_pos = _precession([eqj.x, eqj.y, eqj.z], eqj.t, _PrecessDir.From2000)
eqd_pos = _nutation(mean_pos, eqj.t, _PrecessDir.From2000)

# Rotate from EQD to true ecliptic of date (ECT).
return _RotateEquatorialToEcliptic(eqd_pos, math.radians(et.tobl), eqj.t)


def EclipticLongitude(body, time):
"""Calculates heliocentric ecliptic longitude of a body based on the J2000 equinox.
"""Calculates heliocentric ecliptic longitude of a body.
This function calculates the angle around the plane of the Earth's orbit
of a celestial body, as seen from the center of the Sun.
The angle is measured prograde (in the direction of the Earth's orbit around the Sun)
in degrees from the J2000 equinox. The ecliptic longitude is always in the range [0, 360).
in degrees from the true equinox of date. The ecliptic longitude is always in the range [0, 360).
Parameters
----------
Expand Down
154 changes: 77 additions & 77 deletions demo/python/correct/lunar_angles.txt
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
2021-05-15T01:45:15.502Z Jupiter 120
2021-05-15T17:53:54.557Z Venus 30
2021-05-16T04:23:24.323Z Saturn 150
2021-05-16T05:06:25.856Z Mars 0
2021-05-16T12:51:08.386Z Mercury 30
2021-05-17T06:05:46.557Z Sun 60
2021-05-17T13:28:34.314Z Jupiter 150
2021-05-18T10:43:24.043Z Venus 60
2021-05-18T14:28:31.705Z Saturn 180
2021-05-18T18:01:40.367Z Mars 30
2021-05-19T02:55:48.293Z Mercury 60
2021-05-19T19:13:17.318Z Sun 90
2021-05-19T22:06:38.821Z Jupiter 180
2021-05-20T21:07:44.292Z Saturn 210
2021-05-20T23:01:26.198Z Venus 90
2021-05-21T02:57:43.803Z Mars 60
2021-05-21T11:47:54.388Z Mercury 90
2021-05-22T02:58:57.125Z Jupiter 210
2021-05-22T03:46:48.175Z Sun 120
2021-05-23T00:10:42.249Z Saturn 240
2021-05-23T06:36:37.117Z Venus 120
2021-05-23T07:51:25.441Z Mars 90
2021-05-23T15:59:55.611Z Mercury 120
2021-05-24T04:37:03.217Z Jupiter 240
2021-05-24T08:28:12.625Z Sun 150
2021-05-25T00:34:55.763Z Saturn 270
2021-05-25T10:01:10.928Z Mars 120
2021-05-25T11:01:14.731Z Venus 150
2021-05-25T17:13:39.257Z Mercury 150
2021-05-26T04:29:33.492Z Jupiter 270
2021-05-26T11:14:24.846Z Sun 180
2021-05-27T00:00:58.503Z Saturn 300
2021-05-27T11:31:13.830Z Mars 150
2021-05-27T14:43:34.085Z Venus 180
2021-05-27T17:36:05.800Z Mercury 180
2021-05-28T04:30:48.514Z Jupiter 300
2021-05-28T14:32:15.606Z Sun 210
2021-05-29T00:23:12.944Z Saturn 330
2021-05-29T14:36:19.185Z Mars 180
2021-05-29T19:07:06.445Z Mercury 210
2021-05-29T20:23:23.051Z Venus 210
2021-05-30T06:34:02.076Z Jupiter 330
2021-05-30T20:43:28.840Z Sun 240
2021-05-31T03:24:49.116Z Saturn 0
2021-05-31T21:11:00.051Z Mars 210
2021-05-31T23:13:57.679Z Mercury 240
2021-06-01T06:14:14.724Z Venus 240
2021-06-01T12:03:46.946Z Jupiter 0
2021-06-02T07:25:04.037Z Sun 270
2021-06-02T10:08:01.205Z Saturn 30
2021-06-03T06:24:41.602Z Mercury 270
2021-06-03T08:08:58.541Z Mars 240
2021-06-03T21:09:24.870Z Venus 270
2021-06-03T21:22:13.482Z Jupiter 30
2021-06-04T20:23:38.951Z Saturn 60
2021-06-04T22:38:31.597Z Sun 300
2021-06-05T15:57:17.165Z Mercury 300
2021-06-05T22:47:34.963Z Mars 270
2021-06-06T09:32:04.351Z Jupiter 60
2021-06-06T15:57:32.038Z Venus 300
2021-06-07T08:51:04.866Z Saturn 90
2021-06-07T16:37:11.606Z Sun 330
2021-06-08T02:27:50.910Z Mercury 330
2021-06-08T15:07:18.196Z Mars 300
2021-06-08T22:47:03.995Z Jupiter 90
2021-06-09T12:02:10.026Z Venus 330
2021-06-09T21:43:15.335Z Saturn 120
2021-06-10T10:53:20.688Z Sun 0
2021-06-10T12:38:05.006Z Mercury 0
2021-06-11T07:02:57.519Z Mars 330
2021-06-11T11:27:40.113Z Jupiter 120
2021-06-12T06:59:51.615Z Venus 0
2021-06-12T09:34:14.801Z Saturn 150
2021-06-12T21:38:19.168Z Mercury 30
2021-06-13T03:33:36.529Z Sun 30
2021-06-13T21:08:06.755Z Mars 0
2021-06-13T22:26:26.447Z Jupiter 150
2021-05-15T01:45:15.706Z Jupiter 120
2021-05-15T17:53:54.314Z Venus 30
2021-05-16T04:23:24.170Z Saturn 150
2021-05-16T05:06:25.682Z Mars 0
2021-05-16T12:51:07.810Z Mercury 30
2021-05-17T06:05:45.825Z Sun 60
2021-05-17T13:28:33.770Z Jupiter 150
2021-05-18T10:43:22.784Z Venus 60
2021-05-18T14:28:30.696Z Saturn 180
2021-05-18T18:01:39.264Z Mars 30
2021-05-19T02:55:46.814Z Mercury 60
2021-05-19T19:13:15.714Z Sun 90
2021-05-19T22:06:37.540Z Jupiter 180
2021-05-20T21:07:42.837Z Saturn 210
2021-05-20T23:01:24.412Z Venus 90
2021-05-21T02:57:42.297Z Mars 60
2021-05-21T11:47:52.705Z Mercury 90
2021-05-22T02:58:55.870Z Jupiter 210
2021-05-22T03:46:46.605Z Sun 120
2021-05-23T00:10:41.162Z Saturn 240
2021-05-23T06:36:35.859Z Venus 120
2021-05-23T07:51:24.443Z Mars 90
2021-05-23T15:59:54.578Z Mercury 120
2021-05-24T04:37:02.655Z Jupiter 240
2021-05-24T08:28:11.867Z Sun 150
2021-05-25T00:34:55.447Z Saturn 270
2021-05-25T10:01:10.768Z Mars 120
2021-05-25T11:01:14.390Z Venus 150
2021-05-25T17:13:39.027Z Mercury 150
2021-05-26T04:29:33.608Z Jupiter 270
2021-05-26T11:14:24.797Z Sun 180
2021-05-27T00:00:58.651Z Saturn 300
2021-05-27T11:31:14.024Z Mars 150
2021-05-27T14:43:34.090Z Venus 180
2021-05-27T17:36:05.802Z Mercury 180
2021-05-28T04:30:48.680Z Jupiter 300
2021-05-28T14:32:15.449Z Sun 210
2021-05-29T00:23:12.823Z Saturn 330
2021-05-29T14:36:18.888Z Mars 180
2021-05-29T19:07:05.905Z Mercury 210
2021-05-29T20:23:22.440Z Venus 210
2021-05-30T06:34:01.580Z Jupiter 330
2021-05-30T20:43:27.790Z Sun 240
2021-05-31T03:24:48.177Z Saturn 0
2021-05-31T21:10:58.832Z Mars 210
2021-05-31T23:13:56.300Z Mercury 240
2021-06-01T06:14:13.103Z Venus 240
2021-06-01T12:03:45.645Z Jupiter 0
2021-06-02T07:25:02.187Z Sun 270
2021-06-02T10:07:59.646Z Saturn 30
2021-06-03T06:24:39.897Z Mercury 270
2021-06-03T08:08:56.940Z Mars 240
2021-06-03T21:09:23.029Z Venus 270
2021-06-03T21:22:12.060Z Jupiter 30
2021-06-04T20:23:37.640Z Saturn 60
2021-06-04T22:38:30.011Z Sun 300
2021-06-05T15:57:16.003Z Mercury 300
2021-06-05T22:47:34.042Z Mars 270
2021-06-06T09:32:03.690Z Jupiter 60
2021-06-06T15:57:31.165Z Venus 300
2021-06-07T08:51:04.462Z Saturn 90
2021-06-07T16:37:11.096Z Sun 330
2021-06-08T02:27:50.634Z Mercury 330
2021-06-08T15:07:18.273Z Mars 300
2021-06-08T22:47:04.179Z Jupiter 90
2021-06-09T12:02:10.110Z Venus 330
2021-06-09T21:43:15.531Z Saturn 120
2021-06-10T10:53:20.717Z Sun 0
2021-06-10T12:38:05.109Z Mercury 0
2021-06-11T07:02:57.745Z Mars 330
2021-06-11T11:27:40.329Z Jupiter 120
2021-06-12T06:59:51.450Z Venus 0
2021-06-12T09:34:14.672Z Saturn 150
2021-06-12T21:38:18.839Z Mercury 30
2021-06-13T03:33:35.931Z Sun 30
2021-06-13T21:08:06.168Z Mars 0
2021-06-13T22:26:25.894Z Jupiter 150
2 changes: 1 addition & 1 deletion demo/python/correct/lunar_eclipse.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
1989-02-20T13:43:24.718Z Partial eclipse begins.
1989-02-20T14:55:34.839Z Total eclipse begins.
1989-02-20T15:35:19.956Z Peak of total eclipse.
1989-02-20T16:15:05.072Z Total eclipse ends.
1989-02-20T16:15:05.073Z Total eclipse ends.
1989-02-20T17:27:15.194Z Partial eclipse ends.

1989-08-17T01:20:43.868Z Partial eclipse begins.
Expand Down
20 changes: 10 additions & 10 deletions demo/python/correct/moonphase.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
2019-06-15T09:15:32.987Z : Moon's illuminated fraction = 95.63%.

The next 10 lunar quarters are:
2019-06-17T08:31:17.934Z : Full Moon
2019-06-25T09:47:07.624Z : Third Quarter
2019-07-02T19:16:46.550Z : New Moon
2019-07-09T10:55:28.849Z : First Quarter
2019-07-16T21:38:53.691Z : Full Moon
2019-07-25T01:18:42.697Z : Third Quarter
2019-08-01T03:12:26.152Z : New Moon
2019-08-07T17:31:35.717Z : First Quarter
2019-08-15T12:29:57.164Z : Full Moon
2019-08-23T14:56:46.202Z : Third Quarter
2019-06-17T08:31:17.943Z : Full Moon
2019-06-25T09:47:05.867Z : Third Quarter
2019-07-02T19:16:46.600Z : New Moon
2019-07-09T10:55:27.398Z : First Quarter
2019-07-16T21:38:53.593Z : Full Moon
2019-07-25T01:18:41.310Z : Third Quarter
2019-08-01T03:12:25.793Z : New Moon
2019-08-07T17:31:34.799Z : First Quarter
2019-08-15T12:29:56.277Z : Full Moon
2019-08-23T14:56:45.685Z : Third Quarter
2 changes: 1 addition & 1 deletion generate/ctest.c
Original file line number Diff line number Diff line change
Expand Up @@ -3576,7 +3576,7 @@ static int EclipticTest(void)
if (max_vec_diff > 3.388e-18)
FAIL("C EclipticTest: EXCESSIVE VECTOR DIFF = %0.6le AU.\n", max_vec_diff);

DEBUG("C EclipticTest: PASS: count = %d, max_vec_diff = %0.6le AU, max_angle_diff = %0.6le AU.\n", count, max_vec_diff, max_angle_diff);
printf("C EclipticTest: PASS: count = %d, max_vec_diff = %0.6le AU, max_angle_diff = %0.6le AU.\n", count, max_vec_diff, max_angle_diff);
error = 0;
fail:
return error;
Expand Down
2 changes: 1 addition & 1 deletion generate/dotnet/csharp_test/csharp_test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2202,7 +2202,7 @@ static int EclipticTest()
if (max_vec_diff > 3.743e-18)
return Fail($"EclipticTest: EXCESSIVE VECTOR DIFF = {max_vec_diff:G6} AU.");

Debug($"C# EclipticTest: PASS: count = {count}, max_diff = {max_vec_diff:G6} AU, max_angle_diff = {max_angle_diff:G6} AU.");
Console.WriteLine($"C# EclipticTest: PASS: count = {count}, max_diff = {max_vec_diff:G6} AU, max_angle_diff = {max_angle_diff:G6} AU.");
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion generate/template/astronomy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5428,7 +5428,7 @@ private static Ecliptic RotateEquatorialToEcliptic(AstroVector pos, double obliq
public static Ecliptic EquatorialToEcliptic(AstroVector eqj)
{
// Calculate nutation and obliquity for this time.
// As an optimization, the nutation angles are cached in `time`,
// As an optimization, the nutation angles are cached in `eqj.t`,
// and reused below when the `nutation` function is called.
earth_tilt_t et = e_tilt(eqj.t);

Expand Down
29 changes: 18 additions & 11 deletions generate/template/astronomy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5462,12 +5462,12 @@ fun horizon(


/**
* Calculates heliocentric ecliptic longitude of a body based on the J2000 equinox.
* Calculates heliocentric ecliptic longitude of a body.
*
* This function calculates the angle around the plane of the Earth's orbit
* of a celestial body, as seen from the center of the Sun.
* The angle is measured prograde (in the direction of the Earth's orbit around the Sun)
* in degrees from the J2000 equinox. The ecliptic longitude is always in the range [0, 360).
* in degrees from the true equinox of date. The ecliptic longitude is always in the range [0, 360).
*
* @param body
* A body other than the Sun.
Expand Down Expand Up @@ -5965,23 +5965,30 @@ private fun rotateEquatorialToEcliptic(pos: Vector, obliqRadians: Double): Eclip
}

/**
* Converts J2000 equatorial Cartesian coordinates to J2000 ecliptic coordinates.
* Converts a J2000 mean equator (EQJ) vector to a true ecliptic of date (ETC) vector and angles.
*
* Given coordinates relative to the Earth's equator at J2000 (the instant of noon UTC
* on 1 January 2000), this function converts those coordinates to J2000 ecliptic coordinates,
* on 1 January 2000), this function converts those coordinates to true ecliptic coordinates of date,
* which are relative to the plane of the Earth's orbit around the Sun.
*
* @param equ
* @param eqj
* Equatorial coordinates in the J2000 frame of reference.
* You can call [geoVector] to obtain suitable equatorial coordinates.
*
* @return Ecliptic coordinates in the J2000 frame of reference (ECL).
* @return Spherical and vector coordinates expressed in true ecliptic coordinates of date (ECT)..
*/
fun equatorialToEcliptic(equ: Vector): Ecliptic =
rotateEquatorialToEcliptic(
equ,
0.40909260059599012 // mean obliquity of the J2000 ecliptic in radians
)
fun equatorialToEcliptic(eqj: Vector): Ecliptic {
// Calculate nutation and obliquity for this time.
// As an optimization, the nutation angles are cached in `eqj.t`,
// and reused below when the `nutation` function is called.
val et = earthTilt(eqj.t)

// Convert J2000 mean equator (EQJ) to true equator of date (EQD).
val eqd = gyration(eqj, PrecessDirection.From2000);

// Rotate from EQD to true ecliptic of date (ECT).
return rotateEquatorialToEcliptic(eqd, et.tobl.degreesToRadians())
}

/**
* Searches for the time when the Sun reaches an apparent ecliptic longitude as seen from the Earth.
Expand Down
Loading

0 comments on commit 1a4f842

Please sign in to comment.