1

Say I have a particle-based physics engine (which I do) that uses lots of particles with a x and y coordinate and velocity. These particles can also have a mass, which means that these particles (with a large enough mass) can attract each other based off their masses. My question is how and where should the program work out the deduction of velocity when moving against a source of gravity, should it check every time a particle gets a new velocity? Or should it check every tick? And also, how would it calculate the deduction of velocity, since I don't know how it would work with a x and y system

  • There are at least a few approaches to this. You might want to watch Clojure Is the New C by Robert Martin. At 52 minutes into the talk he is describing an orbit (gravity) where it does indeed have the all objects attract each other and he goes a bit through the design. – user40980 Mar 7 '15 at 22:27
  • How much you know know about orbital mechanics? – raptortech97 Mar 7 '15 at 22:27
  • 1
    This is called the "n-body problem". Once you know that term, you can find loads of material on Google about exactly how to do this properly. – Ixrec Mar 7 '15 at 22:28
  • @raptortech97 I'm not sure if I can quantify my knowledge, but I'd say I know quite a bit – Orfby Mar 7 '15 at 22:29
2

As with pretty much any physics simulation, yes you have to calculate everything on every tick. The forces the objects exert on each other are constantly changing (as long as at least one of them is moving), so you can't really avoid it.

I have no idea what you're asking specifically about "deduction of velocity", since the law of gravity works exactly the same way in all direction. It's also a really simple law to calculate:

F = G * (m1*m2)/r^2

G is a constant, you can probably get away with pretending particles have constant mass, and all that's left is computing the distance (r) between each pair of particles.

  • the deducting is the fact that moving a heavier object away from a source of gravity is harder than with a lighter one – Orfby Mar 8 '15 at 19:27
  • The formulas are still exactly the same for any combination of masses, so that shouldn't be any harder or easier to calculate. – Ixrec Mar 8 '15 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.