Commit Graph

1235 Commits

Author SHA1 Message Date
Don Cross
1e84f4940f Demo jupiter_moons for Kotlin, Java.
Added Kotlin and Java demos for calculating Jupiter's moons.
Illustrates correcting for light travel time.
I added named getters for the 4 moons in `JupiterMoonsInfo`,
because in Java it was really ugly to write
`jm.getMoon()[0]`, etc.
2022-05-02 15:45:10 -04:00
Don Cross
f670ae2127 Added Kotlin demo: jupiter_moons.
I had to add a new method `Vector.withTime` to work around
the error checking that throws an exception if vectors
from different times are added.

Also made Kotlin constants public:

    MINUTES_PER_DAY
    SECONDS_PER_DAY
    MILLISECONDS_PER_DAY
2022-05-02 14:57:16 -04:00
Ebrahim Byagowi
962b9c7c9c kotlin: Revert and use arrayOf directly
Direct use of arrayOf can be a bit more efficient than calling map and toTypedArray.

It could be faster if JupiterMoonsInfo was holding a list but better to use direct
typed array initializer for more efficiency.
2022-04-28 19:10:35 +04:30
Ebrahim Byagowi
abd48a3e2b kotlin: Use hashMapOf instead mutableMapOf
mutableMapOf guarantees order of insertion and hashMapOf don't and
as it doesn't matter here let's use that instead.
2022-04-28 18:58:39 +04:30
Don Cross
462f172e6d Kotlin: restored original series calculations.
Changing series calculations to use `sumOf` caused
test failures for Jupiter's moons, compared to the other
languages. I don't understand why, but it is losing about
5 decimal places of accuracy:

    First  file: temp/c_check.txt
    Second file: temp/k_check.txt
    Tolerance = 6.700e-15

                lnum                 a_value                 b_value     factor       diff  name
      OK       59558 -3.7992709399390907e-04 -3.7992709399390658e-04  411.52263  1.026e-15  helio_x
      OK       70088 -1.2672603312645981e-03 -1.2672603312646005e-03  411.52263  9.816e-16  helio_y
      OK      122819  1.0937502621531685e-04  1.0937502621531790e-04  411.52263  4.294e-16  helio_z
      OK        2427  2.0269124415104024e+01  2.0269124415104031e+01    0.01730  1.229e-16  sky_j2000_ra
      OK       96711 -1.3269907232295576e+01 -1.3269907232295552e+01    0.00556  1.382e-16  sky_j2000_dec
      OK      321094  1.9426425943521761e+00  1.9426425943521755e+00    2.61780  1.744e-15  sky_j2000_dist
      OK      302748  3.5388201408771312e+02  3.5388201408771533e+02    0.00275  6.086e-15  sky_hor_az
      OK      121119 -2.2454039277279009e+01 -2.2454039277279151e+01    0.00556  7.895e-16  sky_hor_alt
    FAIL      462886  3.2838700693197847e-05  3.2838701021405780e-05  354.60993  1.164e-10  jm_x
    FAIL       18898  4.1298198258838197e-05  4.1298197961707834e-05  354.60993  1.054e-10  jm_y
    FAIL       18898  6.5401658638156675e-05  6.5401658496812707e-05  354.60993  5.012e-11  jm_z
    FAIL       18898 -1.9369714715980919e-04 -1.9369714599049137e-04  100.00000  1.169e-10  jm_vx
    FAIL      462886  2.0741129523130840e-04  2.0741129628185288e-04  100.00000  1.051e-10  jm_vy
    FAIL      462886 -7.0200557604537683e-05 -7.0200557103467577e-05  100.00000  5.011e-11  jm_vz

    Score = 1.169e-10
    ctest(Diff): EXCEEDED ERROR TOLERANCE.

Restored the original loop logic and now it is back within tolerance:

    First  file: temp/c_check.txt
    Second file: temp/k_check.txt
    Tolerance = 6.700e-15

                lnum                 a_value                 b_value     factor       diff  name
      OK       59558 -3.7992709399390907e-04 -3.7992709399390658e-04  411.52263  1.026e-15  helio_x
      OK       70088 -1.2672603312645981e-03 -1.2672603312646005e-03  411.52263  9.816e-16  helio_y
      OK      122819  1.0937502621531685e-04  1.0937502621531790e-04  411.52263  4.294e-16  helio_z
      OK        2427  2.0269124415104024e+01  2.0269124415104031e+01    0.01730  1.229e-16  sky_j2000_ra
      OK       96711 -1.3269907232295576e+01 -1.3269907232295552e+01    0.00556  1.382e-16  sky_j2000_dec
      OK      321094  1.9426425943521761e+00  1.9426425943521755e+00    2.61780  1.744e-15  sky_j2000_dist
      OK      302748  3.5388201408771312e+02  3.5388201408771533e+02    0.00275  6.086e-15  sky_hor_az
      OK      121119 -2.2454039277279009e+01 -2.2454039277279151e+01    0.00556  7.895e-16  sky_hor_alt
      OK       92717  4.1268347083494783e-03  4.1268347083494774e-03  223.21429  1.936e-16  jm_x
      OK       45091 -8.0149190392649894e-03 -8.0149190392649929e-03   79.42812  2.756e-16  jm_y
      OK      135377  1.5470777280065808e-03  1.5470777280065804e-03  223.21429  9.680e-17  jm_z
      OK      216836  4.5725777238332412e-03  4.5725777238332394e-03  126.58228  2.196e-16  jm_vx
      OK      351647  5.1351566793199944e-03  5.1351566793199962e-03  126.58228  2.196e-16  jm_vy
      OK      351647  2.5217607180929289e-03  2.5217607180929298e-03  126.58228  1.098e-16  jm_vz

    Score = 6.086e-15
2022-04-27 21:18:29 -04:00
Ebrahim Byagowi
7ab343e7d4 kotlin: Avoide code duplication in jupiterMoons by using map 2022-04-28 03:42:01 +04:30
Ebrahim Byagowi
474cffccac kotlin: Use sumOf where possible
As sumOf is inline in Kotlin it supposed to have the same performance.
2022-04-28 02:42:23 +04:30
Ebrahim Byagowi
6789c64343 kotlin: Use idiomatic way to create mutable objects 2022-04-28 01:57:38 +04:30
Ebrahim Byagowi
2fe4c8abf4 kotlin: Use single format instead multiple calls 2022-04-28 01:37:35 +04:30
Ebrahim Byagowi
d2485392c3 kotlin: Use getOrPut to facilitate use of cache 2022-04-28 01:19:36 +04:30
Don Cross
53f5540f09 Kotlin: cleanup of code and documentation.
Used IntelliJ IDEA's linter to perform code cleanup.
There were unused variables, `var` that could be replaced with `val`,
and other minor code style issues.

While doing this, I also discovered that a lot of documentation
links were broken. The fix is to stop intenting the text after
a `@param`.
2022-04-27 14:04:42 -04:00
Don Cross
b93719146b Set version numbers to 2.1.0.
In anticipation of releasing the Kotlin version,
I set the version numbers for the following to 2.1.0:

    Kotlin
    Node.js / npm
    Python / pip

The intention is to keep matching releases of
Astronomy Engine at a common version number.
2022-04-26 15:58:27 -04:00
Don Cross
565bac127a Kotlin docs: link to body enum values.
When documentation refers to a Body value, e.g. Body.Earth,
link to its information page. I'm not sure this is super helpful,
but it is an attempt to provide better linking.

Added more explanatory text about the SSB and EMB values.
I found that a blank line splits the extra text onto the
dedicated pages for SSB and EMB, while leaving the "brief"
description on the list of all Body enum values. That is nice.
2022-04-25 20:43:41 -04:00
Don Cross
4c34245c01 Kotlin doc cleanup: removed more 'jvm' tags.
I found that there were a bunch of lingering 'jvm'
tags in the generated markdown documentation.
Got rid of them with another change to format_kotlin_doc.py.
2022-04-25 17:16:46 -04:00
Don Cross
d130405d13 Kotlin docs: more enum cleanup.
I missed a couple of places where I want to remove
private constructor calls from enum members.
Also, discard [name] and [ordinal] links while preserving
other properties that are intentionally exposed.
2022-04-25 16:51:25 -04:00
Don Cross
b7c7733370 Kotlin docs: fixed backwards enum members.
I reported an issue to Dokka about enum members
being listed backwards in the generated markdown:

https://github.com/Kotlin/dokka/issues/2466

In the meantime, this is a workaround where I reverse the order
of the enum members in my own script format_kotlin_doc.py.
2022-04-25 16:41:19 -04:00
Don Cross
737fb01384 Kotlin docs: remove unwanted enum constructors.
This is a workaround for a Dokka GFM issue I reported:
https://github.com/Kotlin/dokka/issues/2468

I updated the format_kotlin_doc.py script to
remove the internal constructor calls for members of the Body enum.
2022-04-25 16:20:18 -04:00
Don Cross
5708ae36a6 Process Kotlin documentation to fix dokka issues.
The dokkaGfm tool has a few oddities I don't like.
I updated my format_kotlin_doc.py script to work around
a couple of them:

1. Strip out all the noisy [jvm] tags it puts everywhere.

2. Remove the unhelpful and incorrect `Properties` sections
   it adds to all my enum classes and enum members.

I will come back and address other issues later.
2022-04-25 12:56:35 -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
554bbf1b00 Kotlin: calculate Lagrange points.
Calculate the position and velocity of any
of the five Lagrange points for a pair of
Solar System bodies. Added the functions:

    lagrangePoint
    lagrangePointFast
2022-04-21 21:11:44 -04:00
Don Cross
e545677d67 Kotlin: observerGravity function. 2022-04-21 16:04:53 -04:00
Don Cross
567376255c Kotlin: visual magnitude, peak magnitude search.
Implemented the `illumination` function, which calculates
visual magnitude, illuminated phase angle/fraction, and
ring tilt for Saturn.

Implemented `searchPeakMagnitude` for finding when
Venus appears brightest in the sky.
2022-04-20 19:47:21 -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
0af17074f2 Kotlin: elongation function.
This function calculates how easy it is to see a given planet
with respect to the Sun: how far apart they are in the sky,
and whether the planet is easier to see in the morning or evening.
This function is especially helpful for spotting Mercury,
but it works with any body.
2022-04-18 11:41:46 -04:00
Don Cross
17fbf34a71 Kotlin: search lunar perigee, apogee.
Added functions to find a series of consecutive
lunar apsides:

    searchLunarApsis
    nextLunarApsis
2022-04-17 21:29:12 -04:00
Don Cross
f64d22c1c2 Kotlin: search for transits of Mercury and Venus.
Implemented functions searchTransit and nextTransit.
2022-04-17 14:40:59 -04:00
Don Cross
23ed1cda5a Kotlin: added more planet longitude tests.
Generate longitude output files that are tested by
the `generate` program.

Discovered that Windows `run.bat` was not correctly testing
the longitude output test files generated by the JavaScript
code. Fixed that.
2022-04-17 13:30:09 -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
a36d31b75e Merge branch 'kotlin' of https://github.com/ebraminio/astronomy into ebraminio-kotlin 2022-04-16 17:02:05 -04:00
Don Cross
4f387e5fda Kotlin: added heliocentric/topocentric state vector tests. 2022-04-16 16:23:35 -04:00
Ebrahim Byagowi
9cb3a50901 kotlin: Take advantage of functional interface syntax 2022-04-17 00:40:32 +04:30
Don Cross
0ed52f3cea Kotlin: barycentric states, geocentric moon/EMB
Added geoEmbState: calculates the geocentric
state vector of the Earth/Moon Barycenter (EMB).

Added baryState: calculates the barycentric
state vector of a body.

Unit tests now support parsing JPL Horizons
state vector text files.
2022-04-16 15:31:25 -04:00
Don Cross
d5fc878a6a Kotlin: calculate heliocentric ecliptic longitude
Added function: eclipticLongitude.
Verified its calculations against the same function
in the Python version of Astronomy Engine.
2022-04-16 12:59:48 -04:00
Don Cross
b1bc4ccc9b Kotlin: another test for local solar eclipses. 2022-04-16 11:16:44 -04:00
Don Cross
f0b0113806 Kotlin: added local solar eclipse prediction.
Added functions to predict solar eclipses seen
from a specified geographic location on the Earth:

    searchLocalSolarEclipse
    nextLocalSolarEclipse
