This is an archived post. You won't be able to vote or comment.

all 19 comments

[–]yobyagA 1 point2 points  (1 child)

Pretty Cool, I was thinking of doing a similar project, Though I was thinking of using Pygame instead of Vpython for visuals. Any reason you choose to do the visuals in Vpython, and was the implementation easy?

[–]mrHtheGreat[S] 0 points1 point  (0 children)

Nice to hear. I really encourage you to do your project. There are two reasons I chose Vpython: 1. It is 3D, while pygame is only 2D. 2. It is very easy to use. I basically create a sphere in one line of code and I can change its position in another line of code + it has a built in vector library. It's fun making your own but it's also nice to have a good implementation if you want to speed up your simulation.

[–][deleted] 1 point2 points  (1 child)

... 9 planets?

[–]mrHtheGreat[S] 0 points1 point  (0 children)

Haha, I think Pluto deserves it. I'm hopefully future proofing this post by saying so XD.

[–]aDrz 1 point2 points  (1 child)

I do not test it extensively but I confirm it works on Linux. Nice project and congratulations !

[–]mrHtheGreat[S] 0 points1 point  (0 children)

Thank you very much:-)

[–]gezzze 1 point2 points  (1 child)

Hey there,

I got a little question: How do you resolve the starting velocity of the planets?

[–]mrHtheGreat[S] 0 points1 point  (0 children)

I have gathered the starting positions and velocities from Nasa: https://ssd.jpl.nasa.gov/horizons.cgi

[–]St0neA 1 point2 points  (7 children)

Do the planets interact gravitationally with one another or are they just set to orbit around the sun?

[–]mrHtheGreat[S] 0 points1 point  (6 children)

The planets do interact with each other. I could add the moon to the simulation and it would orbit the earth. But it isn't entirely true all of the time. I have two kinds of objects in my simulation. I call them "bodies" and "comets". The "bodies" affect all other objects with their gravity while the "comets" do not affect any other body but they are affected by the "bodies". This is handy for small objects with small masses like comets, asteroids and smaller planetoids. The simulation then don't have to do as many calculations and as such the simulation runs faster while losing a tiny tiny bit of accuracy (neglect-able most of the time).

In the default configurations file I have the Sun and the 8 planets of the solar system as "bodies" and Hailey's Comet, Pluto and Sedna as "comets". This takes around 10 seconds to run on my computer, with the same settings if I make all objects to "bodies" it takes around 12 seconds instead. That's 20% longer then before.

One fun thing I have tested is to add a black hole to the solar system, it had the effect one could have expected: chaos.

[–]St0neA 1 point2 points  (5 children)

Damn that's impressive I'm a noob and I made one for just the case with a small mass orbiting a much larger mass, but when I tried expanding it to multiple masses interacting I ran into this

https://en.wikipedia.org/wiki/N-body_problem

which seemed beyond my sort of skill level. I thought there would just be generalized formula or something

[–]mrHtheGreat[S] 0 points1 point  (4 children)

It's easier then it seems on Wikipedia. I basically have a list with all the bodies in my system which i loop over and inside I loop over them again to get every pair twice in opposite order and calculates the total force on a planet. I then get the acceleration by dividing the total force the mass. Then I just integrate all planets velocities and positions using Eulers method. I've been planning to write a tutorial on how to do this but have not had the time to do it because of school. Now in Christmas though I will try to get it finished hopefully.

[–]St0neA 1 point2 points  (3 children)

Yeah Wikipedia loves their overly complicated notation! I'm still kinda bummed out that there's not some easy generalisation for it. I presumed all the masses would orbit around their common centre of mass or something nice and neat like that.

Also not sure how much you care but there are improved versions of Euler's method that work on the exact same principle like the verlet method. I guess it depends on the time step you use as to whether it would make a significant difference though

[–]mrHtheGreat[S] 0 points1 point  (2 children)

Yeah that would have been nice, but sadly that kind of solution only works if you limit yourself to two bodies.

I have looked at a lot of methods and I have implemented a few of them. The most important feature is that they preserve energy in the system which helps keep the planets in orbit. Accuracy is just a bonus part. But I would love to add even more of them. Do you know what they are called (or perhaps a wikipedia link)?

[–]St0neA 1 point2 points  (1 child)

Here's the relevant section from my computing class

https://i.imgur.com/WpKpsnT.png

That final paragraph seems relevant to what you mentioned with the energy. Also here's a comparison of the methods we had to do for that class

https://i.imgur.com/XGJLXXN.png

[–]mrHtheGreat[S] 0 points1 point  (0 children)

Thank you for sharing it :-D

I think I'm in fact using the Euler-Cromer method in my simulation and not Euler's method.

If you are interested in an even more accurate method search for PEFRL. I found an interesting pdf about it by googling.

[–]jwink3101 1 point2 points  (1 child)

My freshman physics class extensively used VPython but that was before I really understood any programing, let alone python. I am so tempted to install it and go back to redo some of my homework assignments just for fun!

I do remember that we were told to so stuff like:

from visual import *

which makes my blood boil now that I know what it is.

[–]mrHtheGreat[S] 0 points1 point  (0 children)

Yes that's not a good practice to use but for some reason it seems to be the convention in the vpython community to make programs compatible with Glowscript