Commit Graph

276 Commits

Author SHA1 Message Date
Don Cross
a5fd814ba1 Finished single-source-of-truth for Pluto constants.
The Pluto gravity simulator constants now come from
a single source: pluto_gravsim.h. This will allow me
to experiment with the Pluto state table to get a better
compromise between size and accuracy.
2021-11-12 15:30:56 -05:00
Don Cross
45ea0ea113 Fixed #131 - Added phase_fraction in C, C#.
The C and C# Illumination functions now return
a `phase_fraction` result to complement `phase_angle`.
This makes them consistent with the Python and JavaScript
versions.
2021-11-05 20:27:58 -04:00
Don Cross
296f23af76 Libration functions now calculate apparent angular diameter of the Moon.
All 4 languages have added a `diam_deg` field to the
structure returned by the Libration function.
It is the apparent angular diameter of the Moon as
seen from the center of the Earth, expressed in degrees.
2021-11-05 16:02:14 -04:00
Don Cross
c72dd30ada C# Libration implemented
C# Libration(../../libration/mooninfo_2020.txt): PASS (8785 test cases, max_diff_elon = 0.12984487564674296 arcmin, max_diff_elat = 1.665274961400911 arcmin, max_diff_distance = 52.860241484013386)
C# Libration(../../libration/mooninfo_2021.txt): PASS (8760 test cases, max_diff_elon = 0.10404742496932684 arcmin, max_diff_elat = 1.6466732189634214 arcmin, max_diff_distance = 53.88185173016973)

C Libration(libration/mooninfo_2020.txt): PASS (8785 test cases, max_diff_elon = 0.1298 arcmin, max_diff_elat = 1.6653 arcmin, max_diff_distance = 52.860 km)
C Libration(libration/mooninfo_2021.txt): PASS (8760 test cases, max_diff_elon = 0.1040 arcmin, max_diff_elat = 1.6467 arcmin, max_diff_distance = 53.882 km)
2021-11-03 20:28:39 -04:00
Don Cross
6d4cb068c5 Implemented C# function SearchAltitude. 2021-09-23 15:44:06 -04:00
Don Cross
1e53f09630 C# ObserverGravity function. 2021-07-19 17:09:08 -04:00
Don Cross
56b4852542 Documented the BaryState functions. 2021-07-14 20:28:15 -04:00
Don Cross
bd29e67663 Implemented C# AberrationTest. 2021-07-13 22:00:01 -04:00
Don Cross
0d23d46f74 Implemented Python function BaryState. 2021-07-13 20:43:50 -04:00
Don Cross
0ee6b22279 C# BaryState implemented. 2021-07-12 22:23:14 -04:00
Don Cross
8abda4ea30 Documentation fixes for VectorObserver functions. 2021-06-21 20:23:33 -04:00
Don Cross
6060a36b09 C#: Implemented VectorObserver. 2021-06-21 18:47:08 -04:00
Don Cross
52fb59b32e Python: Implemented EQJ/GAL conversions.
Ported conversion to/from galactic coordinates to Python.
Added unit test for new Python code.
Updated documentation for all 4 supported languages.
Fixed mistakes in JavaScript function documentation.
2021-06-10 20:48:11 -04:00
Don Cross
f8b449bbbe Ported GAL/EQJ conversion to C#.
The C# version of Astronomy Engine can create rotation
matrices to convert between equatorial J2000 (EQJ)
and galactic (GAL) orientations.
2021-06-08 21:59:36 -04:00
Don Cross
d45bb771ac Python: Replaced LongitudeFromSun with more general PairLongitude. 2021-04-24 21:55:54 -04:00
Don Cross
2cf6419792 C#: Replaced LongitudeFromSun with more general PairLongitude. 2021-04-24 21:18:03 -04:00
Don Cross
cbcacc4b57 Improved agreement of precision among the 4 supported languages.
Before making these changes, I had the following discrepancies
between the calculations made by the different programming
language implementations of Astronomy Engine:

    C vs C#: 5.55112e-17, worst line number = 6
    C vs JS: 2.78533e-12, worst line number = 196936
    C vs PY: 1.52767e-12, worst line number = 159834

