wow, i come back, and their are plenty of posts, first thank you to everyone whom has responded
up until today, this is what I've created: http://www.swfcabin.com/open/1273481279
from research and collation with some friends, that is what I've come up with, after reading through your posts i should be able to modify it to be a bit more realistic, also you'll notice collision's don't occur, i took them out actually, i felt it gave a nicer creation of unique rotations, also, i limit the speed of any object, just enough to break away from other objects, and not soo fast it's just a blur
time for my nice long reply to everyone
kev said:
In your last effort, the final clump of masses drifts up and to the right which does not seem right, because the initial momentum of the system appears to be zero. The total momentum of the system before and after the interactions should be unchanged.
this is a hard concept for me to understand, while they start at rest, the attraction to each other mass's increments an increase in momentum, unless your referring to the after, being when they have collided with each other, in which case, i can understand that they should be at rest, however if u noticed, my collision code isn't perfect, and the efficiency of each impact is not perfect as well, so i suspect that the reason for the clumping, and maintaining of momentum is somewhere in the way i handle collisions
kev said:
Here is a basic heuristic to work by. For a system consider each body in turn. Calculate the acceleration of the considered body by ignoring its own mass and calculating the acceleration due to each other mass in the system individually. Acceleration is a vector so you need to add all the acceleration vectors* together to get the final magnitude and direction of the acceleration of the considered body. Do this for all the other bodies in the system for each step (time increment) of the simulation.
this is exactly what i came up, each object's calculates a vector to each other object, which are all combined to the object's current vector
kev said:
Unfortunately you can not combine the masses of the other bodies as one large effective mass and you have to consider the mass and distance of each individual body and this can take a lot of processing power.
yes, the processing power is something I'm running into for large scale number of objects, I've seen flash support 4000 objects in real time, so I'm not certain what I'm doing wrong in particle managment to increase efficiency(perhaps it's as simple as I'm using as 2.0, and not 3.0)
kev said:
There are some shortcuts and reasonable aproximations you can make to speed up the simulation. For example a "clump" of bodies far from the considered body can be treated as a single point mass with little loss of accuracy. See http://www.amara.com/papers/nbody.html#tcu
i had considered creating a system which combined clumps of objects into sectors with a mass = to the mass of all the objects, it's just something i haven't implemented yet
kev said:
To see a nice (fast and beautiful) gravity simulation of multiple bodies that can run on a PC see: http://gravit.slowchop.com/ It is a pure simulation rather than a game, but the source code is included and it might be helpful to you.
i'll take a look at this right away, thanks for linking me to this
LukeD said:
Oh no! Your system oscillates around the center at the end in this one: http://www.swfcabin.com/open/1273377894
That's definitely not right. If your system starts off at rest, then it should clump together and then be stationary. It's ok if the individual particles are moving a bit, but since the whole collection of masses started off at rest, it should remain at rest.
ah, more re-assurance as to the before/after rest issue i have, i believe it has to do mostly with my collision implementation that creates the drag(if u'd notice, the objects well begin to move over each other, this is a by-product of trying to ensure that i didn't loop forever, re-calculating new collisions, and is most likly the cause for the non-rest issue)
LukeD said:
You asked if you should "divide by mass to get drag". That doesn't really make much sense. But you do "divide by mass to get inertia"
Don't forget Newton's force law "F=ma". The acceleration of a particle with mass m is "a=F/m"
ah, yes, that's exactly what i meant, I'm sorry for the wording, I'm not the best at knowing all the words in physics, thanks for picking up on what i meant=-)(thankfully the concept is equal to how i implemented it, so that's a plus)
starthaus said:
Actually, eq (3) is incorrect. It is easy to see that A and B accelerate C in the same direction (the -x direction). You can find the correct
general equation of motion
here
For two bodies, the problem reduces to solving a system of two second order differential equations. The solution is not trivial. You would need to solve:
\frac{d^2\vec{r_A}}{dt^2}=GM_B\frac{\vec{r_A}-\vec{r_B}}{(r_A-r_B)^3}\frac{d^2\vec{r_B}}{dt^2}=GM_A\frac{\vec{r_B}-\vec{r_A}}{(r_A-r_B)^3}
]
unfortunately this is the problem with trying to read through wikipedia's math, their are a lot of symbols their that i simply don't understand(actually since I'm quoting you, i can see all the symbols written around their meanings, which helps me understand it much more)
kev said:
Yes, it gets much more complicated when you take linear and angular momentum etc into account. It depends how realistic you want the game to be and how much computational power you have available.
could you elaborate upon linear and angular momentum, at least in a context of how they relate to gravitational pull(i'm assuming quite a bit, but isn't momentum inherently linear along w/e line it's moving?)
starthaus said:
I was talking about something a lot more basic:(3)Acceleration of C = -Ma/Rc^2 - Mb/(Rc-Rb)^2
kev said:
Perhaps I should of mentioned in #5 that you need to keep track of the instantaneous velocities of all the bodies and apply the calculated acceleration to each body's instantaneous velocity at each iteration. For a small body in circular orbit around a very large body, the acceleration of the orbiting body is at right angles to its instantaneous velocity. Good point Starthaus.
hmm, I'm not really certain i understand what you mean by instantaneousthanks again everyone for your help thus far=-), I'm very grateful
also thanks for moving it to the appropriate section