• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by BerkayDrsn_Legacy · Jan 18, 2015 at 10:22 PM · physicssimulation

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/

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Baste · Jan 18, 2015 at 11:39 PM 0
Share

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.

avatar image Waterforever · Apr 29, 2016 at 09:52 AM 0
Share

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.

avatar image Genubath · Oct 12, 2016 at 01:26 AM 0
Share

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.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

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.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Llama_w_2Ls · Dec 15, 2020 at 04:05 PM 0
Share

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

avatar image EZS Llama_w_2Ls · Dec 15, 2020 at 04:11 PM 0
Share

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.

avatar image commadorecoder64 · Mar 16 at 08:58 PM 0
Share

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.

avatar image commadorecoder64 commadorecoder64 · Mar 16 at 09:06 PM 0
Share

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.

avatar image commadorecoder64 commadorecoder64 · Mar 16 at 09:12 PM 0
Share

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

avatar image
0

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.


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with a ballistic trajectory simulation (rigidbody.velocity) 0 Answers

Water Toy Ring Toss - How to simulate the rings 1 Answer

Using cylinder colliders as wheels. 1 Answer

Physics seem inaccurate with massive amounts of rigidbodies. 0 Answers

Create a leaf with it's natural motion acting upon gravity? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges