• entries
232
1463
• views
961833

# The "Moons" case

259 views

I just discovered that, even if the simulation was globally correct, the moons in particular were not. They're moving 500 times too fast compared to their real velocity.

I didn't spot the problem first because the orbits are correct. I have in my code a function which, given a time in days, returns me the position of the planet (or moon) on its orbit. Making this function was no easy task, but after spending many days on the net and studying celestial motions, i thought i got it right.

Well..no. Specifically, in that function, there was a hard-coded parameter (the mean angle the body traverses each day around its parent) which i found on a formula over the net, which is only valid for bodies rotating around the sun. In case of moons, you have a planet rotating around another planet. Hence the parameter was incorrect.

I fixed it by calculating it with this algorithm:
1. Calculating the length of the orbit (it's an ellipse)
2. Calculating the mean velocity (it's dependant of the distance and the mass of the parent)
3. Dividing the two => this is the period (amount of days it takes to make a 360? rotation around the parent).
4. Dividing 360? by the period => gives the angle the body traverses each day.

I found that there is no real mathematical solution to the length of an ellipse, only approximations. But fortunately in most cases, the orbits are near circular, so the approximation is good.

After that, i made a test to see if the Moon was correctly rotating around the Earth in 27.8 days, and it was. Yipeee!

There are no comments to display.

## Create an account

Register a new account