2022-04-16 10:25:22 -04:00
Don Cross
61e398b592 Kotlin: removed all dependencies on JVM.
The Kotlin version of Astronomy Engine was using Java
classes like `Date` and `GregorianCalendar`.

Reworked the code to use a completely self-contained
representation of calendar date/time, just like the C version does.
Now Astronomy Engine does not depend on anything outside of
the Kotlin standard library. This should allow us to use
Astronomy Engine for Kotlin Native apps, Web Assembly, etc.

Updated Java demo to use the new method Time.fromMillisecondsSince1970.
2022-04-14 10:55:22 -04:00
Ebrahim Byagowi
b06493fd6d kotlin: Improve access of companions object fields/methods in Java 2022-04-13 04:25:22 +04:30
Don Cross
5052920517 Merge pull request #200 from ebraminio/kotlin-sam
kotlin: Move search context to the end of arguments
2022-04-12 19:22:18 -04:00
Ebrahim Byagowi
902f25db3f kotlin: Move search context to the end of arguments
This, in addition to annotating SearchContext interface as functional,
turns it into a more idiomatic Kotlin.
2022-04-13 02:53:39 +04:30
Don Cross
4c4aa3dac4 Merge pull request #199 from ebraminio/kotlin-android-demo
kotlin: Upgrade Android example to use the new namings
2022-04-12 17:25:28 -04:00
Don Cross
77b6edd2ff Kotlin: global solar eclipse search
Added functions:
    searchGlobalSolarEclipse
    nextGlobalSolarEclipse

These functions find a solar eclipse that is visible
somewhere on the Earth. They report the time of the
eclipse, what kind it is (partial, annular, total),
and if annular/total, the geographic location where
the eclipse is greatest.
2022-04-12 16:46:40 -04:00
Ebrahim Byagowi
7ad9487c3e kotlin: Upgrade Android example to use the new namings 2022-04-12 23:29:09 +04:30
Don Cross
74cca88d9e Kotlin: lunar eclipse search
Added functions:
    searchLunarEclipse
    nextLunarEclipse

These allow searching for a series of consecutive
lunar eclipses, including penumbral, partial,
and total eclipses.

Added a few extra functions that will be used soon
to search for solar eclipses (global and local) and
transits of Mercury and Venus.
2022-04-12 14:01:22 -04:00
Ebrahim Byagowi
6ac0dcbff4 kotlin: Directly provide the library to demo
No longer having jitpack as the middle man and just directly building
demo from the project itself.
2022-04-12 12:06:58 +04:30
Don Cross
57a736067a Kotlin: renamed AstroTime, AstroVector.
Renamed AstroTime to Time.
Renamed AstroVector to Vector.
For some reason this breaks the Java demo build.
I'm pushing the broken build anyway to see if
ebraminio can help me fix it.
2022-04-11 20:17:59 -04:00
Don Cross
4b3b445889 Kotlin: added function angleFromSun. 2022-04-10 20:42:31 -04:00
Don Cross
3dd817934e Kotlin: minor code cleanup.
Changed RotationMatrix.identity from a variable to a function.
I want to leave open the possibility of mutating matrices
in the future, for the sake of performance critical code.
That means it is a good idea to create a new matrix to avoid
unintended side effects.

Removed redundant function equatorFromVector.
It was the same as Vector.toEquatorial.

Moved nextMoonQuarter to be right after searchMoonQuarter.
Somehow other functions had ended up between them.

Simpler syntax for initializing SearchContextPeakAltitude.
2022-04-10 17:23:22 -04:00
Don Cross
b1ebd8d0d7 Kotlin: convert AstroVector to Observer.
Added `AstroVector.toObserver`, which converts a
geocentric equatorial vector (EQJ or EQD) into
a geographic location in an `Observer` object.
2022-04-09 19:41:15 -04:00