cosinekitty / astronomy

Astronomy Engine: multi-language calculation of Sun, Moon, and planet positions. Predicts lunar phases, eclipses, transits, oppositions, conjunctions, equinoxes, solstices, rise/set times, and other events. Provides vector and angular coordinate transforms among equatorial, ecliptic, horizontal, and galactic orientations.
MIT License
418 stars 59 forks source link

JS VectorObserver / inverse_terra sometimes fails to converge #347

Open tostt opened 1 month ago

tostt commented 1 month ago

There is a possible heisenbug with VectorObserver(). When running the following loop, I end up with the error Uncaught inverse_terra failed to converge (for the value ts=1717780096005).

const body = Astronomy.Body.Sun
for (let ts = 1717780096000; ts <= 1717780096200; ts++) {
   var date = new Date(ts);
   var vect = Astronomy.GeoVector(body, date, true)
   console.log('ts, date, vector', ts, date.valueOf(), vect)
   var point = Astronomy.VectorObserver(vect)
   console.log('point', point)
   console.log('*')
}

However, when I change the starting point of the loop, say from 1717780096000 to 1717780096001, the program falls in error later in the loop. Is anyone able to reproduce this error ?

cosinekitty commented 1 month ago

Thank you for your bug report! I have confirmed this is a real problem. I am investigating, and will report back here when I have an update.

cosinekitty commented 1 month ago

Here is a stack trace using unminified code:

$ node --trace-uncaught test vecobs

/home/don/github/astronomy/source/js/astronomy.js:1942
                throw `inverse_terra failed to converge.`;
                ^
inverse_terra failed to converge.
Thrown at:
    at inverse_terra (/home/don/github/astronomy/source/js/astronomy.js:1942:17)
    at VectorObserver (/home/don/github/astronomy/source/js/astronomy.js:2700:12)
    at VectorObserverTest (/home/don/github/astronomy/generate/test.js:2857:30)
    at main (/home/don/github/astronomy/generate/test.js:3719:16)
    at /home/don/github/astronomy/generate/test.js:3727:14
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at executeUserEntryPoint (node:internal/modules/run_main:86:12)

Node.js v18.18.0
cosinekitty commented 1 month ago

This commit was not supposed to close the issue. Re-opening now, because there are more changes coming.