Sign in to follow this  
Thomas Mathers

Impulse or Acceleration?

Recommended Posts

I was just wondering where is it applicable to use impulse over acceleration? I know that velocity can be calculated from both impulse and acceleration. For example, I know when objects collide their momentum gets altered and therefore and impulse could be applied to these objects. However could I not achieve the same effect by applying forces to these objects, which affects their acceleration? Also if I am using euler integration in my update function....the velocity directly depends on acceleration....how could I make it depend on momentum and impulse? Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites
Thinking in terms of an impulse or a force (rather than acceleration) would be more appopriate. You know how to apply the force in your simulation -- just integrate its effect. An impulse is also a force integrate over time, typically very short so that you can effectively say it was applied over an infinitesmially small period of time. When you integrate force over time, you get the units of momentum. So an impulse has the units of momentum and you can apply it directly to the momentum (or velocity) of the object. Perhaps it is easiest to think of an impulse as a force that's applied on a timescale much smaller than the one you are using.

Share this post


Link to post
Share on other sites
Quote:
Original post by Thomas Mathers
So does applying an impulse create an effect similar to acceleration? This is where I am getting confused.


It is like applying acceleration briefly, and then turning it off. It just changes the momentum/velocity of the object, it doesn't keep accelerating afterwards.

Share this post


Link to post
Share on other sites
Quote:
Original post by Thomas Mathers
So how would I implement impulses? Would I have to take into account how long the impulse is being applied?


No, that's kind of the point -- you don't deal with time. Think of a pool ball dropped onto concrete. You integrate the force due to gravity as the ball is falling. But when the ball comes into contacts with the concrete it experiences a force pushing it away from the concrete for a VERY short period of time. Now, you can either try to integrate the force due to the collision (probably a bad idea) or you can basically reflect the velocity of the ball so that it goes up. That change in the velocity/momentum is the impulse, or rather you add the impulse to achieve that effect.

Share this post


Link to post
Share on other sites
Quote:
Original post by Thomas Mathers
Ok, I think I understand now. But why would using forces in a collision be a bad idea?


In the example I gave, the timescale of the collision is much smaller than the timescale you are interested in. To integrate that accurately you would need to reduced your stepsize A LOT. It depends upon what you are trying to achieve with your simluation, but you probably don't need or want to model a collision explicitly. In that case, it is much simpler and faster to just use an impulse. It is not always bad to model a collision using forces, it depends on the timescale and what you are trying to achieve.

Share this post


Link to post
Share on other sites
So would this code be accurate for adding an impulse?

void CSprite::AddImpulse(float fx, float fy, float fz)
{
m_vecMomentum.x += fx;
m_vecMomentum.y += fy;
m_vecMomentum.z += fz;
}

and then in my update....

void CSprite::Update(float fDt)
{
......
......
m_vecVelocity.x = m_vecMomentum.x / m_fMass;
m_vecVelocity.y = m_vecMomentum.y / m_fMass;
......
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Thomas Mathers
So would this code be accurate for adding an impulse?

void CSprite::AddImpulse(float fx, float fy, float fz)
{
m_vecMomentum.x += fx;
m_vecMomentum.y += fy;
m_vecMomentum.z += fz;
}

and then in my update....

void CSprite::Update(float fDt)
{
......
......
m_vecVelocity.x = m_vecMomentum.x / m_fMass;
m_vecVelocity.y = m_vecMomentum.y / m_fMass;
......
}


Maybe... it depends on what fx, fy, and fz are. If they are force, then this is not quite correct. Forces and impulses are directly interchangable.

Share this post


Link to post
Share on other sites
Quote:
Original post by Thomas Mathers
Looks like flaming to me.


Sorry about that, from the link, please ignore the AP posts; see the math and derivations.

Numerically, the only difference between force and impulse is scale (conceptually (and unit-wise), they are of course different, and as seen from the previous link, can give rise to confusion and debate).

To be consistent, always think about everything as an impulse, converting forces to impulses as needed:

Keeping mass constant:

a = F/m // Acceleration
F = ma // Force
a = dv/dt // Acceleration again
F = m*(dv/dt) // Force again
F*dt = m*dv // Impulse

In a simple integrator:

a = F/m

v += a*dt
x += v*dt

a*dt => impulse: instantaneous change in velocity for this integration step.

Another formulation:

impulse = F*dt
linearMomentum += impulse
newVel = linearMomentum/mass

Velocity version (technically impulse is change in momentum, but is commonly used to describe instantaneous change in velocity when mass is constant (and for particles, when mass is 1.0, etc.)):

impulse = F*dt/m (resulting units are velocity)
(impulse can now be clamped to keep velocity (or momentum) stable)
v += impulse (add instantaneous change in velocity)

Again, keep track of units and rearrange as needed (constant mass):

Force: F = m*(dv/dt)
Impulse: F*dt = m*dv (formally): F*dt = d(mv) (mass and/or velocity can change)
Impulse: ma*dt = m*dv, a*dt = dv

An integrator applies impulses every integration step. Forces are first converted to impulses before being applied to velocity (or momentum, depending on implementation). Switching between forces and impulses is a matter of scaling by dt (for the specific integration time step).

Depending on your application, integrating momentum (as suggested by Baraff) may be a better choice than integrating velocity (velocity is fine for particles, however for rigid body motion, momentum is a better choice (especially for angular momentum)).

Again, for conceptual purposes, I suggest thinking about everything as impulses during your integration step. This will allow you to clamp (the impulse resulting from) spring forces, etc., so that you can ensure no large jumps in momentum (or velocity) which could lead to instability (common with game-size time steps and simple integrators). Minimally, use Newton-Stormer-Verlet (velocity is computed first, then used to update position), as opposed to simple Euler where velocity is computed after position. Lastly, use a fixed time step: this helps ensure stability (clamping, etc., will be stable in a tested range).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this