Commit Graph

520 Commits

Author SHA1 Message Date
Don Cross
5891cfdb5e Jupiter Moons: implemented optimizer that truncates series.
The optimizer makes the Jupiter moons series as short as
possible while keeping error within an acceptable limit.
This should help produce much smaller code, especially
for JavaScript where it really matters.
2021-04-11 17:27:03 -04:00
Don Cross
260ef16781 C Jupiter Moons : cleaner generated code.
Output the Jupiter moon model data tables in a tidier format.
Format the amplitudes as fixed-point instead of exponential,
so that the JavaScript minifier will have an easier time
shrinking the data (later, when I get to the JavaScript version).
2021-04-11 10:30:32 -04:00
Don Cross
dcbd6fe243 Jupiter moons calculations are now consistent with Stellarium.
I translated the L1.2 FORTRAN code into C, and verified
that the calculations match the Stellarium code I modified
to produce EQJ coordinates. I still need to compare against
JPL Horizons data.
2021-04-10 16:29:10 -04:00
Don Cross
881664a5f0 C: Stubbed function for calculating Jupiter's moons.
Work in progress.
Generating the data tables for Jupiter's moons, but not using them yet.
Created a stub function Astronomy_JupiterMoons(), but it just
returns invalid vectors. The formulas have not yet been implemented.
2021-04-06 16:42:29 -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
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
6a39b1913c Follow up fix for generating markdown for C pointer types. 2021-03-29 16:41:25 -04:00
Don Cross
dbebde2dc7 Fixed #93 - Incorrect markdown for C type links.
The C functions that took a parameter of a pointer type
'astro_time_t *' were causing incorrect Markdown to be generated.
Now my custom Markdown translator (hydrogen.js) handles this case.
2021-03-29 16:32:08 -04:00
Don Cross
61da2253be Implemented C version of ObserverVector function.
This function calculates the position of an observer on or
near the surface of the Earth (the geoid) in one of two
equatorial coordinate systems: J2000 or equator-of-date.
2021-03-29 08:33:17 -04:00
Don Cross
743c11b7fc Miscellaneous work on C code and documentation.
Moved the following constant definitions from astronomy.c
to astronomy.h, so external code can use them:

DEG2RAD
RAD2DEG
KM_PER_AU

My custom doxygen-to-markdown translator (hydrogen.js)
now emits markdown for the above constants.

Eliminated the obsolete constants MIN_YEAR and MAX_YEAR.
Astronomy Engine is no longer limited to calculating planets
within that range of years.

Fixed a couple of minor documentation issues in the C code.

Started work on a new function Astronomy_ObserverVector,
but it is just a stub for now.
2021-03-28 20:53:29 -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
4791474271 Updated C and C# topic indexes to include IdentityMatrix, Pivot. 2021-03-23 21:37:50 -04:00
Don Cross
fcd6ec4d05 Starting to work on support for camera orientation in the C version.
Added C function Astronomy_Pivot to transform a rotation matrix
by rotating it around one of its coordinate axes by a given angle.

Added C function Astronomy_IdentityMatrix that just returns
an identity matrix that can be used as the starting point in
a series of transforms.

C function Astronomy_Equator now also returns the topocentric
equatorial location in the form of a cartesian vector.
This is in a new member of the astro_equatorial_t struct
called 'vec'.

The unit test in ctest.c "Rotation_Pivot()" could be improved
with more and better tests.

