본문 바로가기
물리코딩

3체 운동

by 로토마 2021. 7. 7.

3체 운동하는 지구 달 토성 

파란 구 - 지구

노란 구 - 토성

흰색 구 - 달

상대적으로 질량이 큰 토성을 기준으로 지구와 달이 그 주위를 도는 것처럼 보인다.

 

코드)

GlowScript 3.0 VPython
#creating objects
r = 385000e3/2
earth = sphere(pos = vector(r,0,0), radius = 6400000, texture = textures.earth)
moon = sphere(pos = vector(-r,0,0), radius = 6400000, make_trail = True)
sat = sphere(pos = vector(0,0,0), radius = 1737000, color = color.yellow, make_trail = True)

#scailing factor
sf = 3
earth.radius = sf*earth.radius
moon.radius = sf*moon.radius
sat.radius = sf*sat.radius

#physical properties
G = 6.67e-11
earth.m = 5.972e24
moon.m = 5.972e24
sat.m = 1/10*earth.m
earth.v = (0,0,0)
moon.v = vec(0,1000,0)
sat.v = vec(0,0,0)

#momentum conservation
earth.v = -moon.v*moon.m/earth.m
attach_trail(earth)
# time
t = 0
dt = 60*5

#simulation loop
while True:
    rate(1000)
    #forces
    r_me = moon.pos - earth.pos
    f_me = -G*earth.m*moon.m/mag(r_me)**2*norm(r_me)
    r_sm = sat.pos - moon.pos
    f_sm = -G*sat.m*moon.m/mag(r_sm)**2*norm(r_sm)
    r_se = sat.pos - earth.pos
    f_se = -G*sat.m*earth.m/mag(r_se)**2*norm(r_se)
    
    #time integration
    earth.v = earth.v + (-f_me-f_se)/earth.m*dt
    moon.v = moon.v + (f_me-f_sm)/moon.m*dt
    sat.v = sat.v + (f_sm+f_se)/sat.m*dt
    earth.pos += earth.v*dt
    moon.pos += moon.v*dt
    sat.pos += sat.v*dt
    t += dt
    

https://www.glowscript.org/#/user/emilyjiminroh/folder/physicscoding/program/3%EC%B2%B4%EC%9A%B4%EB%8F%99

 

GlowScript IDE

GlowScript is an easy-to-use, powerful environment for creating 3D animations and publishing them on the web. Here at glowscript.org, you can write and run GlowScript programs right in your browser, store them in the cloud for free, and easily share them w

www.glowscript.org

 

'물리코딩' 카테고리의 다른 글

등속도, 등속직선, 등가속도 운동  (0) 2021.12.31
수직(자유낙하운동) + 수평(포물선운동)  (0) 2021.06.28
달이 멈춘다면 ?!  (0) 2021.06.24
달의 공전  (0) 2021.06.24
지구의 자전  (0) 2021.06.24