Now the results are:

    Diffing calculations: C vs C#
    ctest(Diff): Maximum numeric difference = 5.55112e-17, worst line number = 5

    Diffing calculations: C vs JS
    ctest(Diff): Maximum numeric difference = 1.02318e-12, worst line number = 133677

    Diffing calculations: C vs PY
    ctest(Diff): Maximum numeric difference = 5.68434e-14, worst line number = 49066

    Diffing calculations: JS vs PY
    ctest(Diff): Maximum numeric difference = 1.02318e-12, worst line number = 133677

Here is how I did this:

1. Use new constants HOUR2RAD, RAD2HOUR that directly convert between radians and sidereal hours.
   This reduces tiny roundoff errors in the conversions.

2. In VSOP longitude calculations, keep clamping the angular sum to
   the range [-2pi, +2pi], to prevent it from accumulating thousands
   of radians. This reduces the accumulated error in the final result
   before it is fed into trig functions.

The remaining discrepancies are largely because of an "azimuth amplification" effect:
When converting equatorial coordinates to horizontal coordinates, an object near
the zenith (or nadir) has an azimuth that is highly sensitive to the input
equatorial coordinates. A tiny change in right ascension (RA) can cause a much
larger change in azimuth.

I tracked down the RA discrepancy, and it is due to a different behavior
of the atan2 function in C and JavaScript. There are cases where the least
significant decimal digit is off by 1, as if due to a difference of opinion
about rounding policy.

My best thought is to go back and have a more nuanced diffcalc that
applies less strict tests for azimuth values than the other calculated values.
It seems like every other computed quantity is less sensitive, because solar
system bodies tend to stay away from "poles" of other angular coordinate
systems: their ecliptic latitudes and equatorial declinations are usually
reasonably close to zero. Therefore, right ascensions and ecliptic longitudes
are usually insensitive to changes in the cartesian coordinates they
are calculated from.
2021-04-18 21:15:17 -04:00
Don Cross
6b01510b33 Fixed #99 - Export the AngleBetween function for outside callers. 2021-04-16 20:18:25 -04:00
Don Cross
6f379397e8 Fixed #102 - generate more compact constellation boundary tables.
This change has no effect on client-facing behavior.
It just makes the internal data tables for the array of
constellation appear more compact in C, C#, and Python.
This is what the TypeScript/JavaScript code was already doing.
2021-04-16 19:43:14 -04:00
Don Cross
1e2763af63 Finished defining Jupiter moon radii constants.
Now there are constants for the mean radii of Jupiter's
four major moons available in the C, C#, Python, and JavaScript
versions of Astronomy Engine.

Clarified that these are all mean radii.

Fixed some lingering "//" comments in the C code
(I want to keep ANSI C code as portable as possible.)
2021-04-15 13:20:55 -04:00
Don Cross
a3734bc60b Fixed #105 - Added functions to calculate a time object from TT.
Now callers can create time objects from either UT (UT1/UTC civil time)
or ephemeris/dynamical Terrestrial Time (TT). The new TT functions
numerically solve to find the UT that produces the given TT based
on the Delta-T value at that UT. This is always a very fast
numerical convergence, because TT and UT are almost perfectly
linear over brief time windows.
2021-04-14 19:42:03 -04:00
Don Cross
4f7a6e69cb C#: Implemented calculation of Jupiter's moons. 2021-04-13 11:45:03 -04:00
Don Cross
6b0a966fe7 Tweaks to generating documentation for constants.
Python, C#: sort constants by name.
C#: use horizontal line separators between constants.
C: put a link to the [constants] section.
2021-04-04 21:40:45 -04:00
Don Cross
9b67e7f3f9 Starting development for calculating Jupiter's moons.
I am starting the process of implementing calculation
of Jupiter's four largest moons: Io, Europa, Ganymede, Callisto.
This commit just contains constant declarations for the
equatorial, polar, and volumetric mean radii of Jupiter.

The positions of the moons will be related to the center
of Jupiter and be expressed in Jupiter equatorial radius units,
so I felt it would be good to give users a way to convert to
kilometers, which can in turn be converted to AU.
2021-04-04 20:52:31 -04:00
Don Cross
6f943d9ea4 Fixed some minor documentation mistakes. JS: Export DEG2RAD, RAD2DEG. 2021-04-01 14:08:56 -04:00
Don Cross
085d285ef0 Refactored all the nutation and precession functions.
Use a private enumerated type to select which direction
the precession and nutation is to be done:
- from date to J2000
- from J2000 to date

