(2D) Friction & MOI (with images)

Started by
9 comments, last by Ilici 18 years, 11 months ago
Hi there! Since a few month I'm trying to implement a little 2D physics engine without sucess [depressed] That's how far I got: I have a vertices and constraints. Every frame I apply some gravity to all vertices in the scene. Then I add another force to satisfy the constraints: if two connected verts move to apart I pull them them together again (and vice versa). That way I can achieve some very basic (but still cewl) siulations. E.g. a rubber-rope or boxes falling on top of each other... But there are still two main problems that make everything UGLY [crying] The first one is friction. Take a look at this image: The red images show how my engine actually behaves: the stick gets pulled down by gravity, but instead of falling to the left or right side (green images) it just rotates around its center. The lower vertex "slides" on the box as if they both were made of ice (no friction). The problem gets even worse when objects (boxes etc.) are used. They behave totally unrealistic! Is there a simple way to correct this problem? The second problem: "moment of inertia" (I'm not quite sure if I use this term correctly...maybe this has a different name???) Again an image: Here you can see a pendulum. In my sim (red images, again) I apply gravity every frame. But that's the only force acting on the vertex! So when it has reached the top-down-position, it simply stops! :-( Of course in reality it should swing on, to the other side. What am I missing here? I'm sure there's just a little bit of code missing... ;-) So, thank's a lot for reading this post! If you have any ideas please let me know!!! Sincerily your's, Boris
Advertisement
What kind of integrator do you use ?

Secondly, the pendulum results are totally wrong, I'm thinking your problem is that you are simply pulling the particles together. Thus the particle which should swing does not get horizontal velocity (which would make it swing afterwards). You need to apply a constraing resolving force to the particles. A more detailed description of such forces can be found in Baraff - Constrained Dynamics.

Basically you apply a force that solves the constraint, but I found that you still need to pull the particles together too. If you'd like you can take a look at my demo which includes such forces and is pretty close to what you're doing yourself.

A problem with such constraints is that if they're stiff - a rod or an inelastic string - you'll need a good integrator if you have a more complex system or you can iterate over the constraints many times to fix them.

In regards to the friction question. That's a much harder problem. First of all you'll need those constraint forces so you determine the force acting on each particle. A very simple approximation of friction, which should work for particles, is to find the amount of force in the normal direction (normal to the surface the particle is resting on) and apply a force equal to miu * N in the opposite direction of movement. Choose miu as you wish. If you can compute the constraint forces correctly then this should bring a particle to a stop if it's moving on a surface, not accounting for static friction.

You also need to consider that the particle does not move until static friction is broken which raises a whole lot more problems. A good robust implementation is pretty hard to do.
Thanks a lot for your reply. I'm looking through all the stuff you gave me ;-)
(Your demo looks goooood, but the DL doesn't work)

One more question: what is an "integrator"?
Wurks! I just took a look at the paper....I'm totally overwhelmed by all that math stuff :-(
Is that really neccessary?? ;-)

(Until now everything went fine without using that complicated stuff) ^^

EDIT:Now your site seems to be completely down!?!
My site is down, sorry, i just found out I bought a POS router. I'll try to e-mail it if you want.

EDIT: ok the site works now. you can download

[Edited by - Ilici on May 23, 2005 7:05:36 PM]
The first example is actually the correct result for a frictionless surface on the table. If there is no friction stopping the point of contact on the table sliding left or right the beam will do exactly what it did.
Hi,
Its nice to another person take on the physics challenge!

Anyway, from what you describe, it seems you're trying to implement Jakobsen's idea in "Advanced Character Animation". If you haven't read that yet, I suggest you give it a read, the concept is simple and it shouldn't take much effort to get it.

As for the first problem: Friction is a known setback to Jakobsen's idea. There are ways to fake it though. Check out oliii's website. He's a member of gamedev.

For the second problem: If you properly implemented the timestepping scheme proposed by Jakobsen, this should not be happening. You might want to take another look at your verlet integrator.
That's the second time I hear the word "integrator" ;-)
What is that???

And second I'm not using any verlet-stuff...every vertex has a force (2D Vector) which is applied every frame (NewPos = OldPos+ForceVect*time). Is that a bad idea? I thought that was quite intuitive... ?!?

Thanks for your replies!
Quote:
And second I'm not using any verlet-stuff...every vertex has a force (2D Vector) which is applied every frame (NewPos = OldPos+ForceVect*time). Is that a bad idea? I thought that was quite intuitive... ?!?


This is the reason for your pendulum test failing. You should definitively read the Jacobsen paper. Forces act on acceleration (Accel = Force / Mass (f = m * a)) wich in turn integrate into velocity (newVel = oldVel + Accel) wich in turn integrate into position (newPos = oldPos + newVel).

The integrator is in charge of integrating the particule accel->vel->pos until position is updated. The most intuitive integrator (and you're almost using it right now) is the Euler integrator.

What's happening here is that your particle has no velocity so whenever you stop applying forces to it (gravity only in your case I presume) the particle just stops dead on.
Praise the alternative.
Hey, that sounds good :-)
Thanks soooo much for your help guys! Now I've got a lot of stuff to look into...

This topic is closed to new replies.

Advertisement