Created a demo program camera.c that illustrates using
Astronomy_Pivot() to help calculate the tilt of the sunlit
side of the Moon, as seen by a camera pointing right at it.
The resulting tilt angle is not yet verified.
I need to have some confirmation that it is correct before
porting to the other languages.
2021-03-22 22:30:04 -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
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
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
3bcc44d0fc Reduced precision of generated PlutoStateTable.
The PlutoStateTable was slightly different when generated
in Linux and Windows, because there was so much precision
after the decimal point. Reduced precision until Linux
and Windows generated the exact same output.
2020-08-22 14:08:07 -04:00
Don Cross
bfaa2c185b Pluto integrator: cache all calculated segments.
Instead of remembering the most recent 3 segments of Pluto's orbits,
cache up to all 40 segments within the year span 0000..4000.
Use dynamic memory to allocate them instead of static memory.
Added Astronomy_Reset() to free memory before exit.
2020-08-22 12:01:20 -04:00
Don Cross
10139d3762 Pluto integrator: More refactoring to make code smaller. 2020-08-21 20:09:02 -04:00
Don Cross
64d425994f Pluto integrator: More refactoring to decrease code size.
Also reduced stack usage by sharing bary[5] more.
Eliminated a redundant call to MajorBodyBary() when
calculating one-way outside the bounds of PlutoStateTable.
2020-08-21 19:16:01 -04:00
Don Cross
38139c620b Pluto integrator: making code a little smaller. 2020-08-21 16:59:18 -04:00
Don Cross
90c6b18729 Pluto integrator: simplify calculating table indexes.
There were two places where I was searching for table entries.
I realized I can just directly calculate the same indexes.
This makes the code smaller and faster.
2020-08-21 15:27:14 -04:00
Don Cross
4febeff50e Pluto integrator: added ability to calculate before outside years 0000..4000.
Calculations outside 0000..4000 are slower because they are not cached.
But at least they work now instead of returning an error.
2020-08-20 21:56:43 -04:00
Don Cross
f58778b071 Pluto integrator: Changed dt from 500 to 250 days. Tweaked error threshold. 2020-08-20 15:54:29 -04:00
Don Cross
5c3e5a83d9 Pluto integrator: keep and recycle calculations over segments.
To make Pluto calculations have a low amortized time cost,
calculate up to 3 segments between adjacent pairs of
pre-calulcated states and recycle them. Do linear ramp
fade-mixing between them.

Currently, something is wrong with this because it fails
by inaccurately calculating horizontal coordinates of Pluto
in one test. I'm not sure what's going wrong there yet,
but likely related to multiple calls via search.
2020-08-20 13:49:21 -04:00
Don Cross
a71acd70ca Pluto integrator: settled on dt = 500 days.
This is a happy compromise between speed and accuracy.
Solidified this as a #define PLUTO_DT, which will allow
me to do compile-time math to establish an array size for
an internal buffer of lazy-computed dt increments between
most recently requested segment endpoints.
2020-08-19 17:12:45 -04:00
Don Cross
783aa5008c Pluto integrator: Dramatically improved accuracy and speed.
Now we are getting somewhere!
Using the mean acceleration over the interval seems so much
better than the complicated calculus thing I did.
Now I am using a very large time step: 500 days,
with an error less than 0.2 arcminutes.

C PlutoCheck: dt = 500.000000
C PlutoCheck: 2049-12-19T12:00:00.000Z = 18250.000000 UT = 18250.001076 TT
C PlutoCheck: calc pos = [ 37.4373396436339121, -10.2445033319559062, -14.4764587025278448]
C PlutoCheck: ref  pos = [ 37.4377303529113306, -10.2466292445590774, -14.4773101309873091]
C PlutoCheck: del  pos = [ -0.0003907092774185,   0.0021259126031712,   0.0008514284594643]
C PlutoCheck: diff = 2.323163e-03 AU, 0.198 arcmin
2020-08-19 16:20:51 -04:00
Don Cross
0bfd30d751 Pluto integrator: 'ctest pluto' allows tweaking dt. Default dt = 50 days.
Allow passing in the dt value as an environment variable PLUTO_DT:

