Due stelle – 2

\displaystyle b_x = \frac{m_1\cdot x_1 + m_2\cdot x_2}{m_1 + m_2}…
\displaystyle b_y = \frac{m_1\cdot y_1 + m_2\cdot y_2}{m_1 + m_2}…

Lo stesso codice di Due stelle – 1 con calcoli aggiuntivi per la posizione del baricentro

from vpython import *

G = 6.7e-11

stella_1       = sphere(pos = vector(-2e11, 0, 0), radius = 2e10  , color = color.white , make_trail = True)
stella_2       = sphere(pos = vector(+2e11, 0, 0), radius = 1e10  , color = color.yellow, make_trail = True)
baricentro     = sphere(opacity = 0.5            , radius = 2.5e10, color = color.cyan  , make_trail = True)
stella_1.massa = 2.5e30
stella_2.massa = 1.0e30
stella_1.p     = stella_1.massa*vector(0, +1e3, 0)
stella_2.p     = stella_2.massa*vector(0, -1e4, 0)

dt = 1e4
while(True):
    rate(500)

    r = stella_1.pos - stella_2.pos
    F = G*stella_1.massa*stella_2.massa/mag2(r)*r.hat

    stella_1.p    += -F*dt
    stella_2.p    += +F*dt
    stella_1.pos  += stella_1.p/stella_1.massa*dt
    stella_2.pos  += stella_2.p/stella_2.massa*dt

    baricentro.pos.x = (stella_1.massa*stella_1.pos.x + stella_2.massa*stella_2.pos.x) / (stella_1.massa + stella_2.massa)
    baricentro.pos.y = (stella_1.massa*stella_1.pos.y + stella_2.massa*stella_2.pos.y) / (stella_1.massa + stella_2.massa)

Lascia un commento