Three Body Problem

Not trying to solve the problem, but trying to simulate movement of multiple bodies in gravitational bound situation and project it onto a screen. See setup below.

Config:

(1e1 to 10e10)
(1 to 100)
(1 to 1000)
[, ] as [width, height]


    

Setup

Basic idea is to calculate discrete movement periods. At any point in time any object has a known position and speed (3D vectors). Every object has a known mass. Gravitational pull can be calculated from a total mass and weighted position of all other masses - this induces a force, which induces an acceleration, which with fixed time per run enables to calculate new positions and speeds. Repeat.

So we need:

To display this, we need an observer and a screen. We assume both are fixed in space and have no mass (which is unrealistic as hell). The observer watches the center of screen orthogonally without blinking. This setup is available in simulation and in reality and is represented in the virtual display at this html page. Having this, we can project an object to the screen in simulation resulting in a position in screen's coordinates. This can be shown in virtual screen using same coordinates. (see also Abbildung auf Mattscheibe [de])

So we need:

Finding the screen's coordinate system in simulation

The screen's center is located at screen_center_position_3d_m [p] and is oriented to observation_target_3d_m [t]. The vector t-p being observation_vector_3d_m [o] is orthogonal to the screens axes screen_axes_xy_m [x] and [y]. Both have fixed length being the screen's width [w] and height [h] from real_screen_size_xy_m, resulting coordinates in screen will be factors of +/-.5.

  1. o→≔ t→ - p→
  2. o→⋅x→≔0 ∧ o→⋅y→≔0
  3. ‖x→‖≔w ∧ ‖y→‖≔h

Break down into coordinates assuming ∀v→. v→≔ [ v1 v2 v3 ]T in 3D.

  1. (2) ⇒ o1x1+ o2x2+ o3x3=0
  2. (2) ⇒ o1y1+ o2y2+ o3y3=0
  3. (3) ⇒ x12+ x22+ x32= w2
  4. (3) ⇒ y12+ y22+ y32= h2

Screen shall be upside up, therefor we search for a solution for y with y2 being max (second coordinate assuming being the "up" direction). Eliminate y3 by setting (5) into (7).

  1. (5) ⇒ y3= -o1×y1 + -o2×y2 o3 = -o1o3 ×y1 + -o2o3 ×y2
  2. into (7) ⇒ y12+ y22+ ( -o1o3 ×y1 + -o2o3 ×y2 ) 2= h2
  3. ⇒ y12+ y22+ o12 o32 ×y12+ 2× o1o2 o32 ×y1×y2+ o22 o32 ×y22 = h2
  4. ⇒ ( 1+ o22 o32 ) ×y22 + 2× o1o2 o32 ×y1 ×y2 + ( 1+ o12 o32 ) ×y12 = h2
  5. ⇒ o32+ o22 o32 ×y22 + 2× o1× o2 o32 ×y1 ×y2 = h2- o32+ o12 o32 ×y12
  6. ⇒ (o32+ o22) ×y22 + 2× (o1× o2) ×y1 ×y2 = h2 o32- (o32+ o12) ×y12
  7. ⇒ y22+ 2× o1× o2 o32+ o22 ×y1 ×y2 = h2 o32 o32+ o22 - o32+ o12 o32+ o22 ×y12

Simplify by replacing complex but constant elements:

  1. c1≔ o1× o2 o32+ o22 ∧ c2≔ h2 o32 o32+ o22 ∧ c3≔ o32+ o12 o32+ o22
  2. ⇒ y22+ 2 c1 y1 y2 = c2 - c3 y12
  3. ⇒ ( y2 + c1 y1 ) 2 - ( c1 y1 ) 2 = c2 - c3 y12
  4. ⇒ ( y2 + c1 y1 ) 2 = ( c12 - c3 ) × y12 + c2
  5. ⇒ y2 = - c1 y1 ± ( c12 - c3 ) × y12 + c2

This formula shows y2 being derived only from y1 and constant parameters. To maximize y2 we need to set the derivative to 0. According to chain rule ∀f(x)≔g(h(x)).f'(x)=g'(h(x))×h'(x) and because the derivative of x is 12x we get:

  1. y2' = -c1 ± 1 2 × ( c12 - c3 ) × y12 + c2 × ( 2 × ( c12 - c3 ) × y1 + 0 )
  2. y2'≔0⇒ c1 = ± ( c12 - c3 ) × y1 ( c12 - c3 ) × y12 + c2
  3. ⇒ c12 = ( ( c12 - c3 ) × y1 ) 2 ( c12 - c3 ) × y12 + c2
  4. ⇒ c12 × ( ( c12 - c3 ) × y12 + c2 ) = ( c12 - c3 ) 2 × y12
  5. ⇒ c12 × ( c12 - c3 ) × y12 - ( c12 - c3 ) 2 × y12 = - c12 × c2
  6. ⇒ ( c12 - ( c12 - c3 ) ) × ( c12 - c3 ) × y12 = - c12 × c2
  7. ⇒ c3 × ( c12 - c3 ) × y12 = - c12 × c2
  8. ⇒ y1 = ± - c12 × c2 c3 × ( c12 - c3 )

