Commit Graph

49 Commits

Author SHA1 Message Date
Don Cross
bb27adfdfa Update C# demo/test projects to dotnet core 7. 2023-06-18 21:04:33 -04:00
Don Cross
9ab7767a57 Document camera demos and include image to explain the angles. 2023-03-25 11:40:02 -04:00
Don Cross
da900c6793 Fixed C# camera demo bug: incorrect sunlit angle of Moon. 2023-03-24 21:55:07 -04:00
Don Cross
fc408501c5 Fix for dotnet command no longer allowing --output on solution files.
The `dotnet` command no longer allows using `--output` to specify the
output directory for building a solution file:
https://github.com/dotnet/sdk/issues/15607

This broke my GitHub Actions tests for C#.

I used the following workaround, because in my case I
know merging multiple builds into one directory is safe:
https://github.com/dotnet/sdk/issues/30624#issuecomment-1432118204
2023-02-19 17:13:05 -05:00
Don Cross
93fb6226cd C#: Solar time demo using HourAngle(). 2023-02-12 13:32:38 -05:00
Don Cross
47ce0ac34e C#: EquatorialToEcliptic now returns ECT instead of ECL. 2022-12-09 21:03:05 -05:00
Don Cross
8a153315cf Simplified and optimized nutation formula.
While trying to convert ecliptic coordinates from mean
equinox of date to true equinox of date, I ran into excessive
overhead from the IAU2000B nutation model. The fact that it
uses 77 trigonometric terms made the calculations a lot slower.

https://apps.dtic.mil/sti/pdfs/AD1112517.pdf
Page 4 in the above document mentions a shorter series
“NOD version 2” that has 13 terms instead of 77 as used in IAU2000B.
I had not noticed NOD2 before, because it appears only in
the FORTRAN version of NOVAS 3.x, not the C version.

After reading the FORTRAN code, I realized NOD2 is the same
as IAU2000B, only it keeps the first 13 of 77 terms.
The terms are already arranged in descending order of
significance, so it is easy to truncate the series.

Based on this discovery, I realized I could achieve all of
the required accuracy needed for Astronomy Engine by
keeping only the first 5 terms of the nutation series.
This tremendously speeds up nutation calculations while
sacrificing only a couple of arcseconds of accuracy.

It also makes the minified JavaScript code smaller:
Before: 119500 bytes.
After:  116653 bytes.

So that's what I did here. Most of the work was updating
unit tests for accepting slightly different calculation
results.

The nutation formula change did trigger detection of a
lurking bug in the inverse_terra functions, which convert
a geocentric vector into latitude, longitude, and elevation
(i.e. an Observer object). The Newton's Method loop in
this function was not always converging, resulting in
an infinite loop. I fixed that by increasing the
convergence threshold and throwing an exception
if the loop iterates more than 10 times.

I also fixed a couple of bugs in the `demotest` scripts.
2022-12-04 10:31:15 -05:00
Don Cross
480e0c3ab5 C#: Overhauled altitude search for polar regions.
The C# version of the altitude searches now work correctly
near the Earth's poles. This is a port of the C version.
Cleaned up a little code in the C version.
2022-11-13 12:25:10 -05:00
Don Cross
c798c5015d C#: lunar eclipse obscuration 2022-10-18 16:21:15 -04:00
Don Cross
6abce518f6 C#: added iterator helper functions
Added the following iterator functions that wrap
search/next pairs of functions:

    GlobalSolarEclipsesAfter
    LocalSolarEclipsesAfter
    LunarApsidesAfter
    LunarEclipsesAfter
    MoonNodesAfter
    MoonQuartersAfter
    PlanetApsidesAfter
    TransitsAfter

I updated the following C# demos:

    moonphase.cs     ==> MoonQuartersAfter
    lunar_eclipse.cs ==> LunarEclipsesAfter

Fixed an issue in the C# Markdown generator
so that it can now handle generic types like
`IEnumerable<MoonQuarterInfo>`.
2022-05-07 13:02:42 -04:00
Don Cross
e11cb1721b Simplified demotest scripts for C, C#, JS, PY.
I made the scripts for testing the demos for
C, C#, JavaScript, and Python follow the improved
pattern used for Java and Kotlin: much smaller
and easier to maintain thanks to bash functions.
2022-05-02 12:27:19 -04:00
Don Cross
efc59ae6fc Refactored demo tests.
I refactored the unit tests for all the demo programs
to follow a different pattern that makes it simpler
to add more demo tests in the future.

