<p><strong>There isn't a general closed form solution for the n-body problem for n&gt;2, so a general solution to this problem can't be given without additional constraints on the problem.</strong> Does the planet orbit both stars in a close binary system from far away?  Or does the planet orbit only one of the stars in a wide binary system?  Can we consider the orbits to be Keplerian for a good enough approximation?</p>
<p>If we have an engine that gives us the positions of the bodies at any time, we can perform a numerical solution as follows.  Given the positions <span class="math-container">$\vec{p}_s$</span> of a star, an observer <span class="math-container">$\vec{p}_p$</span>, and a moon <span class="math-container">$\vec{p}_m$</span> at any particular time <span class="math-container">$t$</span>,</p>
<p><a href="https://i.sstatic.net/PtlGQ.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/PtlGQ.jpg" alt="enter image description here" /></a></p>
<p>the <a href="https://en.wikipedia.org/wiki/Angular_diameter" rel="nofollow noreferrer">apparent angular radius</a> of the moon in the sky as observed from the planet is <span class="math-container">$$\theta_m = \sin^{-1}\biggl(\dfrac{r_m}{|\vec{p}_m-\vec{p}_p|}\biggr)$$</span> where <span class="math-container">$r_m$</span> is the radius of the moon.  Similarly, the apparent angular radius of a star as observed from the planet is <span class="math-container">$$\theta_s = \sin^{-1}\biggl(\dfrac{r_s}{|\vec{p}_s-\vec{p}_p|}\biggr)$$</span> where <span class="math-container">$r_s$</span> is the radius of the star.</p>
<p>It should be clear that the only way a total stellar eclipse is possible is if <span class="math-container">$\theta_m \geq \theta_s$</span>.</p>
<p>To obtain the angular separation <span class="math-container">$\alpha$</span> between the center of the star and the center of the moon in the sky as observed from the planet, we start with the definition of the vector dot product:  <span class="math-container">$A \cdot B  = |A||B|\cos(\alpha)$</span>, and solve for <span class="math-container">$\alpha$</span> to get <span class="math-container">$$\alpha = \cos^{-1}\biggl(\frac{A \cdot B}{|A||B|}\biggr) $$</span></p>
<p>Here, <span class="math-container">$A = \vec{p}_m-\vec{p}_p$</span>, and <span class="math-container">$B = \vec{p}_s-\vec{p}_p$</span> are vectors to the star and moon from the observer rather than the reference system origin.</p>
<p>If <span class="math-container">$\theta_m+\theta_s \geq \alpha$</span>, then an eclipse is occurring at time <span class="math-container">$t$</span>.  In addition, if <span class="math-container">$\theta_m \geq \theta_s+\alpha$</span> a total eclipse is occurring.</p>
<p><strong>Notes:</strong></p>
<ol>
<li><p>This is a solution for only a single star for simplicity. For additional stars the same above equations can be used.</p>
</li>
<li><p>How do you choose the right value of <span class="math-container">$t$</span> to correspond to the time of eclipses when you don't know when the eclipse will occur?  Try many values of <span class="math-container">$t$</span> in a loop with small increments. Where values of <span class="math-container">$\alpha$</span> are small, try even smaller increments of <span class="math-container">$t$</span> over smaller intervals.</p>
</li>
</ol>

