Commit Graph

2245 Commits

Author SHA1 Message Date
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
b773834349 Implemented Python Lagrange point calculation. 2022-03-13 17:47:40 -04:00
Don Cross
13413f2754 Prep Python unit tests for Lagrange.
Reworked the Python state vector unit tests so that they will
be ready for adding Lagrange point tests, which require
additional parameters.
2022-03-13 09:45:48 -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
45dbdd87d4 Implemented C# Lagrange point functions. 2022-03-12 17:08:56 -05:00
Don Cross
4ce1bb8a6b C# test: refactored JPL state vector loader.
I want to be able to re-use the code for loading state
vectors from a JPL Horizons text file, instead of copy-n-paste
like I did in C. So I reworked it as an iterator.
2022-03-12 11:30:22 -05:00
Don Cross
a1ec0b730c ctest.c: fixed function names in error messages.
There were a few places inside the unit test function LoadStateVectors
where I had error messages that printed the wrong function name
(VerifyStateBody instead of LoadStateVectors) if an error was detected.
This is because of a copy-n-paste oversight. They are fixed.
2022-03-12 11:28:04 -05:00
Don Cross
1ad336be37 Fixed #158 - Use hypot function where appropriate.
In languages that support it, using hypot(x,y) is a little
easier to read than sqrt(x*x + y*y). Some documentation
(e.g. the man page for the C function) leads me to believe
hypot might also be better behaved than sqrt in some cases.

The JavaScript Math.hypot() is especially nice because it works
for any number of dimensions, so I can use it in 2D and 3D cases.

C only allows 2D usage, as does Python 3.7. Python 3.8 added
support for any number of dimensions, but I don't want to break
compatibility with Python 3.7 just yet. Therefore, in C and Python,
I am only using hypot for 2D cases.

C# does not appear to have any kind of hypot function,
so no changes were made to the C# code.

Thanks to https://github.com/ebraminio for this suggestion.
2022-02-21 13:30:13 -05:00
Don Cross
871389c9cf Fixed C# .NET Framework 4 compile error.
There is no function double.IsFinite() in .NET Framework.
Reworked the sanity check in Astronomy.Pivot so the C# code
builds in these older .NET platforms.
2022-02-21 10:54:01 -05: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
31f36f2ef8 Fixed #159 - unmangle markdown for C #defines.
My custom Markdown documentation generator for C had
a bug when emitting the listing of a #define.
It is not valid to try to hyperlink to other symbols,
because the Markdown syntax gets listed literally inside
the context of a C code block.
2022-02-19 19:19:01 -05:00
Don Cross
19a66caea2 Miscellaneous cleanup of C documentation. 2022-02-19 18:42:25 -05:00
Don Cross
3952ebd9af C Lagrange: Add simpler-to-use function for most cases.
In most cases, people calculating Lagrange points will just
want to pass in the bodies and not have to worry about calculating
their state vectors and masses.

Renamed Astronomy_LagrangePoint to Astronomy_LagrangePointFast.
Added new function Astronomy_LagrangePoint that accepts body enum
values instead of state vectors and masses. It knows to optimize
the precision of the calculation by calling GeoMoonState for the
Earth/Moon case.
2022-02-19 14:24:20 -05:00
Don Cross
d0693f972d Loosened tolerances on VerifyEquilateral Lagrange test for Mac.
I confirmed that the Mac version of GitHub Actions does not
flush stderr on exit, so that is why I couldn't see my
diagnostic error messages. Now I can tell VerifyEquilateral
is failing due to a slightly out of bounds length ratio
in the Earth/Moon/M4 equilateral triangle. Made the tolerance
window a little larger, and trying again.
2022-02-19 12:29:26 -05:00
Don Cross
030cc8f3d3 Testing theory: Mac does not flush stderr on exit. 2022-02-19 11:35:21 -05:00
Don Cross
aa3821cbf2 More guesswork to diagnose GitHub Actions failure on Mac. 2022-02-19 11:09:05 -05:00
Don Cross
0d1561a9d8 Still tracking down why VerifyLagrangeTriangle fails on Mac. 2022-02-19 05:18:16 -05:00
Don Cross
f83d995285 More debugging trying to figure out why Mac OS build fails. 2022-02-18 20:09:28 -05:00
Don Cross
d6957e19ee Trying to figure out why Mac OS test build failed. 2022-02-18 19:29:14 -05:00
Don Cross
6779e4e81c The 5.44 arcmin issue persists even in EMB-centric coordinates. 2022-02-18 07:52:36 -05:00
Don Cross
9dfcd80e17 Script that confirms JPL Horizons 5.44 arcmin issue. 2022-02-17 21:40:22 -05:00
Don Cross
3f257ca924 Check JPL Horizons L4/L5 by feeding their geomoon through my function.
I think I have finally tracked down where the 5.4 arcminute
discrepancy comparing my L4 with JPL Horizons L4 is coming from.
When I feed JPL's geocentric Moon state vector through my
L4/L5 calculator, the result is in a slightly different plane
than it should be. It looks like a mistake in JPL Horizons!