Normalize the order of parameters to be consistent
between precession() and nutation(), and across languages.
Pass in AstroTime instead of a pair of floating point TT
values (one of which had to be 0).

Added TypeScript version of ObserverVector(),
but it has not yet been documented or tested.
2021-03-31 12:09:11 -04:00
Don Cross
0d4c8e30c0 Added ObserverVector() to C and C# documentation topic indexes. 2021-03-30 19:11:32 -04:00
Don Cross
dfa88f23b8 C#: Added more use of operator overloads for AstroVector. 2021-03-30 17:21:02 -04:00
Don Cross
668c212c5e Simplified C# precession function.
It always seemed a little odd to have to pass in two
time values to the precession() function, when one of
them always had to be 0. I think the logic is clearer
now that I pass in an enum value to select whether I
want a forward transform or a backward transform.
It is cleaner that now I can just pass in an AstroTime.
2021-03-29 21:26:32 -04:00
Don Cross
d5304651f2 C#: ObserverVector, vector operators, constant docs in Markdown.
Ported the ObserverVector function to C#, but it is not tested yet.

While doing that, I realized I needed a way to document newly public
constants DEG2RAD, RAD2DEG, and KM_PER_AU. This led to work
on the 'csdown' project that converts C# XML documentation
into Markdown format.

Then I realized a lot of code would be more elegant if
AstroVector had operator overloads for addition, subtraction,
and dot products.

This in turn required these operators to know which time value
to store in the AstroVector, which led to realizing that I
was sloppy in a lot of places and passed in null times.

So this whole commit contains a variety of unrelated topics,
which is something I don't usually do, but it felt
justified here while I'm in a refactoring mood.
2021-03-29 20:36:55 -04:00
Don Cross
5cd0e60d74 Updated obsolete comments about how Delta-T is calculated.
Astronomy Engine used to use USNO historical and predictive tables,
along with linear interpolation, to calculate Delta-T values.
The problem with the USNO tables is, they did not work well outside
a few centuries around present day.

Later I replaced with Espenak & Meeus piecewise polynomials
that work over a much larger time span (thousands of years).
I just discovered there were still comments in the code referring
to the USNO models. I updated the ones I could find to reflect
the current truth about how the code works today.
2021-03-27 19:44:37 -04:00
Don Cross
6f98095cae Reworked ecliptic coordinate types to contain a vector type.
This is technically a breaking change, but only for clients
that use the cartesian coordinates in an ecliptic coordinate
return type.  Before now, the coordinates were just separate
floating-point members ex, ey, ez. Now they are a standard
vector type.

The purpose is to allow seamless interfacing with vector
rotation functions, and to be consistent with the equatorial
coordinate types.
2021-03-27 12:26:27 -04:00
Don Cross
0426272da4 Eliminated obsolete function VectorFromEquator.
Now that equatorial coordinates include both angles
and cartesian coordinates, there is no need for the
VectorFromEquator function. It has been removed
from all four supported languages.

The expression "VectorFromEquator(equ, time)" can be
replaced with "equ.vec" in any calling code.
2021-03-27 08:24:42 -04:00
Don Cross
a4d61c872a Added JavaScript version of camera demo.
This caused me to discover I had forgotten to finish
making the necessary changes to astronomy.ts for saving
the cartesian vector inside the EquatorialCoordinates class.

I also realized I had made a mistake in the documentation
for the y-coordinate of the vector: it is the June solstice;
there is no such thing as a September solstice!

Also fixed some mistakes in demo tests: if something failed,
I was printing out the wrong filename (camera.c instead of camera.cs).
2021-03-26 21:04:34 -04:00
Don Cross
7241322364 Added C# demo for camera orientation.
Added a C# demo program camera.cs that works the same way
as the C demo program camera.c.

I realized I can speed up the C# demo tests by directly
running the executables after I build them, instead of using 'dotnet'.

Added 'vec' field to Equatorial class. I just realized I no longer need
the function VectorFromEquator(), because the vector is now available
as 'vec'. I will get rid of it in another commit.
2021-03-24 19:38:50 -04:00
Don Cross
4791474271 Updated C and C# topic indexes to include IdentityMatrix, Pivot. 2021-03-23 21:37:50 -04:00
Don Cross
d2d54c9ae2 Implemented C# functions IdentityMatrix and Pivot.
Created new rotation matrix functions for the C# version.
IdentityMatrix creates a new instance of the 3x3 identity matrix

