Jump to content
  • Advertisement
  • entries
  • comments
  • views

The "Moons" case

Sign in to follow this  


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!
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!