The main thing is that correct output and generated
output are now in separate directories `correct` and `test`.
I have moved the test scripts from `test/test` to `./demotest`
in all the langauge demo directories.

This makes it simpler to clean up any stale generated
files before each test run by `rm -f test/*.txt`.

I stumbled across this while making the Java demo tests,
and it was a better solution, so now all the other languages
are consistent with the Java demo tests.

In the C demo tests, I also decided to compile all the
binary executables into a subdirectory `bin` that can
be cleaned out before each run, to make sure there are
no stale executables from an earlier run.
2022-04-30 21:01:11 -04:00
Don Cross
0d24433db3 Fixed #187 - Seasons() failed for distant years.
For years before 1582 or years after 3668, the Seasons functions
were unable to find many equinoxes and/or solstices.
The problem was that over time, the Earth's axis precesses
enough that the calendar dates of these events drifts outside
the fixed search ranges I had provided for them.

I expanded the search ranges so all season changes can be found
for a much wider range of years, as verified by unit tests:

    C/C++:      -2000..9999
    C#:             1..9999
    JavaScript: -2000..9999
    Python:         1..9999
    Kotlin:         1..9999

Note: C#, Python, and Kotlin currently do not allow
years values below +1. In fact, I discovered we were not
noticing when an invalid year was passed into the Kotlin code.
I updated that code to throw an exception when the year does
not match what was expected. It is disturbing that the
GregorianCalendar class silently ignores invalid years!

Constricted the search tolerance from 1 second to 0.01
seconds for the seasons search, to ensure more consistent
behavior.

Fixed a bug in the Kotlin search() function's
quadratic interpolation that was causing the convergence
to be slower than it should have been.
2022-04-08 16:51:09 -04:00
Don Cross
5744c9ebe9 Moon phase demos also calculate illuminated fraction.
The phrase "Moon phase" is ambiguous, because sometimes
it means relative ecliptic longitude, other times it means
illuminated fraction. The "moonphase" demos were only
calculating the relative ecliptic longitude, which was
confusing. Now they calculate both.
2022-02-20 15:27:46 -05:00
Don Cross
753554db67 Make demo tests less sensitive to tiny floating point errors.
More work getting MacOS build process to work.
Avoid excessive number of floating point digits of
output in the demo tests, so that insignificant
floating point variations don't cause unit test failures.
2022-01-07 20:19:23 -05:00
Don Cross
cb4c9a6549 Fixed mistake in raytracer. Stop using 'realpath'.
I found a mistake in the raytracer's Spheroid class,
thanks to a warning about an unused member variable.
I don't believe it had any effect on the currently
generated images, but it was important to fix it before
I ever do any set operations on Spheroids.

On macOS, there is no 'realpath' command by default.
So I eliminated some more attempts to use 'realpath'
in the demo test scripts.

Renamed the GitHub Actions tests to be consistent:
    Astronomy-Engine-Linux
    Astronomy-Engine-Macos
2022-01-07 18:30:15 -05:00
Don Cross
0547aafc2b Made 'camera' demo checks tolerant of floating point roundoff.
The demo tests on Mac OS failed because of very tiny
floating point discrepancies that don't matter.
Changed the output of the "Moon check" so that slight
differences in vector residue no longer fail the unit tests.
2022-01-06 21:25:26 -05:00
Don Cross
f994d8d04c Fixed #141 - Upgrade C# code to .NET 6.
Now that Microsoft has officially released .NET 6,
I have upgraded the C# version of Astronomy Engine to use it.
No source code changes were needed. I just bumped the
version number in the project files, and targeted .NET 6
in the GitHub Actions continuous integration tests.
Fixed some obsolete wording in generate/README.md.
2021-12-07 17:06:04 -05:00
Don Cross
4e6cb282f5 Use original Pluto gravsim with finer time steps.
I'm getting much better accuracy sticking with my original
gravity simulator, just with smaller time increments, than
I was with the Runge-Kutta 4 method. The PlutoStateTable
gets a bit larger (51 state vectors instead of 41), but the
accuracy is so much higher.

