Draft

Three Body Problem

18 of 19Mo0dy

Description:

Three-body problem

Hello Everyone,

There is a famous problem in physics that can (only) be solved using Computers: The Three-body problem.

It is the problem of computing the trajectories of three bodies where their initial velocities, positions and masses are given. In this Kata you will solve the problem in 2d (all masses are on the same plane). You will receive three scalars m1, m2 and m3 as well as six lists (mathematical vectors) v1, v2, v3, p1, p2, p3 with two entries each describing the initial masses, velocities and positions of the three bodies respectively. You are expected to give the position of the FIRST mass after a total time sim_time has passed. The result needs to be in error range of +- 10 of the correct solution. The position should be returned as a list with two entries.

Note: time, positions, velocities and masses are all in "Units"

Also v, and p are vectors (lists):

vi = [vi_x, vi_y]
pi = [pi_x, pi_y]
solution = [p1_x, p1_y]

These differential equations govern the system:

a1=Gm2(p1p2)/p1p23Gm3(p1p3)/p1p33,a1 = -G * m2 * (p1 - p2) / |p1 - p2|^3 - G * m3 * (p1 - p3) / |p1 - p3|^3,
a2=Gm1(p2p1)/p2p13Gm3(p2p3)/p2p33,a2 = -G * m1 * (p2 - p1) / |p2 - p1|^3 - G * m3 * (p2 - p3) / |p2 - p3|^3,
a3=Gm2(p3p2)/p3p23Gm1(p3p1)/p3p13a3 = -G * m2 * (p3 - p2) / |p3 - p2|^3 - G * m1 * (p3 - p1) / |p3 - p1|^3

where a1 to a3 are the accelerations of the masses respectively and G is the gravitational constant with

G=10000G = 10000

Note that these are vector equations. This means every single equations describes both the x and y components of the acceleration (ai) and position (pi) vectors. Note that in this context the absolute of a 2d vector v = (v_x, v_y) is defined as follows:

v=sqrt(vx2+vy2)|v| = sqrt(v_x^2 + v_y^2)

If your solution is slightly off the numerial error in your solution might be too great. Try decreasing the stepsize.

The wikipedia page describing the problem: https://en.wikipedia.org/wiki/Three-body_problem

Spoiler: One of the simplest numerical integrators: https://en.wikipedia.org/wiki/Euler_method

Note: Only initial conditions that lead to differential equations in the region of stability of the euler-cauchy integrator will be tested.

Algorithms

Stats:

CreatedAug 1, 2018
Warriors Trained63
Total Skips0
Total Code Submissions140
Total Times Completed19
Python Completions18
Total Stars5
% of votes with a positive feedback rating82% of 11
Total "Very Satisfied" Votes7
Total "Somewhat Satisfied" Votes4
Total "Not Satisfied" Votes0
Total Rank Assessments11
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • Mo0dy Avatar
  • hobovsky Avatar
Ad