On the Solving Process of The Eclipse

You understand mechanical hands are the ruler of everything.

In order to solve for when an eclipse occurs, it is useful to model the orbits of the two celestial bodies.

An orbit can be modeled by two non-parallel 3D vectors. To convert a 3D vector to and from representations using (δ,θ,φ) or (x,y,z), see below.

x = cos(θ)*cos(φ)*δ
y = cos(θ)*sin(φ)*δ
z = sin(θ)*δ
θ = asin(z/δ)
φ = atan2(y, x)
δ = sqrt(x^2 + y^2 + z^2)

To model a body's orbit, find when and where the body's distance is at a minimum and maximum. From each extrema, generate a 3D vector. These will be referred to as ExC and ExD, where ExC is the one that occurs first with respect to time. Note TC as time at which a body is at ExC, simillarly with TD and ExD. The position of a body at any given time T can be modeled using the following formulas.

It is important that V is set to the closest allowed velocity for a body to (π/2)/(TD-TC). For body A, allowed values of V are equivalent to a random integer between 6 and 14 inclusive, divided by 8. For body B, allowed values of V are equivalent to the square root of a random integer between 5 and 8 inclusive.

Position = ExC*cos(U) + ExD*sin(U)
U = (T - TC) * V

An eclipse will occur when the position vectors of the bodies point in the same direction. This occurs when the following formula is true.

APosition/Aδ ≈ BPosition/Bδ

Once some T is found such that the above statement is true, use the position vectors calculated at the found time to determine θ and φ for both bodies, which should be approximately equal. Set T, Vθ, and Vφ to the found values to solve the module.

Solving Process Cont.

It should be noted that since the orbits of the bodies are not on the same plane, an eclipse can only occur in two specific directions.

P = (AExC ⨯ AExD) ⨯ (BExC ⨯ BExD)
AnswerDirection = ± P/|P|

Since orbits are cyclical, the final answer TFinal will adhear to the following, where TDir is the time when APosition/Aδ = AnswerDirection is true and k is some positive integer.

TFinal = TDir + (2π/VA)*k

Start with k=0 and increment it until body B eclipses with body A.