The positive is the relevant solution; using (27), (19) und (8), y→ can be calculated. For x→ we have to go back to (4) and (6), adding that x and y have to be orthogonal, too. All is fixed now except x:

  1. o1x1+ o2x2+ o3x3=0
  2. x12+ x22+ x32= w2
  3. y1x1+ y2x2+ y3x3=0
  4. (3) ⇒ x3 = - y1 y3 × x1 - y2 y3 × x2
  5. into (1) ⇒ x2 = c4 x1 ∧ c4 ≔ o1 y3 + o3 y1 o2 y3 + o3 y2
  6. into (2) ⇒ x12 + ( c4 x1 ) 2 + ( - y1 y3 × x1 - y2 y3 × ( c4 x1 ) ) 2 = w2
  7. into (2) ⇒ x12 × ( 1 + c42 - y1 y3 - y2 y3 × c4 ) 2 = w2
  8. into (2) ⇒ x1 = ± w 1 + c42 - y1 y3 - y2 y3 × c4

Taking the positive value show be sufficient; using (8), (5) and (4), x→ can be calculated.

Project to virtual screen

Every object i has a position in simulation objects_positions_sim_3d_m[i] (j→) and a diameter of objects_diameters_m[i] (d). Screen position and size and observer and observation target position in simulation are well-known based on previous calculation: screen_center_position_sim_3d_m (p→), screen_size_xy_sim_3d_m (x→, y→), observer_position_sim_3d_m (s→), observation_target_sim_3d_m (t→).

s, p and t form a line; x and y are orthogonal to this line at point p. We search a and b for (p + ax + by) is between s and j - being the virtual position of j on screen as seen from s. This means there is a c for (p + ax + by) = s + c * (j-s). We get a standard linear system of equations:

  1. x1 * a + y1 * b + (s1-j1) * c = s1-p1
  2. x2 * a + y2 * b + (s2-j2) * c = s2-p2
  3. x3 * a + y3 * b + (s3-j3) * c = s3-p3

For simplicity take k=s-j and q=s-p and solve it. If a and b are in [-0.5;+0.5] they can be seen at screen. The diameter will be d*||s-(p+ax+by)||/||s-j|| in simulation measures divided by average of ||x|| and ||y|| for relative screen measures.

  1. c = q3/k3 - x3/k3*a - y3/k3*b
  2. x2*a + y2*b + k2*(q3/k3 - x3/k3*a - y3/k3*b) = q2
  3. x2*k3*a + y2*k3*b + k2*q3 - x3*a - y3*b = q2*k3
  4. b = (q2*k3-k2*q3)/(y2*k3 - y3) + (x3-x2*k3)/(y2*k3 - y3)*a
  5. define c5 = (q2*k3-k2*q3)/(y2*k3 - y3), c6 = (x3-x2*k3)/(y2*k3 - y3)
  6. x1*a + y1*(c5+c6*a) + k1*(q3/k3 - x3/k3*a - y3/k3*(c5+c6*a)) = q1
  7. x1*a + y1*c5 + y1*c6*a + k1*q3/k3 - k1*x3/k3*a - k1*y3/k3*c5 - k1*y3/k3*c6*a = q1
  8. a = (q1 - y1*c5 - k1*q3/k3 + k1*y3/k3*c5)/(x1 + y1*c6 - k1*x3/k3 - k1*y3/k3*c6)

References

[SI] Wikipedia contributors. (2026, September 11). International System of Units. In Wikipedia, The Free Encyclopedia. Retrieved 06:20, September 12, 2026, from https://en.wikipedia.org/w/index.php?title=International_System_of_Units&oldid=1374353568

[solsys] Wikipedia contributors. (2026, September 7). List of Solar System objects. In Wikipedia, The Free Encyclopedia. Retrieved 08:43, September 12, 2026, from https://en.wikipedia.org/w/index.php?title=List_of_Solar_System_objects&oldid=1373762538

[Newton] Wikipedia contributors. (2026, August 23). Newton's law of universal gravitation. In Wikipedia, The Free Encyclopedia. Retrieved 12:39, September 12, 2026, from https://en.wikipedia.org/w/index.php?title=Newton%27s_law_of_universal_gravitation&oldid=1370960529

[MathML] W3C. (2026, July 27). MathML Core. In W3C Editor's Draft. Retrieved Sept 12, 2026, from https://w3c.github.io/mathml-core/ and https://www.w3.org/TR/MathML3/appendixc.html