1 0 0
0 1 0
0 0 1

Pivot transforms a rotation matrix by pivoting it about
one of its coordinate axes by a specified angle.

Still need to port the C version of the "camera" demo.
2021-03-23 20:48:33 -04:00
Don Cross
9cc454b1f2 Added comments to explain horizontal coordinate calculations.
I'm about to start working on adding a new output
from the Horizon functions. It was a good time to better
document the ideas behind these calculations, before
adding anything new. These are internal comments only
and do not affect generated documentation.

While I was in there, I noticed extra code that was
checking for impossible return values from atan2().
I eliminated these.
2021-03-20 20:01:38 -04:00
Don Cross
48b7ffe96e Fixed #81 - Upgraded C# projects from .NET Core 3.1 to .NET 5.0. 2021-02-03 14:52:55 -05:00
Don Cross
f34b700ce3 Updated copyrights for 2021. This resolves Travis CI broken build.
I forgot that my build process automatically updates
copyright years when the current year changes.
My Travis CI unit tests verify that there are no local
changes after running all the tests.
That test failed because the update_copyrights.py changed
all the "2019-2020" to "2019-2021".
2021-01-07 08:55:52 -05:00
Don Cross
246ac47d2b Fixed a failure to find a full moon using certain start dates.
In all four versions of Astronomy Engine (C, C#, JavaScript, and Python),
starting a search for a full moon near December 19, 2020 would fail.
I added a unit test to all four languages and it failed consistently
across them all.

The root cause: I was too optimistic about how narrow I could make
the window around the approximate moon phase time in the
SearchMoonPhase functions. Finding the exact moon phase time failed
because it was outside this excessively small window around the approximate
time. I increased the window from 1.8 days to 3.0 days.
This should handle all cases with minimal impact on performance.

Now all four of the new unit tests pass.
2020-12-18 14:29:41 -05:00
Don Cross
9de3be62d3 Made a change to astronomy.cs template that didn't get checked in. 2020-08-24 21:06:50 -04:00
Don Cross
1a2508f68b Pluto integrator: ported to JavaScript. 2020-08-24 14:14:32 -04:00
Don Cross
304d10fc97 Pluto integrator: ported to C#.
Ported Pluto integrator to C#.

Along the way, I noticed that I had VSOP87 latitude and longitude
swapped in such a way that they worked, but were labeled wrong.
This confused me quite a bit as I tried to implement functions
to calculate the derivatives of the VSOP87 spherical coordinates.
Fixed this in the code generator and the C and C# template files.
2020-08-23 20:49:10 -04:00
Don Cross
69a0548eb7 Upgrading from dotnet core 2.2 to 3.1.
Dotnet core 2.2 is no longer officially supported by Microsoft.
The current LTS is 3.1, so I'm upgrading to it.
2020-07-22 00:30:35 +00:00
Don Cross
9c940d7432 Fixed #69 - Support calculating Pluto without any year range limit.
Fixed lingering documentation and code that refers to a limited
year range for calculating Pluto's position.
2020-07-08 19:20:47 -04:00
Don Cross
765902c542 TOP2013: Ported new Pluto model to C# code.
Also corrected code generator to output term coefficients
in scientific notation. In the C code, it was dropping signficant
digits by outputting in fixed point notation.
2020-07-08 11:10:02 -04:00
Don Cross
100417dbe3 Fixed #52 - Finished documenting transit functions.
This completes work on eclipses and transits.
2020-06-14 15:05:01 -04:00
Don Cross
7fcf730839 Implemented C# Transit functions and unit test. 2020-06-13 21:10:48 -04:00
Don Cross
4f842627da Fixed mistake in GeoVector(SUN): we do need to correct for light-travel time.
To be consistent, when calculating the geocentric position of the Sun,
we do need to correct for light travel time just like we would for any
other object. This reduces the maximum time error for predicting transits
from 25 minutes to 11 minutes.

Also had to disable aberration when calculating moon phases
(longitude from Sun) in order to keep a good fit with test data.
2020-06-13 13:45:59 -04:00