- Home /
It's impossible to make realistic n-body solar system simulation in matter of size and mass?
i have been develeping n-body phyics to simulate our solar system, so i have been gathering data around to make it as realistic as possible. But there is a problem with the data size. I searched every tiny bit of internet and i couldn't find a single explanation how people overcomes this. (If they so) So i trying my shot here.
So, to keep the ratio of distance, radius and "mass" between planets fixed, i created an xml file to calculate all the datas. (Because why the heck would someone put "what would be the earth's mass if it had "that" radius chart" on the internet?) I will give the ss as attachment. It basicly "normalizes" or in other words "scales" every property of a planet to a given reference. In this case, i took the reference as "earth's radius."
I work in unity, and you know, you can't work with "too big" or "too small" values in unity. So i had to scale the solar system down, "a lot!"
So i use the Newton's law of universal gravitation, which is F = GMm/r^2, to make it simple, i am directly calculating the a = GM/r^2, for a given body from all other bodies.
So, the real value of earth's gravitational acceleration "towards sun" is roughly 0,000006 km/s^2, which is even incredibly small value to work with in unity, but it could work. Yet, to get this value,1 i need to set earth's radius (scale) to 6371 unit, and sun to scale of 696,342!, which is TOO big to render it in unity.
So i said, let the earth's radius be 1, in unity units. So, when the radius changes, everything changes, the mass, the distance... I kept the density of the planet and calculate the mass from the new volume with the new radius. All the calculations are in the attachment.
So the thing is, when i take the earth's radius as 1, the gravitational accelaration towards sun becomes is something like 0,0000000000009 which is ridiculously small. And of course Unity doesn't work with that value.
So, if i increase the earth's radius instead, then the mass and radius of the Sun gets ridiculously big and then again, i can't work with it.
I don't know how other people fixed this, what they did to overcome this problem but as i see from here, it looks impossible to make realistic n-body simulation of solar system. (in unity atleast)
Here is the link to the attachment. http://berkaydursun.com/solar_system_simulator/data.PNG Also one directory up is the working experimental solar system simulation with n-body calculations but with UNREALISTIC values. It works quite well, and it even looks somehow close to real, but no, it doesn't have the right ratios ^^ You can test it here if you wish http://berkaydursun.com/solar_system_simulator/
The solution is probably to do the calculations of position and such in the background, and then make a rougher approximation when you're showing the graphical representation.
Do your calculations with the sun and planets having their "real" size, and then do a crazy amount of rounding when you're showing them on the screen.
a n-body solar system with unity physics engine, so excited about your idea. maybe unity will do sth about the floating point limitation in the future.
If you use an unsigned 64-bit integer (UInt64), the number limit will be 2^64 or 18,446,744,073,709,551,615.
Just for comparison: The mass of the Sun: 19,890,000,000 $$anonymous$$g The $$anonymous$$ax distance of Pluto from the sun: 7,376,000,000,000 m
Unless you are trying to do something crazy like simulate every molecule/atom in the solar system or simulate every particle in the universe, you should probably be fine.
Answer by EZS · Dec 14, 2020 at 01:22 PM
4 years later...
I began working on this problem myself, and I believe I may have thought of a solution:
Store body coordinates in a custom double accuracy Vector3 class that can store huge Vector3s. Have a n-body gravity manager that calculates the vector and magnitude of local bodies' in relation to one-another. Apply G as change in Velocity over time. This system may require complexity during creation, as the sun has "gravity trenches" where other planets dig out areas that stabilize orbits, and "hill" areas that will destabilize orbits.
The scale of a star system is incomprehensible, but a simple solution to floating-point-deterioration uses Vector3Doubles(a custom class storing the top whole numbers of a vec3 and bottom decimals in 2 separate vec3s). These positions and distances are still far to large to simulate with Unity's base engine, however, by having the origin of the scene follow the observer we can simulate local space, while calculating system space with simple orbital calculations scaled with Time.
Old thread, relevant issue, I hope someone sees this.
This is a very interesting thread and I do have to say that, modelling accurate representations of real-life things such as planets or atoms are impractical. There are limitations to how close to realism, models and diagrams of objects can become. For example, in an atom, the nucleus is extremely small, compared to the space that the atom takes up. A majority of an atom is empty space! Also, electrons compared to protons and neutrons are... another can of scaling worms
This thread is specifically talking about n-body gravity calculations. Your solution is for a much different problem of how to render scale. While this is a real problem, it doesn't feel like your solution addresses the context of the question.
Additionally, even when an object is parented to another, the position of the object is still calculated using world coordinates, meaning after all the scaling, you'd still be left with a big jittery sphere, or an object too large to render.
Use multiple scenes stacked on top of each other, or layers with each scale composited in. Each layer or level would be scaled appropriately to the max level of floating point precision. One for the solar, one for the surface, one for the current sector of the galaxy. It could be extended from there, and if you allow streaming you could navigate between the scales in real time, swapping out what layer is rendering what scale etc.
Shadows can be done per layer this way per scale allowing for each layer to have to scale shadows. Keeping everything with in the 6-7(1/2) digit precision allowed in 32bit floats.
https://blog.demofox.org/2017/11/21/floating-point-precision/ Or move to 64 bit world space.
Another way would be do all calculations yourself, and just have the data render directly to a render texture bypassing the 32bit unity world limit.
I did find this. https://blog.mapbox.com/wgs84-precision-in-unity-world-space-687c7d574bb3
It really depends if you want to use unity world based systems like animations, physics and so on. If you can get away with streaming and doing all your own calculations. The render to texture method would be your best bet I think.
Compositing layers also allows you to simulate great distances by adjusting the scale of the compositing. Even from surface to solar, or solar to galaxy, you shrink down the layers in the composite with out needing to scale the actual level. In theory
Answer by commadorecoder64 · Mar 17 at 07:18 AM
Use multiple scenes stacked on top of each other, or layers with each scale composited in. Each layer or level would be scaled appropriately to the max level of floating point precision. One for the solar, one for the surface, one for the current sector of the galaxy. It could be extended from there, and if you allow streaming you could navigate between the scales in real time, swapping out what layer is rendering what scale etc.
Shadows can be done per layer this way per scale allowing for each layer to have to scale shadows. Keeping everything with in the 6-7(1/2) digit precision allowed in 32bit floats.
https://web.archive.org/web/20211216224919/https://blog.demofox.org/2017/11/21/floating-point-precision/ Or move to 64 bit world space.
Your answer
![](https://koobas.hobune.stream/wayback/20220613180807im_/https://answers.unity.com/themes/thub/images/avi.jpg)