CC BY-SA 4.0
2021-08-05T20:12:23.253Z
Thank you for your detailed response! The planet does in fact orbit both stars and I have updated the post to include more information regarding the system if this gives you further insights. For now, this is the closest answer I have so thank you!
Linus
CC BY-SA 4.0
2021-08-05T19:59:59.863Z
2021-08-05T19:59:59.863Z
Connor Garcia
<p>I agree with @ConnorGarcia's answer that numerical solutions are the only practical way to go here.</p>
<p>Further evidence can be found in the following paragraph from the <a href="http://spaceengine.org/news/blog180817/" rel="nofollow noreferrer">site's webpage</a> which was noted in the question.</p>
<p>In fact, noticing this bit and pointing it out was a great call; it's really the gateway to understanding what's going on here!</p>
<blockquote>
<p>Over the past month I have worked on planet <a href="https://en.wikipedia.org/wiki/Ephemeris" rel="nofollow noreferrer">ephemerides</a><sup>1</sup>. They are <strong>data tables and pieces of code, which provide the precise positions and velocities of the Solar system’s planets and moons at a given moment in time.</strong> Previously, SpaceEngine used <a href="https://en.wikipedia.org/wiki/Kepler_orbit" rel="nofollow noreferrer">Kepler orbits</a> – they are a good approximation of the motion of a planet around the Sun (or of a moon around a planet) without any perturbations. But the real Solar system is not so simple, we have multiple planets and moons which pull each other with their gravity. This perturbs their orbits, making the Keplerian solution inaccurate. The most significant perturbations are applied to the moons, as you can see on the video below – their orbits precess and wobble.</p>
</blockquote>
<p>I'm pretty sure this means that the author got a numerical integrator (a library function or bit of standard code), put some starting positions, velocities and directions (<a href="https://en.wikipedia.org/wiki/Orbital_state_vectors" rel="nofollow noreferrer">state vectors</a>) into it and let it run for a few hundred &quot;years&quot; or &quot;centuries&quot;.</p>
<h3>What does &quot;data tables and pieces of code&quot; mean?</h3>
<p>They produced an ephemeris (one or more) which is a data table of positions (and sometimes other parameters) at a large number of points in time. They also provided <em>interpolators</em> or &quot;pieces of code&quot; that you would give a series of time points to, and it would look up the closest time values in the ephemeris and interpolate between the fixed points of the table.</p>
<p>Many astronomical ephemerides contain the positions and <em>interpolation coefficients</em> to make the interpolation more accurate. NASA Jet Propulsion Laboratory's <a href="https://en.wikipedia.org/wiki/Jet_Propulsion_Laboratory_Development_Ephemeris" rel="nofollow noreferrer">Development Ephemerides</a> are a wonderful and well-known example. It's not important here, but they use a <a href="https://space.stackexchange.com/search?q=+chebychev">custom-defined implementation of Chebychev polynomials</a> that even out the residual interpolation error along the trajectory.</p>
<p>In order to obtain eclipses, one would simply apply some kind of &quot;potential eclipse detector&quot; or generalized event detector to the problem.</p>
<p>You would scan the ephemeris table and look for regions where the Sun-planet-moon angle is small. This is shown in @ConnorGarcia's answer.</p>
<h3>But.. HOW???</h3>
<p>If you can't get the ephemeris that's used inside the game/model, then try to make one for yourself.</p>
<p>Run the game for a century or millennium and output x, y, z positions for the stars, planet and moon, or if that's not possible, output the star-planet-moon angle for each star.</p>
<p>Then calculate those vectors and look for local minima. Easiest way is to caclulate the changes in angle from one time point to the next. You've found a minimum or at least inflection point if you multiply two adjacent changes together and the product is either zero or negative.</p>
<p>In Python, that would be:</p>
<pre><code>d_theta = theta[1:] - theta[:-1]
dd_theta = d_theta[1:] * d_theta[:-1]
inflections_and_minima = dd__theta &lt;= 0
</code></pre>
<p>It's tempting to use <code>&lt;</code> instead of <code>&lt;=</code> but there's an extremely tiny chance that two points could straddle a minimum leading to an accidental 0.</p>
<hr />
<p><sup>1</sup><a href="https://english.stackexchange.com/q/370655/217285">How to pronounce “Ephemerides”?</a> hint: it's not eee-FEM-er-IDES.</p>

