Now day's everyone have a computer witch permit quite fast calculating. We using or rather losing its power to things like games. Why not use its to see how the lows of gravity move the planets on our computer screen? We often don't realize how important it can be in imagining how the nature works. It's worth to write a program by yourself which will be able to solving some of this gravitation equation (eg for two body). Here is my try:
I wrote my program in C++ with “allegro” graphic library which contains the basic 2D operations like putting a pixels, drawing lines and other staff which could be useful in program. It contains functions for getting data from keyboard and mouse too. Allegro is open-source project that means it’s for free and have a lot of tutorials.
The whole idea of this algorithm is that it doesn’t calculate position of bodies continuously but cut path S into little pieces: dS and check how will be x, y, Vx, Vy after moving by dS. What is more it must calculate how long took moving from earlier to later position. It can be done if we assume that speed of body during moving by dS doesn’t change, what’s of course can’t be true but for very little jumps and little accelerations it’s quite good approximation. This algorithm has drawback: accelerations of bodies can’t be too big (bigger acceleration, bigger precision, longer counting) I don’t want to give all source of this program because I hope that somebody will write other one and then we will compare results ;).
During writing this article I hit on an idea that good thing to do, is comparing change of total energy of system, it permit to conclude about accuracy of counting.
Here is movie that shows how it works: