Question
I need to simulate the moon's orbit around the earth using Vpython programming language. This is my code I used in glowscript but it is
I need to simulate the moon's orbit around the earth using Vpython programming language. This is my code I used in glowscript but it is not working. I need to get the moon and the earth to orbit each other.
s_earth=vector(1.47*10**11,0,0) #position of the earth v_earth=vector(0,30000,0) #velocity of the earth s_moon=vector(1.47384*10**11,0,0) #position of the moon v_moon=vector(0,1022,0) #velocity of the moon m_earth=5.97*10**24 #mass of the earth m_moon=7.35*10**22 #mass of the moon G=6.67*10**30 #gravitational constant
earth=sphere(pos=s_earth,color=color.green,radius=6.37e8) moon=sphere(pos=s_moon,color=color.orange,radius=5e7)
dt=50
while True: rate(10000) s=s_earth-s_moon Fnetmoon=(G*m_moon*m_earth/mag(s_earth-s_moon)**2)*norm(s) a_moon=Fnetmoon/m_moon #acceleration of moon v_moon= v_moon + a_moon *dt #velocity of moon s_moon= s_moon + v_moon *dt #position of moon moon.pos=s_moon Fnetearth=(-G*m_moon*m_earth/mag(s_earth-s_moon)**2)*norm(s_earth-s_moon) a_earth=Fnetearth/m_moon #acceleration of earth v_earth=v_earth+a_earth*dt #velocity of earth s_earth=s_earth+v_earth*dt #position of earth earth.pos=s_earth
print(mag(a_moon)) print(mag(a_earth))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started