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

Ben Hollier
  • 115
  • 4
  • There are at least a few approaches to this. You might want to watch [Clojure Is the New C](http://www.infoq.com/presentations/clojure-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. –  Mar 07 '15 at 22:27
  • How much you know know about orbital mechanics? – raptortech97 Mar 07 '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 07 '15 at 22:28
  • @raptortech97 I'm not sure if I can quantify my knowledge, but I'd say I know quite a bit – Ben Hollier Mar 07 '15 at 22:29

1 Answers1

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.

Ixrec
  • 27,621
  • 15
  • 80
  • 87
  • the deducting is the fact that moving a heavier object away from a source of gravity is harder than with a lighter one – Ben Hollier Mar 08 '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 08 '15 at 19:34