$ PLUTO_DT=100 ./ctest pluto
C PlutoCheck: dt = 100.000000
C PlutoCheck: 2049-12-19T12:00:00.000Z = 18250.000000 UT = 18250.001076 TT
C PlutoCheck: calc pos = [ 37.4506659151144774, -10.2638146514621269, -14.4865003148403595]
C PlutoCheck: ref  pos = [ 37.4377303529113306, -10.2466292445590774, -14.4773101309873091]
C PlutoCheck: del  pos = [  0.0129355622031468,  -0.0171854069030495,  -0.0091901838530504]
C PlutoCheck: error = 2.339073e-02 AU, 1.989 arcmin

Default to dt = 50 days.
2020-08-19 14:35:46 -04:00
Don Cross
68b0ec92bd Fixed another Pluto integrator bug: corrected SSB calculation.
I had a bug in the calculation of the Solar System Barycenter.
The position and velocity vectors were both backwards.
This caused the barycentric Sun to be in the wrong place.

C PlutoCheck: 2049-12-19T12:00:00.000Z = 18250.000000 UT = 18250.001076 TT
C PlutoCheck: calc pos = [ 37.4386594210222654, -10.2474739785185811, -14.4777836541558340]
C PlutoCheck: ref  pos = [ 37.4377303529113306, -10.2466292445590774, -14.4773101309873091]
C PlutoCheck: del  pos = [  0.0009290681109348,  -0.0008447339595037,  -0.0004735231685249]
C PlutoCheck: error = 1.342001e-03
2020-08-19 14:23:09 -04:00
Don Cross
a5d011ee78 Pluto integrator: factored out search for nearest starting state. 2020-08-19 12:53:08 -04:00
Don Cross
b6087c9b14 Pluto integrator: fixed a small math mistake.
I didn't implement the math I had derived on paper exactly right.
There was one place where I meant to have (dt^3 / 6), but I had (dt^2 / 6).
This has only a tiny effect on the error. I know this can work better,
so I'm still searching for the real problem.

C PlutoCheck: 2049-12-19T12:00:00.000Z = 18250.000000 UT = 18250.001076 TT
C PlutoCheck: calc pos = [ 37.3682426267669996, -10.0216432448322834, -14.3724661626442582]
C PlutoCheck: ref  pos = [ 37.4377303529113306, -10.2466292445590774, -14.4773101309873091]
C PlutoCheck: del  pos = [ -0.0694877261443310,   0.2249859997267940,   0.1048439683430509]
C PlutoCheck: error = 2.577586e-01
2020-08-18 21:59:37 -04:00
Don Cross
f279cdd9b5 PlutoCheck: made test much more difficult.
I picked a worst-case starting time that is halfway between
two entries in the PlutoStateTable[]. This requires the most
iterations to calculate. Now I have a better metric for
position accuracy:

C PlutoCheck: 2049-12-19T12:00:00.000Z = 18250.000000 UT = 18250.001076 TT
C PlutoCheck: calc pos = [ 37.3682426469732860, -10.0216428456503461, -14.3724660445065933]
C PlutoCheck: ref  pos = [ 37.4377303529113306, -10.2466292445590774, -14.4773101309873091]
C PlutoCheck: del  pos = [ -0.0694877059380445,   0.2249863989087313,   0.1048440864807159]
C PlutoCheck: error = 2.577590e-01

Clearly I still have a lot of work to do!
2020-08-18 20:37:52 -04:00
Don Cross
a212630a2a Pluto integrator: fixed bug; now have much more accurate results.
Got 'ctest pluto' error down to 5.675183e-05 AU.
I was adding vectors when I should have been subtracting,
to find heliocentric Pluto from barycentric Pluto.
2020-08-18 15:58:35 -04:00
Don Cross
b55d216f3e Simplified Pluto integrator looping logic a little bit. 2020-08-18 14:42:23 -04:00
Don Cross
ed43329639 Pluto integrator bug fix: was using stale Sun location to correct coordinates.
When finalizing the position of Pluto, I need to convert
barycentric coordinates to heliocentric coordinates.
I do this by adding the barycentric location of the Sun
to the barycentric location of Pluto to obtain the
heliocentric location of Pluto. But I was using the Sun
coordinates from the simulation starting point, not
at the final time.

