Commit Graph

151 Commits

Author SHA1 Message Date
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
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
0d4c8e30c0 Added ObserverVector() to C and C# documentation topic indexes. 2021-03-30 19:11: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
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
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
0a4e0c48a0 Documentation fixes for eclipse functions.
Added global/local solar eclipse functions to topic indexes for
C#, JavaScript, and Python.

Revised wording "eclipse found may be" --> "eclipse may be".

Python:
- Added missing Attributes section in class GlobalSolarEclipseInfo.
- Added classes EclipseEvent, LocalSolarEclipseInfo.
- Added stub functions SearchLocalSolarEclipse, NextLocalSolarEclipse.
2020-06-06 10:42:57 -04:00
Don Cross
9645ff6cc3 C# LocalSolarEclipse: finished code, but no unit test yet. 2020-05-26 21:09:22 -04:00
Don Cross
26b3a68e00 C# GlobalSolarEclipse: code builds, but no unit test yet. 2020-05-25 22:46:50 -04:00
Don Cross
a8b29b4509 Renamed lunar eclipse info member from 'center' to 'peak'.
This makes the name consistent with the solar eclipse fields.
2020-05-25 21:07:36 -04:00
Don Cross
30c2141ca6 Added documentation about lunar eclipse functions to topic indexes. 2020-05-16 20:41:57 -04:00
Don Cross
b970694aa2 Implemented JavaScript version of lunar eclipse functions. 2020-05-16 15:43:16 -04:00
Don Cross
f5b7c6c758 C#: Coded SearchLunarEclipse, NextLunarEclipse. Not yet tested. 2020-05-15 21:33:52 -04:00
Don Cross
7eb3322fd1 C#: Use Espenak/Meeus DeltaT function. 2020-05-15 17:20:51 -04:00
Don Cross
d05f213584 Added constellation finder algorithm to C#. 2020-05-03 15:06:02 -04:00
Don Cross
f754a6de82 Fixed #58 - Solar System Barycenter, Earth/Moon Barycenter.
Can now calculate the heliocentric Solar System Barycenter (SSB)
and Earth/Moon Barycenter (EMB).

Changes made in C, C#, JavaScript and Python:
Added new body codes SSB, EMB.
Added support for calculating both in HelioVector functions.
Verified that all calculations match NOVAS.
Verified that all calculations match each other across languages.
2020-04-29 21:53:57 -04:00
Don Cross
cdf9c6955e Added planet apsis functions to C and C# documentation topic indexes. 2020-01-06 17:28:09 -05:00
Don Cross
977ab2d5b3 C# planet apsis: Implemented unit tests. 2020-01-06 16:04:57 -05:00
Don Cross
9992f2570b Starting to port planetary apsis functions to C#.
No unit tests implemented yet.
2020-01-06 15:19:19 -05:00
Don Cross
93fdf9a146 C# rotation: added remaining rotation functions.
Fixed a couple of mistakes in the C documentation.
Turned on link checking for csharp markdown output.
2019-12-22 13:44:58 -05:00
Don Cross
d3f0339498 C# rotation: Added more rotation functions. 2019-12-22 13:32:15 -05:00
Don Cross
8768a157cb C# rotation: Added more rotation functions.
More work on new functions for converting orientation systems.
Changed a few classes to structs for memory allocation efficiency.
Moved stuff around in astronomy.cs so the Astronomy class comes
last. This is helpful when I want to add new functions, so I
don't have to search for the end of the class.
2019-12-22 12:07:38 -05:00
Don Cross
660096e8b0 C# rotation: Added Rotation_EQJ_ECL, Rotation_ECL_EQJ. 2019-12-21 21:54:41 -05:00
Don Cross
30a0e51347 C# rotation: Implemented InverseRotation(). 2019-12-21 21:08:35 -05:00
Don Cross
633b7ae2ef C# rotation: Added CombineRotation. Started unit tests. 2019-12-21 20:52:15 -05:00
Don Cross
8d28f07ef3 C#: Added class RotationMatrix, reworked precession function.
Starting to work on rotation functions in C#.
Added class RotationMatrix.
Split precession() into precession() and precession_rot().
Fixed problem in csdown handling type double[3,3].
2019-12-21 19:03:26 -05:00
Don Cross
30d03321e3 C# doc: fixed broken internal links. 2019-12-21 15:15:44 -05:00
Don Cross
3160bbc992 C# doc: Fixed incorrect symbol names in documentation internal links. 2019-12-21 14:46:26 -05:00
Don Cross
6c8bef9b5e C# doc: Fix internal links within descriptive text. 2019-12-21 14:31:47 -05:00
Don Cross
3ae1d92cb2 C# doc: generate Markdown for type summary and remarks. 2019-12-21 13:54:23 -05:00
Don Cross
d0183e2930 C# doc: generate Markdown for class member variables. 2019-12-21 13:48:31 -05:00
Don Cross
3bb59f99f1 C# doc: generating Markdown for enumeration values. 2019-12-20 21:48:25 -05:00
Don Cross
b6a913785c C# doc: Merging classes, structs, and enums into one section. 2019-12-20 21:21:51 -05:00
Don Cross
424fc82da8 C# doc: starting to generate Markdown for classes.
Currently emit the member functions.
Need to emit the public member variables.
2019-12-20 21:13:46 -05:00
Don Cross
ef654a1d14 C# doc: documenting function parameters and return value. 2019-12-20 20:30:13 -05:00
Don Cross
1bb7fcde6f C# doc: starting to merge in summary and remarks for each function. 2019-12-20 20:10:01 -05:00