Predicting Future Eclipses with Three.js

Uses threejs to help find eclipses
demo here

  • Get the positions of the Sun, Earth, and Moon.
  • Check out my API if you’re interested (any feedback would be greatly appreciated!) https://orbital-api.com/ & https://orbital-api.com/allPlanetsSvEciOnEcef
  • Propagate the Sun, Earth, and Moon
  • Cast a ray from the Moon in the direction of the Sun.
  • If that ray intersects the Earth, it might be an eclipse.

What I find neat is that Earth’s rotation (once every 24 hours) is completely decoupled from the Sun-Earth-Moon’s orbits. Yet, the simulated eclipses are pretty close to professional estimates.

Change the time scale to speed things up.



5 Likes

Looks nice.

Do you plan to develop if further?

In case you do, you could add a fast forward mode to next eclipse (or fast rewind to previous), and once there turn into slow motion. Also, the moon’s shadow casted on the earth surface would be a nice touch.

3 Likes

Great ideas! I’m sure the next eclipse could be found with a while loop and the shadow would be great! Wonder if I would try it in shader code or with threejs lights :thinking:

Added the suggestions! But now that I have pause, backward, and forward buttons, I’m a bit worried I might be introducing some bugs. ¯_(ツ)_/¯

Also calling the raycaster, while intersecting, was causing slowdowns (understandably, it was called 5000 times per animation frame). Since I’m only casting to a perfect sphere (earth), I wrote a custom raycaster that seems a bit faster!

updated demo

For faster calculations you may use some filters which determine whether an eclipse is probable. And raycast only when it is probable.

Filter 1: if the distance sun-moon d is less than some value, there might be eclipse:

Filter 2: if the angle between sun-moon and sun-earth \alpha is less that some value, there might be eclipse:

1 Like

that is not a bad idea!

Why so many?

For this physics model, I need a small time step and check for eclipses (intersections) at every step. Since it uses real space data, when simulating over months or years, it progresses using a dt of only a few minutes in size

1 Like