This decreases the AU error from 1.369e-02 to 1.347e-02.
I'm still looking for the rest of the error.
2020-08-18 14:23:06 -04:00
Don Cross
071e21c198 Fixed uninitialized memory bug in GravSim().
I wasn't initialzing the acceleration vector in the value returned
by GravSim(). I'm not sure how any of this ever worked!
Found it by using valgrind.
There is no apparent advantage to looping for convergence in GravSim().
Also, it looks like I can use a much larger dt = 10 days.
2020-08-17 22:39:33 -04:00
Don Cross
0fb4d86691 Reworked terse_vector_t to use (x, y, z) instead of c[3].
The code reads so much easier to use normal (x, y, z) coordinates.
2020-08-17 21:31:04 -04:00
Don Cross
2bfef280fd Starting work on using a gravitational simulator to calculate Pluto's movement.
Added PlutoStateTable to C code generator.
This is a table of known correct [tt, pos, vel] tuples for Pluto,
calculated using TOP2013. These serve as seed points from which
to integrate Pluto's motion.

Added PlutoCheck() function to ctest, just to get going.
I have a lot more peformance work to do in order to make
the full blown unit test to finish in a reasonable amount of
time.

Changes in astronomy.c:

Added some generic "terse vector" support.
A terse vector contains 3 components and nothing else.
This is handy for implementing compact formulas for various
vector expressions.

Created enhanced VSOP87 calculations that provide
velocity vectors as well as position vectors for
the Sun, Jupiter, Saturn, Uranus, and Neptune.
These are the "major" bodies that have significant
effects on the motion of Pluto. Also used to convert
heliocentric coordinates to barycentric coordinates.

Implemented first version of the integrator logic.
It is not accurate enough yet, and it is far too slow.
I need to debug the accuracy first, then I will work on
making it faster.
2020-08-17 17:33:03 -04:00
Don Cross
c4442103c4 More fixes for gcc 9.3.0 aarch64 on Raspberry Pi 3.
Fixed some build warnings that occur on various gcc
optimization levels, and only on this version of gcc.

For now, build ctest with fewer optimizations: -O1
instead of -O3. This is because -O3 and -O2 cause
excessive errors in 'ctest diff' of the order
1.0e-9, where I usually get 1.0e-12. I will have to
come back and figure out exactly which optimization(s)
are causing the problem and turn them off specifically.
This also means I need to document the dangerous optimizations
for people who are using the C version of Astronomy Engine.

When 'ctest diff' fails because of excessive numeric error,
print out the two lines of input text that had the worst
numeric error. This really helps on the Raspberry Pi
where memory is at a premium, and it's hard to open the
full output files using vi.
2020-07-22 18:53:13 +00:00
Don Cross
84bbeefd5c Made some documentation fixes for the C version.
Added Astronomy_FormatTime to the topic index.
Reworded text to avoid "as explained above", because it turns
out the generated documentation does not always put things
in the same order they appear in the source code comments.
2020-07-09 15:55:26 -04:00
Don Cross
686401d3ef Added C function Astronomy_FormatTime.
It's surprisingly tricky to print a time rounded to the
nearest millisecond, second, or minute using the C code.
I saw a case where positions.c printed '2020-07-09 04:29:60'.
Because printing a date/time is a basic need of an astronomy program,
I added the new function Astronomy_FormatTime to do this.
All the demo programs use this new function, which required
me to update the correct reference output for the unit tests.
2020-07-09 15:25:28 -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
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
b31c0185df TOP2013: greatly decrease waviness in Pluto curve.
The high-frequency wobble in the Pluto position function was bothering me.
Decreased the arcminute error threshold from 1.0 to 0.5, resulting
in a much larger model, but a lot less ripple:

   547 [    78   140    94   115    21    99]
2020-07-07 15:38:39 -04:00