I also fixed a bug where ctest's LoadStateVectors() was not
initializing the state.status before appending to the array.
The result was uninitialized random garbage in the status.
2022-02-17 21:02:26 -05:00
Don Cross
a3da258e7c C Lagrange: confirm JPL geocentric moon state.
Make sure Astronomy Engine's geocentric moon state calculations
match what JPL Horizons calculated.
2022-02-17 19:03:36 -05:00
Don Cross
5e3faef062 C Lagrange: simplify logic using cross products.
It is conceptually simpler to take cross products to
generate 3 coordinate axes (essentially a rotation matrix)
that represent radial, tangential, and normal directions
with respect to the major and minor bodies.
2022-02-17 18:47:05 -05:00
Don Cross
5001be0120 ctest.c : More verification of L4/L5 triangles.
Verify that all three angles inside the major/minor/L triangle
are very close to 60 degrees.
2022-02-17 17:08:40 -05:00
Don Cross
8c801edee2 Adding equilateral triangle checks for L4/L5.
Before comparing my Lagrange point calculations to JPL Horizons,
I check to see if my Lagrange point calculations form an
equilateral triangle from (major body, minor body, L4/L5).
2022-02-17 14:09:57 -05:00
Don Cross
f01419a42b ctest.c prints more diagnostics on vector failures.
When ctest.c detects that a state vector error is
unacceptably large, it now prints extra diagnostics
about the two vector values, their magnitudes, and
how much of the error is angular and how much is
a magnitude discrepancy.
2022-02-17 10:07:16 -05:00
Don Cross
35f8a45d53 C Lagrange: fixed mass parameter comments. Clarified algorithm. 2022-02-16 22:13:23 -05:00
Don Cross
6e142a1df5 Verified JPL Horizon velocity angles.
Calculated the angles between JPL Horizons velocity vectors
for the geocentric Moon and the geocentric L4/L5.
They are always very close to 60 degrees apart, within 0.15 arcsec.
This is not large enough to explain the velocity vector
errors my code calculates.
2022-02-16 19:53:59 -05:00
Don Cross
8ba15530ac ctest: Use more precise coordinates for Lagrange.
The Lagrange test was using Solar System barycentric
state vectors for the pair of bodies. This involved
a lot of unnecessary calculation.
For the Sun/EMB test, use heliocentric coordinates.
For the Earth/Moon test, use geocentric coordinates.

Fail the lagrange_jpl test if we see the major/minor/L4,L5
triangle deviate more than a tiny fraction from equilateral,
after adding the velocity components.
This convinces me that the JPL Horizons velocity vectors
make sense for L4/L5.
2022-02-16 17:13:51 -05:00
Don Cross
d8e58e9e36 Confirmed JPL Horizons L4/L5 maintains equilateral triangle.
I'm having problems confirming formulas for L4/L5 velocity vectors.
So I wanted to test the assumption that these Lagrange points would
have velocity vectors that would leave the major body, minor body,
and Lagrange point in an equilateral triangle after all 3 bodies
continued in a straight line at their current relative velocities.

This does turn out to be the case, which means there is just
a bug in how I'm calculating the velocity vectors.
I just need to find the bug.
2022-02-16 12:44:42 -05:00
Don Cross
2616880835 C Lagrange Points: almost there!
Now correctly calculating L4 and L5 positions, but
there is a large error in their velocity vectors.
Refactored ctest.c LagrangeTest() to be a lot easier
to understand and modify. A new function VerifyStateLagrange()
allows passing test parameters in a more function-oriented way.

