Created
August 19, 2020 01:13
-
-
Save ahmedazizkhelifi/a4c6fb44b43ac2c3c86f78ada954503b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while (True): | |
vp.rate(500) | |
#Calculte the force using gravitationalForce function | |
star.force = gravitationalForce(star,planet1)+gravitationalForce(star,planet2)+gravitationalForce(star,planet3) | |
planet1.force = gravitationalForce(planet1,star)+gravitationalForce(planet1,planet2)+gravitationalForce(planet1,planet3) | |
planet2.force = gravitationalForce(planet2,star)+gravitationalForce(planet2,planet1)+gravitationalForce(planet2,planet3) | |
planet3.force = gravitationalForce(planet3,star)+gravitationalForce(planet3,planet1)+gravitationalForce(planet3,planet2) | |
#Update momentum, position and time | |
star.momentum = star.momentum + star.force*dt | |
planet1.momentum = planet1.momentum + planet1.force*dt | |
planet2.momentum = planet2.momentum + planet2.force*dt | |
planet3.momentum = planet3.momentum + planet3.force*dt | |
star.pos = star.pos + star.momentum/star.mass*dt | |
planet1.pos = planet1.pos + planet1.momentum/planet1.mass*dt | |
planet2.pos = planet2.pos + planet2.momentum/planet2.mass*dt | |
planet3.pos = planet3.pos + planet3.momentum/planet3.mass*dt | |
t += dt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment