Commit Graph

109 Commits

Author SHA1 Message Date
Don Cross
7c475fcada Expanded the fix for issue #347.
I tried more distant objects like Jupiter ... Neptune.
This revealed that at increasing distances, the convergence
threshold in inverse_terra needed to increased also.
So now I use 1 AU as a baseline, and scale up linearly
for more distant objects.
2024-05-27 17:07:30 -04:00
Don Cross
0309762a64 Fixed #347 - Relaxed convergence criteria for inverse_terra functions.
Asking the latitude and longitude directly beneath
the Sun causes inverse_terra not to converge, because the
convergence increment `W` never got below 1.48e-8, but the
convergence limit was 1.0e-8. I increased the limit to 2.0e-8
in all programming language versions.

I'm hoping that is a big enough tolerance for all cases now,
but I will do more testing to see if further fixes are required
for even more distant bodies than the Sun.
2024-05-27 16:20:45 -04:00
Don Cross
8c55fbad79 JS: Added metersAboveGround parameter to SearchRiseSet. 2023-03-13 13:06:37 -04:00
Don Cross
66cd0147b5 JS: Added Atmosphere function. 2023-03-13 09:54:54 -04:00
Don Cross
f11e2e8c6d JS: Implemented HourAngle function. 2023-02-12 14:22:41 -05:00
Don Cross
d4660de2a7 JS: Ecliptic function returns ECT instead of ECL. 2022-12-10 03:55:17 -05:00
Don Cross
f959599497 Completed EQJ/ECT, ECT/EQJ rotations. 2022-12-09 13:12:42 -05:00
Don Cross
dfbd268aa3 JS: Added rotation ECT/EQD. 2022-12-07 13:48:24 -05:00
Don Cross
552c7a5557 EclipticGeoMoon uses true equinox of date in all languages.
Added EclipticGeoMoon as output to the temp/*_check.txt files as 'm' lines.
This ensures that all the languages calculate nearly identical values.

Optimized EclipticGeoMoon a little more by eliminating a redundant
call to mean_obliq.
2022-12-05 21:44:35 -05:00
Don Cross
d3f36b942d Verify nutation angles are consistent across languages. 2022-12-04 14:20:44 -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
fe625c5956 Kotlin: added support for user-defined stars. 2022-11-22 19:29:15 -05:00
Don Cross
f6ad8b5b26 C: Find rise/set/culm of user-defined stars.
SearchRiseSet and SearchHourAngle now work with user-defined stars.

Fixed a bug in InternalSearchAltitude where I failed to return an error
code when its call to MaxAltitudeSlope failed.
2022-11-22 05:46:50 -05:00
Don Cross
6b4c6c67e2 C: Added Astronomy_DefineStar.
Beginning to add support in C for user-defined stars.
2022-11-21 22:16:30 -05:00
Don Cross
696efe8649 JS: Find rise/set/culm of user-defined stars.
DefineStar now requires passing in the heliocentric
distance of the star expressed in light-years.
That way, I can directly support returning vectors
to a star from HelioVector, GeoVector, etc.

SearchRiseSet and SearchHourAngle now work with user-defined stars.
2022-11-21 20:55:27 -05:00
Don Cross
84d6aff35a JS: Added function DefineStar.
I'm starting to implement the ability to define
up to 8 distinct points in the sky as "stars"
that will be allowed as a `body` parameter to
some Astronomy Engine functions, to be determined.
2022-11-21 12:53:45 -05:00
Don Cross
351e997a2f Merge branch 'riseset_poles'
Fixed issues with finding rise/set events near the
Earth's poles. Avoid assumptions that rise/set is
tied to hour angles.
2022-11-14 12:05:20 -05:00
Don Cross
e85863acf5 JS: reworked rise/set to work in polar regions 2022-11-13 20:45:00 -05:00
Don Cross
5eca7d7760 CodeQL tweaks and fixes.
Updated CodeQL config to ignore source templates,
because they are not syntactically valid source code.
Ignore other stuff that is irrelevant to published
code quality.

Made various fixes based on helpful CodeQL analysis.
2022-11-07 15:31:05 -05:00
Don Cross
bd115770e1 C: Added function Astronomy_PlanetOrbitalPeriod. 2022-11-01 16:38:57 -04:00
Don Cross
9e4fbecf55 JS: added OrbitalPeriod function. 2022-11-01 16:09:14 -04:00
Don Cross
06b62887d2 Kotlin: obscuration for solar, lunar eclipses. 2022-10-20 17:31:21 -04:00
Don Cross
223b75a69a JS: solar eclipse obscuration. 2022-10-19 16:47:33 -04:00
Don Cross
f81e5f0aea JS: more testing of obscuration in unit test lunar_eclipse. 2022-10-19 14:51:16 -04:00
Don Cross
f6c5bd0bba JS: lunar eclipse obscuration 2022-10-19 14:37:21 -04:00
Don Cross
a50436b535 C: Support formatting calendar years -999999 to +999999. 2022-10-06 15:29:24 -04:00
Don Cross
dc59b55d92 Added more testing of rise/set foreward/backward searches. 2022-10-02 19:58:48 -04:00
Don Cross
6e2229603c Fixed wording, variable names in unit tests. 2022-10-02 12:33:20 -04:00
Don Cross
96fffcf2a6 JavaScript: better forward/reverse moon phase tests.
In the unit tests for searching forward and backward
for moon phases, in addition to new moons, also test
first quarter, full moon, and third quarter.

Verify that forward and backward searches work for
100 start times between a single pair of consecutive events.
2022-10-02 11:33:04 -04:00
Don Cross
c2bded8605 JS: Reverse chrono search for rise/set, hour angles.
The following JavaScript functions now support searching
in forward or reverse chronological order:

    SearchRiseSet
    SearchAltitude
    SearchHourAngle
2022-09-29 04:33:34 -04:00
Don Cross
424b267007 JS SearchMoonPhase: allow searching backward in time.
Enhanced the JavaScript function Astronomy.SearchMoonPhase
to allow searching forward in time when the `limitDays`
argument is positive, or backward in time when `limitDays`
is negative.

Added unit test "moon_reverse" to verify this new feature.
2022-09-26 20:25:35 -04:00
Don Cross
d28f5ecff3 PY gravsim: passes unit tests
The Python version of the GravitySimulator class
is now passing all unit tests. This completes
the initial coding. I still need to review
documentation across all the language implementations.
2022-05-22 21:16:58 -04:00
Don Cross
94589693f5 JS gravsim: finished unit tests, fixed bug
The JavaScript version of the gravity simulator is
now working. I had one bug in the acceleration formula.
Finished the unit tests and also streamlined them a little.
2022-05-19 09:49:37 -04:00
Don Cross
b9db79c6fd JS gravsim: partial completion of unit tests
Implemented half of the GravitySimulator unit tests.
Fixed a bug in the GravitySimulator constructor.

Did some refactoring of test.js:

- Wrote Debug() function as shortcut for conditional output.
- Created generic JPL Horizons state file reader.
2022-05-18 21:14:49 -04:00
Don Cross
5ad71cb702 JS: Replace strings with new enum EclipseKind. 2022-05-05 16:39:51 -04:00
Don Cross
af63d1520f JavaScript: Jupiter's moons returned by name
It makes more sense to report Jupiter's moons with
individually named structure fields rather than an array.
It reduces the overall code and documentation size,
and outside of unit testing, there are few cases
where iterating over an array of moons is more
lucid than using the names of the moons.

This is a breaking change, but hopefully very few
developers are using this function yet.
Fixing the breakage is very simple.
2022-05-05 12:10:33 -04:00
Don Cross
8696241c90 Kotlin: search for planet aphelion/perihelion.
Added functions:

    searchPlanetApsis
    nextPlanetApsis

I discovered that I had an unnecessary special relaxation
of apsis error tolerance for Pluto. It turns out that currently
0.1 degrees of orbital rotation is enough for all the planets.
2022-04-24 20:55:51 -04:00
Don Cross
a6e72a2423 Kotlin: search for lunar nodes.
Search for times when the Moon ascends or descends
through the ecliptic plane. These are called
ascending and descending nodes. Added the functions:

    searchMoonNode
    nextMoonNode

Also corrected comments in the unit tests that
incorrectly stated nodes occur when the ecliptic
longitude is zero. They should have said the
ecliptic latitude is zero.
2022-04-23 20:34:52 -04:00
Don Cross
3ce32f8819 Kotlin: lunar libration. Fixes for other languages.
The existing lunar libration functions in the
other languages (C, C#, Python, JavaScript) were
calculating the Moon's ecliptic latitude and longitude
in radians, not degrees as intended. They have been fixed.

Implemented the libration function for Kotlin.
2022-04-22 16:36:14 -04:00
Don Cross
ef6af40b0d Kotlin: added maximum elongation search.
Added searchMaxElongation function, which finds the
next time Mercury or Venus reaches is maximum angular
separation from the Sun.
2022-04-18 13:03:08 -04:00
Don Cross
16578935ad Kotlin: implemented relative longitude search.
Implemented searchRelativeLongitude, which finds
planetary conjunctions and oppositions.
Discovered I can make all languages' unit tests
more strict: 6.8 minute error tolerance instead of 15.

Fixed documentation mistake in C# function SearchRelativeLongitude:
the function cannot return null. It either finds a solution time
or throws an exception.

Simplified Kotlin unit tests: use a more compact pattern of
scanning space-delimited tokens in lines.
2022-04-17 12:22:07 -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
94c7884f11 Kotlin: added moon phase and search functions.
Added the following Kotlin functions:

    equatorialToEcliptic
    pairLongitude
    moonPhase
    searchMoonPhase
    searchMoonQuarter
    nextMoonQuarter

Discovered I could tighten the tolerance for the moon phase
unit tests from 120 seconds to 90 seconds and they still pass.
2022-04-05 17:33:19 -04:00
Don Cross
9b4223193b Kotlin: sidereal time
Implemented Astronomy.siderealTime() in Kotlin.

Updated all languages' unit tests for sidereal time
to verify exact conformity between them, rather than
to an externally derived value. I wanted to make
sure all languages, including Kotlin, are calculating
the exact same value.

I don't need an external authoritative test for
sidereal time, because it will be indirectly tested
through its involvement in thousands of other calculations
that depend on it. I just need a quick sanity check
before implementing those other things that depend on it.
2022-03-26 02:07:15 -04:00
Don Cross
0943f058c9 Fixed #165 - expose sidereal time function.
There was already an internal function for calculating
Greenwich Apparent Sidereal Time (GAST). By request,
I have exposed this function for outside users.

Added a minimal unit test to verify the function is
callable and returns the correct result for one case.
This function is already exhaustively tested by unit
tests that verify other functions that already called
this function when it was internal, so minimal testing
is sufficient in this case.
2022-03-15 20:48:02 -04:00
Don Cross
d843775122 Fixed #148 - calculate Lagrange points.
Added the following new functions to all 4 languages:

MassProduct: find the GM product for all Solar System bodies.

LagrangePoint: calculate L1..L5 state vectors for a pair of bodies.

LagrangePointFast: calculate L1..L5 state vectors given
state vectors and GM products of a pair of bodies.
2022-03-13 20:56:32 -04:00
Don Cross
eba8c2e87f Implemented JavaScript Lagrange point functions. 2022-03-12 20:31:07 -05:00
Don Cross
e4665f4669 JS tests: refactored StateVector tests.
Reworked the tests that use JPL Horizons output files containing
state vectors so that they generalize to different parameters.
Specifically, soon I will need to pass in (major_body, minor_body,
point) to support Lagrange point tests.
2022-03-12 18:06:58 -05:00
Don Cross
6f9c906061 PY EclipticGeoMoon, SearchMoonNode, NextMoonNode. 2022-02-06 19:55:24 -05:00
Don Cross
19007ebfd5 JS EclipticGeoMoon, SearchMoonNode, NextMoonNode. 2022-02-06 16:11:24 -05:00