Removed the Runge-Kutta code because I won't be going back to it.
2021-11-12 16:22:14 -05:00
Don Cross
1e53f09630 C# ObserverGravity function. 2021-07-19 17:09:08 -04:00
Don Cross
87926a71c1 Implemented C# 'triangulate' demo. Added doc links. 2021-06-22 13:51:14 -04:00
Don Cross
faf752640c C#: Use DEG2RAD and RAD2DEG constants in external code.
Instead of copy-n-paste of this constants, use them
from Astronomy Engine, now that they are public and documented.
2021-03-29 22:25:07 -04:00
Don Cross
a97fc7da9c Ported IdentityMatrix, Pivot functions to Python. Added tests and camera demo. 2021-03-27 05:19:27 -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
8c53180f18 Fixed C# floating point parse/format issues in European cultures.
When built from a system with a European (or similar) culture setting
where a comma is used as a decimal marker instead of a period,
the C# unit tests and demos would fail.

Now explicitly specify InvariantCulture to resolve these problems.
2021-02-06 15:39:55 -05: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
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
8f16f0a5ae Pluto integrator: finished porting to Python.
I believe this wraps up the Python integrator.
It now works in all 4 languages and passes all tests.
Fixed up demo tests to match new output.
Turned on Travis CI checking in this branch again.
2020-08-24 20:54:20 -04:00
Don Cross
23b5bddf8b Fixed minor breakage in C# demo tests. 2020-07-21 21:01:15 -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
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
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
e3255c7401 Cleaned up and unified Earth and Moon radius constants.
In all 4 supported languages, use consistent constant names for
Earth and Moon radii.

Use Moon's equatorial radius for rise/set timing.

Use Moon's mean radius for calculating Moon's umbra radius for
detecting solar eclipses.

Also use Moon's mean radius for determining whether the Earth's shadow
touches the Moon, for finding lunar eclipses.

Use the Moon's polar radius for distinguishing between total
and annular eclipses, with a 14 meter bias (instead of 1420 meters!)
to match Espenak data.

Use consistent unit test error threshold of 0.57 minutes for rise/set.
Updated demo test data for slight changes to rise/set prediction times.

Updated doxygen options to issue an error on any warnings.
Fixed the incorrect function name link that doxygen was warning me about.
2020-05-23 13:08:25 -04:00
Don Cross
5b822de1b5 Fixed broken README link to C# lunar eclipse demo. 2020-05-17 14:19:15 -04:00
Don Cross
83544bf57d Added C# demo for lunar eclipse.
Alphebetized demo readme pages.
2020-05-17 14:03:01 -04:00
Don Cross
f5b7c6c758 C#: Coded SearchLunarEclipse, NextLunarEclipse. Not yet tested. 2020-05-15 21:33:52 -04:00
Don Cross
9ea6a0664f Python: Use Espenak/Meeus formula for calculating Delta T. 2020-05-15 19:28:54 -04:00
Don Cross
4023974079 More adjustments to unit tests to pass for model adjustments. 2020-01-06 12:53:05 -05:00
Don Cross
2f255eda8c C# demo: Added horizon demo. 2019-12-23 14:03:53 -05:00
Don Cross
ff75e70753 C# demo: added seasons demo. 2019-12-23 13:49:09 -05:00
Don Cross
96cd7e4c7e C# demo: added riseset. 2019-12-23 13:30:13 -05:00
Don Cross
ff964879e4 C# demo: Added positions demo. 2019-12-23 12:55:17 -05:00
Don Cross
c1b3bda2bd C# demo: Added moonphase demo. 2019-12-23 12:36:50 -05:00
Don Cross
d79c2ab071 C#: Fixed bugs handling UTC DateTime. Got culminate demo working. 2019-12-23 12:07:33 -05:00
Don Cross
3ffc77caa6 C# demo: more work getting set up. 2019-12-23 11:36:55 -05:00
Don Cross
a4dc0eb41d C# demo: Starting to set up solution, projects, and build. 2019-12-23 10:59:48 -05:00