2D Rigid Body Physics and The Shaking

Started by
30 comments, last by MrRowl 19 years, 1 month ago
f = m * a , think of what a is, it is your function.
Advertisement
Well you have starting values for the physics sim, where objects are located etc at time 0. You also have a way to compute forces acting on these bodies, that is the second derivative of your function f''. When you do simple explicit Euler integration you just assume that this function is linear which leads to large errors with anything except tiny stepsizes. Anyway, when you do a=F/m, v+=a*dt, p+=v*dt you are basically using a simplistic way to solve your differential equation. RK4 is a better way to do it. Hope that makes sense.

Here's a more elaborate and better explanation: http://www.pixar.com/companyinfo/research/pbm2001/notesb.pdf

The page were that doc comes from: http://www.pixar.com/companyinfo/research/pbm2001/ also plenty of more, very readable stuff on physical simulation.
Quote:Original post by BobTheFish
Quote:Original post by GameCat
The easiest way to stop shaking is to reduce the error in your ODE-solver/integrator. This means either taking tiny explicit-Euler steps or using a better solver like Runge-Kutta 4.


I did a subject on Numerical Integration at Uni last year, which dealt with Runge-Kutta and how to use it to solve ODEs, given the function. However I don't see how it could be used in a physics engine since there is no function involved. I mean, in my knowledge of Runge-Kutta, you're required to evaluate the function at certain points - but where in my simulation am I going to pull a function from?

Is this a misunderstanding in my concept of Runge-Kutta, or something else?


http://69.55.229.29/articles/Integration.html
A hard core method is to work with inertia tensors. That is,

-find the cube's inertia tensor.
-Use the the force of impact ( a point of the cube hitting the ground ) and the calculated inertia tensor to find the change in position and angular velocity of the cube.

Just an advanced topic to learn later.
Obviously you need an inertia tensor to get correct movement for your objects, but that has no effect on the shaking problem mentioned here.
It might be...

I'm using the inertia matrix to calculate rotation in the impulse (torque) as well as the inverse masses to calculate the change in linear velocity.

However when objects are overlapping, the seperation is purely changing the positions of each (relative to their inverse masses of course). Should I be rotating the objects as well?
Assuming your using a collision method that gives you penetration depth, like e.g. the separating axis test, then translation is the only thing you need to prevent interpenetration. In fact, rotating as well won't work since the objects are only guaranteed not to interpenetrate when you do pure translation along the collision normal.

The collision impulse you apply in the event of a collision could of course cause a rotation but since you seem to have an inertia matrix I assume that works.

Try just taking smaller time steps, if the problem gets less visible or disappearss, the problem is your ODE-solver/integrator. If it doesn't, something else is wrong. Try at least 3-400 physics ticks per second before giving up.
Thankyou all heaps for your help.

I'll try RK4 first, then I'll get back to you on how it went. :)
Of course, it could turn out to be so hard that I come back for a little help first :)

I've been following the tutorial found here:
http://69.55.229.29/articles/Integration.html

My question is, what do I put in the acceleration function? In that example and others I've found on the web, the acceleration is a specific function for the given simulation. In this case, though, acceleration is given by
a) gravity
and b) the impulse due to collision

So I can't set it out in a function since it needs to involve collisions.

I thought maybe I could accumulate all the impulsive forces due to collision over dt, but is that really correct since acceleration due to impulses isn't proportional to dt?
Quote:Original post by BobTheFish
In this case, though, acceleration is given by
a) gravity
and b) the impulse due to collision


No - the acceleration due to an impulse is infinite (because it results in a non-zero change in velocity over zero time). Impulses cannot be applied during your (force etc) integration (Euler, RK4 etc) step, because they'll break the assumptions used to obtain that integration scheme. They should be applied outside of the integration step. So in your "acceleration function" you would just have things like gravity, drag, spring forces, and possibly resting contact forces (unless you do resting contact with impulses) etc. Collisions get handled separately.

Also impulses affect the velocity immediately - in reality you don't get simultaneous collisions, so you shouldn't "accumulate" impulses before applying them. Your physics/collision may find multiple collisions that occur during the same timestep but that's an artifact of the simulation - youre better off processing them as if they happened in an arbirary order than as a genuine simultaneous collision (because the 2-body rule of Vr' = -eVr doesn't hold for more than 2 bodies).

This topic is closed to new replies.

Advertisement