Help Scaling Gravity Simulation

  • #1
SacCno
2
0
TL;DR Summary
I'm trying to scale the solar system down to around 1:1,000,000,000 for a game I'm making, need help with scaling formulae, forces, velocities etc.
I'm trying to make a 2D game on Unity similar to Universe Sandbox 2. I currently am working with a star and planet, both with roughly the masses of the sun and earth respectively for comparison and at a distance of 31,000,000km.

My current model uses Newton's formula for gravitational force (F = GM1M2 / R2) and then dividing it by the planet's mass to get acceleration towards the star due to gravity. I then use the formula (v = √GMsun/R) to get the orbital velocity. My full process is as follows.
  1. Calculate force.
  2. Divide by planet's mass to get acceleration towards the star.
  3. Calculate orbital velocity.
  4. Divide both by 1,000,000,000 to get scaled down values.
  5. Multiply both by 525,600 (minutes in a year) to speed up simulation to one year per minute.
I then apply both initial orbital velocity and add acceleration towards the star every frame. These are my input values:
  • Msun = 2e30kg
  • Mearth = 6e24kg
  • R = 31units * 1,000,000,000 = 31,000,000,000m
  • G = 0.0000000000667
The values I get from the above steps are:
  • Unscaled Orbital Velocity = 65,598.97718m/s
  • Scaled Orbital Velocity = 34.4788224m/s = 34.4788224units/s
  • Unscaled Force = 8.32882414e23N
  • Scaled Force = 4.37762997e20N
  • Unscaled Acceleration = 0.1388137357m/s/s
  • Scaled Acceleration = 7.29604995e-5m/s/s = 7.29604995e-5units/s/s
The important values there are the scaled orbital velocity (34.48m/s) and scaled acceleration towards the star (7.296e-5m/s/s). Given that the earth has a velocity of roughly 30km/s and the acceleration towards the sun is around 0.006m/s/s the two values I got and the difference between them didn't alarm me too much.

My issue came when I started the simulation and the ≈30m/s of initial velocity sent the planet shooting off into the cosmos. I've obviously made a big mistake somewhere in my calculations but after a few days of trial and error I still can't figure it out. I asked on the Unity forums and got some really handy tips for my simulation as a whole but nothing seemed to address my issue of how to scale my physics. I suspect that my scaling needs to be done inside the formulae to some degree but I've no idea where to start if that is the case.

Any help would be great, and if you need any more information please let me know.
 
Physics news on Phys.org
  • #3
That website's really cool! I did initially use some of Kepler's laws as a stopgap in the beginning with the planet moving in a simple orbit around the sun, this was very linear and not dynamic at all and I'm not too sure how I could make a dynamic system using Kepler, especially if I want the player to be able to throw other planets/stars/black holes into the mix wherever they want, if you have an idea I'd be more than happy to hear!

I'm kinda laying the track as I go, but unless you think a force model is a really bad approximation I think I'll stick to it.

I'm not too concerned about the accurate scaled size of the planet's right now, down the line maybe, but once they're smaller than the sun I'll be happy for now, currently the earth is technically 1,000,000km in diameter 😅 I'm just trying to wrap my head around why the orbital velocity and gravitational acceleration are so out of whack. Again I'm pretty sure I'm being too simplistic with my scaling, but I don't know in what way.
 
  • #4
"Debug my code for me" is a pretty big ask.
Doing so without the code is an even bigger ask.

I don't understand why you are scaling at all. If it's for a sensible display, do the calculation and then plot the code at some smaller scale, e.g. plot(x/1000000000, y/1000000000).
 
  • Like
Likes Motore
  • #5
Vanadium 50 said:
I don't understand why you are scaling at all. If it's for a sensible display, do the calculation and then plot the code at some smaller scale, e.g. plot(x/1000000000, y/1000000000).
this^^
 
  • #7
SacCno said:
My issue came when I started the simulation and the ≈30m/s of initial velocity sent the planet shooting off into the cosmos. I've obviously made a big mistake somewhere in my calculations but after a few days of trial and error I still can't figure it out.
This may or may not be an issue with scaling. You might need a different integrator (the code that calculates the new velocities and positions of the objects). A 'basic' integrator won't cut it. You need a symplectic integrator, which is one that approximately conserves energy. Examples include the leap-frog and modified Euler integrators.

See here: https://carma.astro.umd.edu/nemo/pitp/papers/gd2_s3.4.pdf
Leapfrog example with code: https://www.johndcook.com/blog/2020/07/13/leapfrog-integrator/
Another paper with examples of many different integrators: https://www.researchgate.net/public..._Techniques_in_Orbital_Mechanics_Applications (look into the Verlet integrator)

If you need help understanding the algorithms and converting them to code, let me know. I had to do the same thing earlier this year in a simulation I created.
 
  • Like
Likes vanhees71
  • #8
Scaling down distances by a factor of 1 billion would give a scaled down distance from the earth to the sun about 500 feet. Is that what you really want?
 

1. How can I scale a gravity simulation?

To scale a gravity simulation, you can adjust the gravitational constant, the mass of the objects, and the distance between them. By changing these parameters, you can modify the strength of the gravitational force acting between the objects.

2. What is the importance of scaling in a gravity simulation?

Scaling is important in a gravity simulation as it allows you to simulate scenarios that may not be feasible in real life due to differences in scale. By scaling down the size of objects or increasing the strength of gravity, you can observe the effects of gravity in a more controlled and manageable environment.

3. Can scaling affect the accuracy of a gravity simulation?

Yes, scaling can affect the accuracy of a gravity simulation. When scaling down the size of objects or increasing the strength of gravity, you may encounter issues such as numerical instability or inaccuracies in the simulation results. It is important to carefully consider the implications of scaling on the accuracy of the simulation.

4. Are there any limitations to scaling a gravity simulation?

There are limitations to scaling a gravity simulation, such as the computational resources required to simulate large-scale scenarios. Additionally, scaling may not accurately represent real-world physics in extreme scenarios, such as when objects are extremely close together or have very high masses.

5. How can I ensure that my scaled gravity simulation is realistic?

To ensure that your scaled gravity simulation is realistic, you can validate the results against known physical laws and empirical data. Additionally, you can perform sensitivity analyses to understand how changes in scaling parameters affect the simulation outcomes. Collaborating with other scientists and experts in the field can also help validate the realism of your simulation.

Similar threads

Replies
86
Views
4K
  • Classical Physics
Replies
15
Views
2K
  • Classical Physics
Replies
4
Views
2K
  • Introductory Physics Homework Help
Replies
18
Views
1K
  • Special and General Relativity
Replies
33
Views
1K
Replies
2
Views
1K
  • Astronomy and Astrophysics
Replies
7
Views
4K
  • Introductory Physics Homework Help
Replies
3
Views
969
  • Special and General Relativity
Replies
27
Views
4K
  • High Energy, Nuclear, Particle Physics
Replies
6
Views
1K
Back
Top