Help Scaling Gravity Simulation

Click For Summary

Discussion Overview

The discussion revolves around the challenges of scaling a gravity simulation in a 2D game developed in Unity, specifically focusing on the calculations of gravitational forces, orbital velocities, and the implications of scaling these values for a realistic simulation. Participants explore various models and approaches to address issues encountered in the simulation.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • The original poster describes their method of using Newton's gravitational formula and scaling down values for a simulation involving a star and a planet.
  • Some participants suggest that Kepler's laws might be more suitable for the simulation, although the original poster expresses uncertainty about how to implement a dynamic system based on these laws.
  • One participant questions the necessity of scaling at all, proposing that calculations could be done at full scale and then plotted at a smaller scale for display purposes.
  • Another participant mentions the potential need for a different integrator, suggesting that a symplectic integrator might be necessary to conserve energy in the simulation.
  • Concerns are raised about the implications of scaling down distances significantly, questioning whether the scaled distances align with the original intent of the simulation.

Areas of Agreement / Disagreement

Participants express differing views on the necessity and method of scaling in the simulation. While some suggest alternative approaches, there is no consensus on the best method to resolve the issues faced by the original poster.

Contextual Notes

Participants note that the original poster's scaling approach may be overly simplistic, and there are unresolved questions regarding the integration methods used in the simulation. Additionally, the implications of scaling on the physical representation of distances and velocities remain unclear.

SacCno
Messages
2
Reaction score
0
TL;DR
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
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.
 
"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   Reactions: Motore
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^^
 
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   Reactions: vanhees71
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?
 

Similar threads

Replies
4
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 86 ·
3
Replies
86
Views
8K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 16 ·
Replies
16
Views
1K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 22 ·
Replies
22
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K