Confirmed that L4 and L5 always lie in the same plane with
the position vector and velocity vector.
2022-02-16 11:35:01 -05:00
Don Cross
4ea0d3f9f7 Lagrange: confirmed how JPL defines orbital plane for L4, L5.
By taking the cross product of the Moon's position with
its velocity, I confirmed this is the same normal vector
as taking the Moon's position crossed with the L4/L5 position.
This means I should be able to calculate L4 and L5
using position and velocity vectors to define the
instantaenous co-orbital plane.
2022-02-15 16:32:13 -05:00
Don Cross
faa035d3f6 JPL Horizons L4, L5 angles confirmed to be 60 degrees. 2022-02-13 20:29:08 -05:00
Don Cross
7fc126f81f C Lagrange: use Newton's method for better results.
Use the formulas I already had to calculate first
approximations for L1, L2, L3 distances.
Then use Newton's Method to home in on the positions
where centrifugal acceleration balances with net
gravitational acceleration.
2022-02-13 19:26:50 -05:00
Don Cross
4a30682a13 Better accuracy for L1/L2 points.
I realized there was a small mistake in how I was
calculating the distance scaling factor for L1 and L2.
It was relative to the distance between the minor body
and the barycenter, not the minor body and the major body.
This significantly improves the accuracy for Earth/Moon
Lagrange points, but still has more error compared
to JPL Horizons than I currently understand.
2022-02-12 15:39:01 -05:00
Don Cross
476712430e Standard deviations for JPL Horizons analysis.
Analysis of Lagrange point calculations by JPL Horizons
now includes standard deviations of position/velocity
magnitude ratios. They confirm the ratios are very consistent.
2022-02-12 14:04:36 -05:00
Don Cross
9234a926d5 Lagrange analysis of pos/vel magnitude ratios.
This analysis confirms that JPL Horizons is making perfectly
equilateral triangles to calculate the positions of L4, L5.
2022-02-12 13:25:48 -05:00
Don Cross
08606ba56d Fix build error on Microsoft C compiler.
The Microsoft C compiler is oddly picky about declaring a const variable.
Apparently it cannot do math with other const variables in its
initializer expression, unlike other C compilers.
So I had to change MOON_GM from a const to a #define.
2022-02-12 12:59:10 -05:00
Don Cross
65582ff54f Starting analysis of JPL Horizons Lagrange points.
Wrote code in ctest.c to load state vector data from
JPL Horizons output into a dynamically-allocated array.
This makes it easier to detangle the logic for loading
the data from the logic for doing statistical analysis.
2022-02-12 11:59:57 -05:00
Don Cross
ee7b440c9c C LagrangePoint: patched to pass unit tests.
Still not ready, but patching to pass unit tests so
I can push to GitHub for backup.
2022-02-12 10:49:05 -05:00
Don Cross
7ed50c262b C Lagrange work in progress.
The Lagrange point calculation is still not finished,
but L1 and L2 are working. L3 is probably correct, but there
is no test data for it.

I replaced the test data with new JPL Horizons output that
is centered on the primary body instead of the Solar System Barycenter.
This allows Astronomy_LagrangePoint() to be agnostic about
the coordinate systems of the state vectors handed to it.

I still need to get L4 and L5 calculations to match JPL Horizons
data, but it is not yet clear how to do that.
2022-02-12 10:15:41 -05:00
Don Cross
f4b235fda4 Fixed #156 - Moon ascending/descending nodes.
Python and npm package version: 2.0.11.
Finished implementing new functions across all
supported languages:

    EclipticGeoMoon
        Calculate the Moon's ecliptic geocentric position
        in angular coordinates. The ecliptic longitude is
        measured with respect to the mean equinox of date.

    SearchMoonNode
    NextMoonNode
        A pair of functions to search for consecutive occurrences
        of the Moon's center passing through the ecliptic plane.
2022-02-06 21:06:30 -05:00
Don Cross
6f9c906061 PY EclipticGeoMoon, SearchMoonNode, NextMoonNode. 2022-02-06 19:55:24 -05:00
Don Cross
785bfc456a Python MoonNode test: loading test data 2022-02-06 17:04:41 -05:00
Don Cross
19007ebfd5 JS EclipticGeoMoon, SearchMoonNode, NextMoonNode. 2022-02-06 16:11:24 -05:00
Don Cross
eb5cc8ea9a C# EclipticGeoMoon, SearchMoonNode, NextMoonNode.
Implemented the C# versions of these functions.
Ported the unit tests from C to C# to validate them.
2022-02-06 12:57:51 -05:00
Don Cross
e7717ea4fa Added C functions SearchMoonNode, NextMoonNode.
Implemented a pair of C functions for finding a series of
Moon nodes:

    Astronomy_SearchMoonNode
    Astronomy_NextMoonNode

Finished the C unit test "moon_nodes" that verifies
my calculations against Fred Espenak's test data.
2022-02-05 14:29:08 -05:00
Don Cross
21526cce57 C moon nodes: confirmed match with Espenak data.
Fixed another bug in my parsing of the original Espenak
data for moon nodes. Added verification that my own
Moon calculations match his:

The Moon is always within 0.182 arcminutes ecliptic
longitude of the node when he says it is crossing the node.

The Moon is always within 1.54 arcminutes of the equatorial
coordinates he says.
2022-02-04 21:30:26 -05:00