Universe Sandbox Legacy > Universe Sandbox 2008 | Discussion

Math of Universe Sandbox

(1/5) > >>

FGFG:
This discussion branched off the Nintendo DS concept post.
http://universesandbox.com/forum/index.php/topic,345.0.html
FGFG is discussing how many calculations Universe Sandbox does each second. - Dan

The fact that it is in 3D doesn't mean that the DS is capable of great calculations in order to support Universe Sandbox (even in 2D). A game such as that doesn't require much CPU because there are 2 guys fighting each other with the same movements pre-defined and stored in the memory of the game and not calculated every time. Universe Sandbox, instead, needs much more CPU because it has to calculate all the iteractions between an object and all the others, repeat the algorithm for every object and then repeat all of this again at least 20 times per second, so that it doesn't look too slow...

for example (i hope this is how US works, i'm not sure of it):

there is the famous formula F=G(m1*m2)/d^2 that can be applied to both m1 and m2 (so 1 calculation for every couple of objects ==> 5 bodys are 10 calculation, for 20 bodies are 190, for 100 bodies are 4950).

All the forces found for each body must become just 1 resultant (so n-1 vectorial sums, where n is the number of forces) again for each body; a vectorial sum is made basically with the 2 forces, and the angle between them. If you want i can explicit the formula later).
5 bodies: 15 calculations
20 bodies: 360 calculations
100 bodies: 9800 calculations

Then the Forces have to become accelerations... F=m*a so a = F/m (again for each body)

With the velocity of the body and his acceleration, we can finally calculate the position in the new frame (i don't know how this is calculated however)

the total sums of calculations for each frame is:
5 bodies: 31
20 bodies: 541
100 bodies: 14851

Assuming that you want 20 fps:
5 bodies: 620/s
20 bodies: 10820/s
100 bodies: 297020/s (!)

At last the programme has to translate all these data in an image with procedures that i don'r know.

I just hope MY calculations are correct  ::)
Dan, does Universe Sandbox work this way?

SuperNova:

--- Quote from: FGFG on June 17, 2009, 04:47:55 AM ---The fact that it is in 3D doesn't mean that the DS is capable of great calculations in order to support Universe Sandbox (even in 2D).
...

--- End quote ---

its much and much more >:(
you must fight against 1000 enemies at one's >:(
its much more complicated >:(

FGFG:
I was just saying that it's a bit hard to make Universe Sandbox on a DS, not that it is a bad idea. Just look at my first post in the previous page... It just say what I say here again, but in a way much more concise.

And the finality of my previous post was also to ask Dan if Universe Sandbox works as I've imaginated. And even if I don't think so, it could work in a way much simplier so that it could run even on a DS with small changes.

And we aren't against you, we were just explaining you what you are going towards.

Dan Dixon:

--- Quote from: FGFG on June 17, 2009, 04:47:55 AM ---I just hope MY calculations are correct  ::)
Dan, does Universe Sandbox work this way?

--- End quote ---

You're mostly right. Nice work.

How are you calculating these numbers?
5 bodies: 15 calculations
20 bodies: 360 calculations
100 bodies: 9800 calculations

Since each body compares itself to every other... The math should be:

5 bodies: 5x4 = 20 force calculations
20 bodies: 20x19 = 380 force calculations
100 bodies: 100x99 = 9900 force calculations

Here are the basic steps:
1 - Calculate the force between each body and every other.
2 - This force is converted into the corresponding X,Y,Z forces based on where the bodies are in space.
3 - The 3D acceleration is applied to each body resulting in a new velocity and position.
4 - There are also checks for collisions between every object.
5 - And the scene is redrawn.

FGFG:
THIS IS A POST ABOUT THE MATH OF US, IF IT DOESN'T INTEREST YOU, JUST DON'T READ IT ;)


--- Quote from: Dan Dixon on June 17, 2009, 12:15:41 PM ---How are you calculating these numbers?
5 bodies: 15 calculations
20 bodies: 360 calculations
100 bodies: 9800 calculations

Since each body compares itself to every other... The math should be:

5 bodies: 5x4 = 20 force calculations
20 bodies: 20x19 = 380 force calculations
100 bodies: 100x99 = 9900 force calculations

--- End quote ---

I thought that when you calculate the forces of the bodies you obtain n-1 (e.g. 5-1 = 4) forces for each body, (where n is the number of bodies), so you have n-1 (4) vectors that have to be sum in order to have 1 resultant (I think that this is the passage different, maybe just in the order), so you have to do n-2 ((n-1)-1) vectorial sum as, for example, to obtain a resultant from 4 vectors you have to do 3 sums... All of this for each body, so I obtained the equation c (calculations) = (n-2)*n

e.g. 5:  c = (5-2)*5 = 15
...and so on

Probably the passage different is the 2nd: i supposed that firstly US calculates all the forces for each body, and then it calculates the resultants before converting it to acceleration.


--- Quote from: Dan Dixon on June 17, 2009, 12:15:41 PM ---4 - There are also checks for collisions between every object.
--- End quote ---

I've forgot it... I think that US checks the radius of all the bodies and when 2 bodies are at a distance less than the sum of the radiuses there is a collision so, again, like for the gravity formula, there is a calculation per couple of bodies ==> for 5 bodies there are 10 calculation, 190 for 20, and so on...

Totally, without considering the calculation for the collisions themselves there would be:

5: 41 calculation per frame * 20 fps = 820 calculations per second
20: 731 cpf * 20 fps = 14620 cps
100: 19801 cpf * 20 fps = 396020 cps

Again, I hope they are correct.

Probably during a collision in combine mode, the mass is summed, the velocity is calculated, considering the kinetic energy and the quantity of mote for the module, and using another vectorial sum for the direction (however i'm not sure of this because at school we made only the collisions on a straight line).
In the bounce mode, when there is an elastic collision (so that the 2 bodies doesn't remain attached) it uses the same formulas, but it needs double calculation because the bodies remain separated (so 2 velocities to be calculated).

Other 2/4 calculation per collision.

What happens exctly when the 2 bodies, in the bounce mode, remain attached, escapes from my immagination and deduction... :P
Basically there is a collision per frame, but the position of the 2 bodies must be changed so that they don't "fall" into each other. Can't imagine the enormus amount of calculation where there are many bodies attached in a group (e.g. the systems "Moon - large/small cluster, flat disk" or even in "dice swarm" where the shape is cubic and not spherical). I cannot imagine the calculations for the velocities too...

Well i think, Dan, that you made an excellent work with this simulator  :o ;)

Navigation

[0] Message Index

[#] Next page

Go to full version