CC BY-SA 4.0
2021-08-08T20:15:40.863Z
Thank you! Currently I’m working out an answer with what was suggest by you and other comments as well as papers regarding orbits!! Unfortunately, there is not easy way to gather x, y, z coordinates from space engine. The cfg files show coordinates relative to the barycenter but I can’t figure out what units they are in. When comparing my calculations of star positions my numbers seem wildly off from what is seen in the files. In game, RA/Dec/Dist is used which is rather annoying…as of now I’ve emailed the developer to get some answers regarding the x, y, z coordinates
Linus
CC BY-SA 4.0
2021-08-08T20:24:47.330Z
It’s also my understanding that Kepler mechanics are used for systems procedurally generated
Linus
CC BY-SA 4.0
2021-08-09T00:37:00.413Z
@Linus You can always grab a block of numbers and post it as a new question; "What coordinates are these and how can I change them to state vectors?" If it's spherical coordinates it shouldn't be hard to convert. For reverse-engineering of a game I'm not sure that Astronomy SE is the right site; I'd suggest [Space Exploration SE](https://space.stackexchange.com/) or possibly [Gaming SE](https://gaming.stackexchange.com/). You can look around both sites; I think Space SE is better since they deal with state vectors all the time. Ping me if you do.
uhoh
CC BY-SA 4.0
2021-08-10T18:30:04.057Z
I will probably post another question here soon regarding calculating positions of binary stars in their relative orbits. I can't find good information on how to calculate this and I want to be sure my calculations are correct before going any further. A link to my code so far can be found here: (https://github.com/Libnus/Orbit_Calculations) if you are interested (the positions of the stars are being calculated but are off because it's a two body problem thus the calculations are wrong :/)
Linus
CC BY-SA 4.0
2021-08-10T23:23:20.747Z
@Linus I ran that and see that `n=33180038844.0443` rad/sec can't be right, I wonder if `math.sqrt((u)/(math.pow(a, 3)))` should use `a_in_meters` instead? The first step is to just do the calculation step-by-step by hand with a calculator or paper, or if you're not old-school, then one line at a time in Python to see if everything makes sense. You can do this calculation for Earth in orbit around the Sun for more familliar units; you know what to expect. Don't put everything into functions until you are confident of the math inside them.
uhoh
CC BY-SA 4.0
2021-08-10T23:27:19.610Z
Also, I have found it easier to use reduced units. u = 1, a=1, and T = 2. Once that works, then I redo it with physical units. For exponentiation `a**3` is the same operation as `math.pow(a, 3)` and try to start using the `numpy` library instead of `math` library because once you start using numpy arrays you'll find Python really starts to shine for calculating things! Here's a comparison of numerical versus Keplerian solutions in Python:  https://space.stackexchange.com/a/31247/12102
uhoh
CC BY-SA 4.0
2021-08-11T16:08:31.753Z
Thank you for your continued help and advise, I just made the changes you suggested (a_in_meters was supposed to be written obviously) :) I see that numpy is an extremely powerful tool, still only just learning python so thank you! I have also done the calculations on paper with simpler systems but when I do calculations for the binary star system my values are still off. I am not exactly sure what is going on here. The code also works for these simpler systems. I used calculations for our solar system and another procedurally generated one from Space engine and it was correct...
Linus
CC BY-SA 4.0
2021-08-11T22:48:15.760Z
@Linus okay keep at it, step-by-step, and I think you'll get it all worked out nicely. You can ask as many questions as you like in Stack Exchange, and those that show effort ("I tried the following but it's not working") usually get speedy and helpful answers.
uhoh
CC BY-SA 4.0
2021-11-10T18:17:10.583Z
One thought related to @uhoh and the importance of reduced units, as this is an ugly n-body problem that you forced to do a step-wise MD type simulation to find the positions, is that if your units you're using result in wildly different values (say one unit is very large, say 5.5^15, but another is very small, 5.5^-15, using floats to do the calculations, is that you will *absolutely* get huge roundoff errors.  Using reduced units, so that all the variables in your calculation have similiar order of magnitude will avoid that.
Richard
CC BY-SA 4.0
2021-11-10T21:13:32.760Z
@Richard Indeed! Going reduced, with positions and velocities at least *somewhat* closer to unity sometimes helps when defining a tolerance used for defining an integration step size. When a state vector (say Jupiter's) has three numbers of order $10^12$ (m) and three of $10^4$ (m/s) the automatic step size choosing algorithm may not work as desired.
uhoh
CC BY-SA 4.0
2021-08-08T01:55:19.477Z
2021-08-08T01:55:19.477Z
uhoh
<p><em><strong>How could one calculate eclipses on a planet (in a game) with one moon and orbiting two stars?</strong></em></p>
<p><strong>More Info:</strong></p>
<p>Every so often--roughly every 5 years--the moon (this planet has a single moon) is in a position to cause a partial eclipse on the planet (i.e. blocking only one star). If you’re lucky, you may even witness a total eclipse where both stars are blocked. A full Synodic period for this planet is almost 11 years. I have yet to find a method to find out when such anomalies will occur next.</p>
<p>Eclipses occur roughly every 5 years. I do not know the month or the day or if there will be a total eclipse where both stars are blocked in a given year.</p>
<p>So far, I used <a href="https://worldbuilding.stackexchange.com/questions/113256/calculating-eclipse-periods">this</a> page to find the Saros period. Unfortunately, my calculations were off (can this page even be used for a double star system?). These sets of equations are also geared towards a moon that is on the same orbital plane as our moon which is not the case at all with this fictional moon and system.</p>
<p>A picture is worth 1,000 words so I will provide one here rather than further describe the <em>star orbit:</em></p>
<p><a href="https://i.sstatic.net/nLl8G.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/nLl8G.gif" alt="Star orbit" /></a></p>
<p><strong>1:</strong> Is there a way to calculate when eclipses will happen in this star system?</p>
<p><strong>2:</strong> Is there a way to calculate if it will be a total eclipse (given the positions of the stars, center of mass etc.)?</p>
<hr />
<hr />
<p>The game is quite advanced; orbits are simulated and so is gravity. From what I can tell this is “as close as it gets” for a video game. Information regarding the orbits, masses, gravity, velocity and everything in between can be found within the game and provided here.</p>
<p>Nonetheless, I want to know how to do this just for fun even if it can’t be predicted within the game.</p>
<p>Here is the wiki pages for the game:</p>
<p>*<em><a href="https://en.wikipedia.org/wiki/SpaceEngine" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/SpaceEngine</a></em> (wiki page)</p>
<p><em><a href="https://se-database.fandom.com/wiki/Space_Engine_Database" rel="nofollow noreferrer">https://se-database.fandom.com/wiki/Space_Engine_Database</a></em> (planetary database)</p>
<p><em><a href="http://spaceengine.org/" rel="nofollow noreferrer">http://spaceengine.org/</a></em> (main website)*</p>
<p><strong>As a side note: I am referring to a solar eclipse that can be seen on the surface of this planet where one or both stars are blocked by the moon that orbits</strong></p>
<p><strong>EDIT:</strong></p>
<p>The planet orbits both stars. As do the other planets.</p>
<p>There is a rather large Neptune like planet nearby which could be affecting the planet. Below are some more images/gif animations to show the system in more detail. The moon also appears to be affecting the orbit of the planet! Because of this, the planet has a slight wobble which is also shown below.</p>
<p><em>Planet Orbit (Planet orbit is highlighted in pink; the nearby Neptune planet is the next orbit):</em></p>
<p><em><a href="https://i.sstatic.net/YQGS3.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/YQGS3.gif" alt="Planet Orbit:" /></a></em></p>
<p><em>Planet Wobble (most likely because of moon orbiting close by, its mass is is about half of the moon's but it is much closer at a distance of 83,799 km or 52,070 mi):</em></p>
<p><a href="https://i.sstatic.net/eJSJ4.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/eJSJ4.gif" alt="enter image description here" /></a></p>
<p><em>Moon Orbit Showing Eclipse (as mentioned before, every 5 or 6 years the moon goes through a cycle of eclipses blocking each star roughly 5 times depending on their positions):</em></p>
<p><a href="https://i.sstatic.net/0Z7qM.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/0Z7qM.gif" alt="enter image description here" /></a></p>
<p><strong>Planet Data (gathered from game):</strong></p>
<p>Inclination: <em>-1 degree</em></p>
<p>Orbital Period: <em>10.802 years</em></p>
<p>Pericenter/Apocenter: <em>8.7571 AU/10.0095 AU</em></p>
<p>Mass: <em>0.16163 M⊕</em></p>
<p><em><strong>Moon Data:</strong></em></p>
<p>Inclination: <em>0 degrees</em></p>
<p>Orbital Period: <em>7.205</em></p>
<p>Diameter: <em>2,556 km or 1,588 mi</em></p>
<p>Mass: <em>0.55884 Lunar Mass or 0.00687 M⊕</em></p>
<p>Distance to Planet: <em>83,799 km or 52,070 mi</em></p>
<p><em><strong>Neptune Planet Data:</strong></em></p>
<p>Inclination: <em>0 degrees</em></p>
<p>Orbital Period: <em>7.205</em></p>
<p>Mass: <em>13.569 M⊕</em></p>
<p>Diameter: <em>361,859 km or 224,849 mi</em></p>
<p>Orbital Period: <em>15.481 years</em></p>
<p>Pericenter/Apocenter:<em>11.0257 AU/12.8287 AU</em></p>
<p>Distance to Planet: <em>15.37 AU</em></p>
<p>Hill/Sphere of Influence: <em>0.14 AU/0.10 AU</em></p>
<p>There are many planets in it but the closest is the Neptune like planet.</p>
<p>We can also say that the game uses Keplerian orbits for simplicity; although this page (<a href="http://spaceengine.org/news/blog180817/" rel="nofollow noreferrer">http://spaceengine.org/news/blog180817/</a>) has a quote that confuses me slightly:</p>
<blockquote>
<p>Previously, SpaceEngine used Kepler orbits – they are a good approximation of the motion of a planet around the Sun (or of a moon around a planet) without any perturbations. But the real Solar system is not so simple, we have multiple planets and moons which pull each other with their gravity.</p>
</blockquote>
<p>I think this can be ignored for simplicity sake because it is more talking about our solar system not this procedurally generated one. Additionally, I am not sure that the engine is advanced enough to simulate exact orbits.</p>

CC BY-SA 4.0
2021-08-05T18:08:55.107Z
Wow, this game is a charm! Anyway, from the picture I can't understand whether the planet is orbiting just one star, or is orbiting both of them. I think that a general method to calculate eclipses in a binary system could be very complicated. Maybe you could describe better the configuration of the planets and the stars, to narrow down the problem
Prallax
CC BY-SA 4.0
2021-08-05T18:12:38.080Z
Nice things to know would be if the orbit of the planet is inclined with respect to the stars orbit; if the moon is big enough to have a non-negligible gravitational influence on the motion of the planet; if the orbit of the moon is inclined as well; if there are other planets that could influence the system (like a very close jupiter)... any additional information would be helpful
Prallax
CC BY-SA 4.0
2021-08-05T19:12:02.780Z
Thinking about it some more, I came to the conclusion that probably there is no nice formula to calculate the eclipses on a binary system. I'd love to be proven wrong, though. Normally I'd try and do a simulation, to resolve the issue, at least numerically. But since spaceengine is already a simulation, it would be rather pointless in this case.
Prallax
CC BY-SA 4.0
2021-08-05T20:12:05.643Z
@Parallax, this is what I feared. Regardless, I have updated the post to include some more information about the system if anyone has a slightest clue about where to begin. Thank you for your comment :)
Linus
CC BY-SA 4.0
2021-08-07T19:34:22.910Z
@linus  Is the planet supposed to be habitable?  I find it hard to believe that the circumsteller habitable zone of two stars (low mas enough to have a habtable planet) could extend that far out.  I note you didn't describe the characteristis of the stars from the game.  Their diameters will determine whether the moon with its diameter and distance will be able to fully eclipse them.
M. A. Golding
CC BY-SA 4.0
2021-08-08T01:56:54.810Z
@Linus this is pretty cool, thanks for mentioning this program! I've added an answer, please feel free to comment if something can be clarified.
uhoh
CC BY-SA 4.0
2021-08-08T23:50:30.067Z
@M. A. Golding this planet is not habitable. While far away from the stars, the atmosphere is extremely toxic being about 97 percent co2. At least according to the game, life is not present. I will add the diameters and distances of the stars to the post I just need to gather the data! Thank you for pointing this out
Linus
<orbit><orbital-mechanics><binary-star><solar-eclipse>
How to calculate eclipses on a planet in a binary star system
Linus
# How to calculate eclipses on a planet in a binary star system

(Asked by: username_0 on 2021-08-05)

***How could one calculate eclipses on a planet (in a game) with one moon and orbiting two stars?***

**More Info:**

Every so often--roughly every 5 years--the moon (this planet has a single moon) is in a position to cause a partial eclipse on the planet (i.e. blocking only one star). If you’re lucky, you may even witness a total eclipse where both stars are blocked. A full Synodic period for this planet is almost 11 years. I have yet to find a method to find out when such anomalies will occur next.

Eclipses occur roughly every 5 years. I do not know the month or the day or if there will be a total eclipse where both stars are blocked in a given year.

So far, I used [this](https://worldbuilding.stackexchange.com/questions/113256/calculating-eclipse-periods) page to find the Saros period. Unfortunately, my calculations were off (can this page even be used for a double star system?). These sets of equations are also geared towards a moon that is on the same orbital plane as our moon which is not the case at all with this fictional moon and system.

A picture is worth 1,000 words so I will provide one here rather than further describe the *star orbit:*

[![Star orbit](https://i.sstatic.net/nLl8G.gif)](https://i.sstatic.net/nLl8G.gif)

**1:** Is there a way to calculate when eclipses will happen in this star system?

**2:** Is there a way to calculate if it will be a total eclipse (given the positions of the stars, center of mass etc.)?

---

---

The game is quite advanced; orbits are simulated and so is gravity. From what I can tell this is “as close as it gets” for a video game. Information regarding the orbits, masses, gravity, velocity and everything in between can be found within the game and provided here.

Nonetheless, I want to know how to do this just for fun even if it can’t be predicted within the game.

Here is the wiki pages for the game:

\**<https://en.wikipedia.org/wiki/SpaceEngine>* (wiki page)

*<https://se-database.fandom.com/wiki/Space_Engine_Database>* (planetary database)

*<http://spaceengine.org/>* (main website)\*

**As a side note: I am referring to a solar eclipse that can be seen on the surface of this planet where one or both stars are blocked by the moon that orbits**

**EDIT:**

The planet orbits both stars. As do the other planets.

There is a rather large Neptune like planet nearby which could be affecting the planet. Below are some more images/gif animations to show the system in more detail. The moon also appears to be affecting the orbit of the planet! Because of this, the planet has a slight wobble which is also shown below.

*Planet Orbit (Planet orbit is highlighted in pink; the nearby Neptune planet is the next orbit):*

*[![Planet Orbit:](https://i.sstatic.net/YQGS3.gif)](https://i.sstatic.net/YQGS3.gif)*

*Planet Wobble (most likely because of moon orbiting close by, its mass is is about half of the moon's but it is much closer at a distance of 83,799 km or 52,070 mi):*

[![enter image description here](https://i.sstatic.net/eJSJ4.gif)](https://i.sstatic.net/eJSJ4.gif)

*Moon Orbit Showing Eclipse (as mentioned before, every 5 or 6 years the moon goes through a cycle of eclipses blocking each star roughly 5 times depending on their positions):*

[![enter image description here](https://i.sstatic.net/0Z7qM.gif)](https://i.sstatic.net/0Z7qM.gif)

**Planet Data (gathered from game):**

Inclination: *-1 degree*

Orbital Period: *10.802 years*

Pericenter/Apocenter: *8.7571 AU/10.0095 AU*

Mass: *0.16163 M⊕*

***Moon Data:***

Inclination: *0 degrees*

Orbital Period: *7.205*

Diameter: *2,556 km or 1,588 mi*

Mass: *0.55884 Lunar Mass or 0.00687 M⊕*

Distance to Planet: *83,799 km or 52,070 mi*

***Neptune Planet Data:***

Inclination: *0 degrees*

Orbital Period: *7.205*

Mass: *13.569 M⊕*

Diameter: *361,859 km or 224,849 mi*

Orbital Period: *15.481 years*

Pericenter/Apocenter:*11.0257 AU/12.8287 AU*

Distance to Planet: *15.37 AU*

Hill/Sphere of Influence: *0.14 AU/0.10 AU*

There are many planets in it but the closest is the Neptune like planet.

We can also say that the game uses Keplerian orbits for simplicity; although this page (<http://spaceengine.org/news/blog180817/>) has a quote that confuses me slightly:

> Previously, SpaceEngine used Kepler orbits – they are a good approximation of the motion of a planet around the Sun (or of a moon around a planet) without any perturbations. But the real Solar system is not so simple, we have multiple planets and moons which pull each other with their gravity.

I think this can be ignored for simplicity sake because it is more talking about our solar system not this procedurally generated one. Additionally, I am not sure that the engine is advanced enough to simulate exact orbits.

**Tags:** orbit, orbital-mechanics, binary-star, solar-eclipse

> **Comments:**
> **username_1**: Wow, this game is a charm! Anyway, from the picture I can't understand whether the planet is orbiting just one star, or is orbiting both of them. I think that a general method to calculate eclipses in a binary system could be very complicated. Maybe you could describe better the configuration of the planets and the stars, to narrow down the problem  
> **username_1**: Nice things to know would be if the orbit of the planet is inclined with respect to the stars orbit; if the moon is big enough to have a non-negligible gravitational influence on the motion of the planet; if the orbit of the moon is inclined as well; if there are other planets that could influence the system (like a very close jupiter)... any additional information would be helpful  
> **username_1**: Thinking about it some more, I came to the conclusion that probably there is no nice formula to calculate the eclipses on a binary system. I'd love to be proven wrong, though. Normally I'd try and do a simulation, to resolve the issue, at least numerically. But since spaceengine is already a simulation, it would be rather pointless in this case.  
> **username_0**: @Parallax, this is what I feared. Regardless, I have updated the post to include some more information about the system if anyone has a slightest clue about where to begin. Thank you for your comment :)  
> **username_2**: @username_0  Is the planet supposed to be habitable?  I find it hard to believe that the circumsteller habitable zone of two stars (low mas enough to have a habtable planet) could extend that far out.  I note you didn't describe the characteristis of the stars from the game.  Their diameters will determine whether the moon with its diameter and distance will be able to fully eclipse them.  
> **username_3**: @username_0 this is pretty cool, thanks for mentioning this program! I've added an answer, please feel free to comment if something can be clarified.  
> **username_0**: @username_2 this planet is not habitable. While far away from the stars, the atmosphere is extremely toxic being about 97 percent co2. At least according to the game, life is not present. I will add the diameters and distances of the stars to the post I just need to gather the data! Thank you for pointing this out  

---

## 2 answers

### Answer by username_4 on 2021-08-05. Score: 2 | Accepted answer

**There isn't a general closed form solution for the n-body problem for n>2, so a general solution to this problem can't be given without additional constraints on the problem.** Does the planet orbit both stars in a close binary system from far away? Or does the planet orbit only one of the stars in a wide binary system? Can we consider the orbits to be Keplerian for a good enough approximation?

If we have an engine that gives us the positions of the bodies at any time, we can perform a numerical solution as follows. Given the positions $\vec{p}\_s$ of a star, an observer $\vec{p}\_p$, and a moon $\vec{p}\_m$ at any particular time $t$,

[![enter image description here](https://i.sstatic.net/PtlGQ.jpg)](https://i.sstatic.net/PtlGQ.jpg)

the [apparent angular radius](https://en.wikipedia.org/wiki/Angular_diameter) of the moon in the sky as observed from the planet is $$\theta\_m = \sin^{-1}\biggl(\dfrac{r\_m}{|\vec{p}\_m-\vec{p}\_p|}\biggr)$$ where $r\_m$ is the radius of the moon. Similarly, the apparent angular radius of a star as observed from the planet is $$\theta\_s = \sin^{-1}\biggl(\dfrac{r\_s}{|\vec{p}\_s-\vec{p}\_p|}\biggr)$$ where $r\_s$ is the radius of the star.

It should be clear that the only way a total stellar eclipse is possible is if $\theta\_m \geq \theta\_s$.

To obtain the angular separation $\alpha$ between the center of the star and the center of the moon in the sky as observed from the planet, we start with the definition of the vector dot product: $A \cdot B = |A||B|\cos(\alpha)$, and solve for $\alpha$ to get $$\alpha = \cos^{-1}\biggl(\frac{A \cdot B}{|A||B|}\biggr) $$

Here, $A = \vec{p}\_m-\vec{p}\_p$, and $B = \vec{p}\_s-\vec{p}\_p$ are vectors to the star and moon from the observer rather than the reference system origin.

If $\theta\_m+\theta\_s \geq \alpha$, then an eclipse is occurring at time $t$. In addition, if $\theta\_m \geq \theta\_s+\alpha$ a total eclipse is occurring.

**Notes:**

1. This is a solution for only a single star for simplicity. For additional stars the same above equations can be used.
2. How do you choose the right value of $t$ to correspond to the time of eclipses when you don't know when the eclipse will occur? Try many values of $t$ in a loop with small increments. Where values of $\alpha$ are small, try even smaller increments of $t$ over smaller intervals.

> **Comments:**
> **username_0**: Thank you for your detailed response! The planet does in fact orbit both stars and I have updated the post to include more information regarding the system if this gives you further insights. For now, this is the closest answer I have so thank you!  

---

### Answer by username_3 on 2021-08-08. Score: 2

I agree with @username_4's answer that numerical solutions are the only practical way to go here.

Further evidence can be found in the following paragraph from the [site's webpage](http://spaceengine.org/news/blog180817/) which was noted in the question.

In fact, noticing this bit and pointing it out was a great call; it's really the gateway to understanding what's going on here!

> Over the past month I have worked on planet [ephemerides](https://en.wikipedia.org/wiki/Ephemeris)1. They are **data tables and pieces of code, which provide the precise positions and velocities of the Solar system’s planets and moons at a given moment in time.** Previously, SpaceEngine used [Kepler orbits](https://en.wikipedia.org/wiki/Kepler_orbit) – they are a good approximation of the motion of a planet around the Sun (or of a moon around a planet) without any perturbations. But the real Solar system is not so simple, we have multiple planets and moons which pull each other with their gravity. This perturbs their orbits, making the Keplerian solution inaccurate. The most significant perturbations are applied to the moons, as you can see on the video below – their orbits precess and wobble.

I'm pretty sure this means that the author got a numerical integrator (a library function or bit of standard code), put some starting positions, velocities and directions ([state vectors](https://en.wikipedia.org/wiki/Orbital_state_vectors)) into it and let it run for a few hundred "years" or "centuries".

### What does "data tables and pieces of code" mean?

They produced an ephemeris (one or more) which is a data table of positions (and sometimes other parameters) at a large number of points in time. They also provided *interpolators* or "pieces of code" that you would give a series of time points to, and it would look up the closest time values in the ephemeris and interpolate between the fixed points of the table.

Many astronomical ephemerides contain the positions and *interpolation coefficients* to make the interpolation more accurate. NASA Jet Propulsion Laboratory's [Development Ephemerides](https://en.wikipedia.org/wiki/Jet_Propulsion_Laboratory_Development_Ephemeris) are a wonderful and well-known example. It's not important here, but they use a [custom-defined implementation of Chebychev polynomials](https://space.stackexchange.com/search?q=+chebychev) that even out the residual interpolation error along the trajectory.

In order to obtain eclipses, one would simply apply some kind of "potential eclipse detector" or generalized event detector to the problem.

You would scan the ephemeris table and look for regions where the Sun-planet-moon angle is small. This is shown in @username_4's answer.

### But.. HOW???

If you can't get the ephemeris that's used inside the game/model, then try to make one for yourself.

Run the game for a century or millennium and output x, y, z positions for the stars, planet and moon, or if that's not possible, output the star-planet-moon angle for each star.

Then calculate those vectors and look for local minima. Easiest way is to caclulate the changes in angle from one time point to the next. You've found a minimum or at least inflection point if you multiply two adjacent changes together and the product is either zero or negative.

In Python, that would be:

```
d_theta = theta[1:] - theta[:-1]
dd_theta = d_theta[1:] * d_theta[:-1]
inflections_and_minima = dd__theta <= 0

```

It's tempting to use `<` instead of `<=` but there's an extremely tiny chance that two points could straddle a minimum leading to an accidental 0.

---

1[How to pronounce “Ephemerides”?](https://english.stackexchange.com/q/370655/217285) hint: it's not eee-FEM-er-IDES.

> **Comments:**
> **username_0**: Thank you! Currently I’m working out an answer with what was suggest by you and other comments as well as papers regarding orbits!! Unfortunately, there is not easy way to gather x, y, z coordinates from space engine. The cfg files show coordinates relative to the barycenter but I can’t figure out what units they are in. When comparing my calculations of star positions my numbers seem wildly off from what is seen in the files. In game, RA/Dec/Dist is used which is rather annoying…as of now I’ve emailed the developer to get some answers regarding the x, y, z coordinates  
> **username_0**: It’s also my understanding that Kepler mechanics are used for systems procedurally generated  
> **username_3**: @username_0 You can always grab a block of numbers and post it as a new question; "What coordinates are these and how can I change them to state vectors?" If it's spherical coordinates it shouldn't be hard to convert. For reverse-engineering of a game I'm not sure that Astronomy SE is the right site; I'd suggest [Space Exploration SE](https://space.stackexchange.com/) or possibly [Gaming SE](https://gaming.stackexchange.com/). You can look around both sites; I think Space SE is better since they deal with state vectors all the time. Ping me if you do.  
> **username_0**: I will probably post another question here soon regarding calculating positions of binary stars in their relative orbits. I can't find good information on how to calculate this and I want to be sure my calculations are correct before going any further. A link to my code so far can be found here: (https://github.com/Libnus/Orbit_Calculations) if you are interested (the positions of the stars are being calculated but are off because it's a two body problem thus the calculations are wrong :/)  
> **username_3**: @username_0 I ran that and see that `n=33180038844.0443` rad/sec can't be right, I wonder if `math.sqrt((u)/(math.pow(a, 3)))` should use `a_in_meters` instead? The first step is to just do the calculation step-by-step by hand with a calculator or paper, or if you're not old-school, then one line at a time in Python to see if everything makes sense. You can do this calculation for Earth in orbit around the Sun for more familliar units; you know what to expect. Don't put everything into functions until you are confident of the math inside them.  
> **username_3**: Also, I have found it easier to use reduced units. u = 1, a=1, and T = 2. Once that works, then I redo it with physical units. For exponentiation `a**3` is the same operation as `math.pow(a, 3)` and try to start using the `numpy` library instead of `math` library because once you start using numpy arrays you'll find Python really starts to shine for calculating things! Here's a comparison of numerical versus Keplerian solutions in Python:  https://space.stackexchange.com/a/31247/12102  
> **username_0**: Thank you for your continued help and advise, I just made the changes you suggested (a_in_meters was supposed to be written obviously) :) I see that numpy is an extremely powerful tool, still only just learning python so thank you! I have also done the calculations on paper with simpler systems but when I do calculations for the binary star system my values are still off. I am not exactly sure what is going on here. The code also works for these simpler systems. I used calculations for our solar system and another procedurally generated one from Space engine and it was correct...  
> **username_3**: @username_0 okay keep at it, step-by-step, and I think you'll get it all worked out nicely. You can ask as many questions as you like in Stack Exchange, and those that show effort ("I tried the following but it's not working") usually get speedy and helpful answers.  
> **username_5**: One thought related to @username_3 and the importance of reduced units, as this is an ugly n-body problem that you forced to do a step-wise MD type simulation to find the positions, is that if your units you're using result in wildly different values (say one unit is very large, say 5.5^15, but another is very small, 5.5^-15, using floats to do the calculations, is that you will *absolutely* get huge roundoff errors.  Using reduced units, so that all the variables in your calculation have similiar order of magnitude will avoid that.  
> **username_3**: @username_5 Indeed! Going reduced, with positions and velocities at least *somewhat* closer to unity sometimes helps when defining a tolerance used for defining an integration step size. When a state vector (say Jupiter's) has three numbers of order $10^12$ (m) and three of $10^4$ (m/s) the automatic step size choosing algorithm may not work as desired.  

---

