# Including friction in a collision response

This topic is 2660 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm writing a little 2D physics engine. I've got the impulse working fine for a frictionless collision, but I'm having real trouble establishing how friction affects things.

I'm working from David M Bourg's 'Physics For Game Developers' - Bourg states that the impulse, which in a frictionless collision is in the direction of the collision normal, gets an additional component added in the direction tangent to the normal, of magnitude equal to the coefficient of friction * impulse.

This seems wrong to me (and indeed, when I add this to my code, gives the wrong behaviour) - it doesn't seem to include the relative velocities of the two collision points in the direction of the collision tangent - even if the relative velocity along this tangent is zero, as in the case of two non-rotating spheres colliding, it would still add a sideways impulse which is clearly wrong.

Can anyone direct me any further?

##### Share on other sites
Ok, I think I've got it. I found a paper here: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.130.6905&rep=rep1&type=pdf discussing the topic. mu * impulse is actually the *maximum* tangential impulse that friction can cause. As impulse is a method of approximating a force over a set time, mu * impulse is the impulse if (dynamic) friction acts over the whole time period. If, however, the force is such that at some point in the time period the tangential velocity drops to zero, the friction force no longer acts, after that time, so the tangential impulse will be reduced. If the max tangential Impulse is sufficient to reduce the tangential velocity to 0 then what needs to be calculated is the amount of impulse that will *just* reduce it to 0.

As the time the surfaces are in contact and the force at a given time are unknowable, the only way I can think to do this is using numerical analysis to home in on a given threshold of zero tangential velocity.

##### Share on other sites
Hello,

I have read the paper and the procedure described there seems complicated to me. Before trying this, maybe you should try a simpler aproach:
You can greatly simplify things considering the collision to be instantaneous and forgetting all the dynamic friction thing.

You can find the ecuations here.

The reply of the post only says that there is no need to include friction forces in the calculation of the impulse.

The ecuations in the post are for rigid solids, but can be simplified if you only want to use particles.

Bourg is right, so just another pair of things, to make sure you understood the tangent component of the impulse due to friction:

-The component is not tangent to the normal, but tangent to the normal surface, so it is perpendicular to the normal. As the post says, it is calculated as follows:

-The tangent normal is calculated with this equation.

t = [(n x Vr) x n]
tangent_normal = t/|t|

All the variables in the ecuations are vectors, and x is the vectorial product (or cross product).

With this, I think the odd behavior you saw should dissapear.

I hope this helps.

##### Share on other sites
That's exactly what I was trying at first, and it gives the wrong behaviour. (I also apologise, I was using the word 'tangential' when I should have been using 'perpendicular' which I think has confused things).

Bourg's method basically says that if there is any relative velocity perpendicular to the normal then the impulse instantly gains an extra perpendicular component of magnitude equal to the original impulse * coefficient of friction. There's no gradual build up as the perpendicular realtive velocity increases from zero - at zero, the impulse is parallel to the normal, at (for example) 0.000000001 units/second perpendicular relative velocity, the entire magnitude of the impulse * coefficient of friction is being applied perpendicular to the normal.

If the objects are spinning quite fast this is fine, but if the relative velocities of the contact points are low and coefficient of friction is high, this extra component is enough to completely reverse the relative spins of the objects. What should happen is that if the impulse is sufficient to reduce the contact points' relative velocity (perpendicular to the normal) to zero, then the friction force should stop. It's a limitation of considering a force as being constant for the whole time of the collision.

An analogous situation would be a car skidding to a halt - when the car stops, the braking force becomes zero, it doesn't bounce the car back the way it came.

I've got it all working now anyway, I'll post a video comparing the effects of the different methods when I get home.

##### Share on other sites
It was part my fault for not understanding. The word tangential is the one to use, like in "tangential component". It was the "tangent to the normal" what made me think you had the component in the wrong direction, sorry.

I still think that there is nothing wrong with the colliding objects having their relative spins completely reversed as a result of a collision: imagine 2 non-rotating spheres. One of them stationary, for simplicity's sake. The trajectory of the other doesn't pass through the center of the first ball. When they collide, if friction forces are taken into account, they will both adquire angular speed. If the spheres started with a small angular speed, they could end with their spin reversed after the collision. There is no problem at all with that with current physic laws. And I'm affraid they are here to stay for long :D.

The example of the wheel and brake is not valid because it is not a collision. It is just the result of the friction force between two solids in contact. It always oposes relative movement between the solids, so if they somehow inverted their relative movements, the friction force would also be reversed. If no external forces are trying to slide one solid against the other, they will stop sliding instead of changing their direction.

Anyway, it is your model, so if you have found a model that behaves the way you like and satisfies you, it is up to you to keep with it.

It would be great to see these videos.

##### Share on other sites
The car argument is valid if you only consider it for the movement perpendicular to the normal (which is what I was intending). When, say, two spheres collide, they don't instantly change their angular velocities - there is a period for a fraction of a second where the surfaces are sliding over each other, causing friction, and so causing a force perpendicular to the surface normal which changes the angular momentum - this part is analogous to the car tyre. As soon as the points on the surfaces match velocities (again, just considering the relative velocity perpendicular to the surface normal) there is no more force and the objects will stop gaining/losing angular momentum.

As I said, the behaviour I don't like is a limitation of considering all forces to be constant for the duration of the collision, which is the main assumption when using impulse as a collision mechanism.

lol, the videos explain it better than I can with words... they're uploading now. Hopefully they'll be able to show that the adjusted perpedicular impulse gives a more beleivable collision :-)

##### Share on other sites
Yes, the car argument is valid if you consider that one of the solids in the collision can be externally forced to stay in place (speed 0), and that the collision can last for a few seconds, if needed. But thats not how collisions work. Moreover, none of the solids in the collision is free to move linearly as a result from the collision, the momentum is not conserved, all the kinetic energy is lost in form of heat/deformation so you don't need collisions at all to modelate it. I'm not sure what is what you are trying to model: something like the spheres colliding or something like the wheel and brake? I hope the videos will be revealing :oD

Going back to collisions, the contact points dont't need to reach the same speeds at all: the friction force disapears because the solids are no longer in contact, not because the points in contact have the same speed. Again, if you are forcing the solids to remain in contact, it is not a collision. It is something else.

As a result from the collision, the solids can have gained/lost angular momentum. If the solids had no lineal speed before collision (so it is very unlikely they could collide :oD) then both of them could not reverse their spins, but one of them could. If any of them had linear speed, then both of them could reverse their spins as a result from the collision.

It seems our points of view have collided :oD

[Edited by - peibol on September 1, 2010 5:20:25 PM]

##### Share on other sites
Quote:
 Original post by peibolMoreover, none of the solids in the collision is free to move linearly as a result from the collision, the momentum is not conserved

They are free to move linearly, and momentum is conserved, it's just that the earth is so big compared to the car that you don't notice it move.

Videos are currently 'processing'. Hurry up, YouTube! Is there a better place to quickly upload videos?

##### Share on other sites
Think of it in terms of the angular velocities of the objects before and after the collision. If a moving, spinning sphere hits an identical stationary sphere, some of the spin is transferred so that after the collision the once-stationary sphere is spinning too (as well as moving away).

Now imagine you collide them three times, once where the moving sphere is spinning at 1000 radians/second, once where it's spinning at 2e-11 radians/sec, (which is about one revolution every 10000 years) and once where it's angular velocity is exactly zero - not spinning. Keep the initial linear speed of the moving sphere constant in each case. By the calculations you've given, in both spinning cases the stationary sphere ends up with exactly the same new angular velocity after the collision. However, in the case where the angular velocity is zero, it has zero angular velocity after the collision. This is clearly nonsense.

##### Share on other sites
Here's the videos I promised:

These first two videos show both techniques at high rate of spin (I think Bourg's is the first one but it doesn't matter - the effects are identical).

This is Baker's technique at a low rate of spin (0.4 radians / second). The friction force is sufficient that the touching edges match velocities causing the friction force to stop, preventing any further change of angular velocity.

Compare it with the same collision using Bourg's technique. The full magnitude of impulse * coefficient of friction is being applied perpendicular to the normal causing the angular velocity change to be much higher than it should be.

To illustrate it further, this collision again uses Bourg's technique but with the angular velocity of the moving sphere set to 0.0001 radians/second (about 1 revolution every 16 hours). The resulting final angular velocity of the left sphere is *exactly the same* as the collision above. If I were to reduce the angular velocity to zero however it would have zero angular velocity after the collision.

Baker's technique produces the correct behaviour for low angular velocities - with the above collision the second sphere would (correctly) bounce off with almost 0 angular velocity.

##### Share on other sites
Not quite sure if you've found the solution, but:

1. You need to apply the minimum of:

1.1 The tangential impulse given by frictionCoef * normalImpulse

1.2 The tangential impulse that would result in zero tangential velocity.

The first of these is obviously easy to calculate.

The second might seem tricky, but actually you just need to use exactly the same equations you're using to calculate the normal impulse. The equations tell you the normalImpulse required to result in zero relative velocity along the contact normal. Just change the direction and use them to calculate the tangentialImpulse required to result in zero relative velocity along the tangent direction.

2. You can probably find some example code in Box2D, though I haven't looked there. You can definitely find example code in my code - JigLib.

3. That Bourg book is absolutely terrible. Badly written, example code is (certainly was when I looked ages ago) a complete mess, and the demos are terrible. I use mine to prop up my monitor, and it's not too good even at doing that.

##### Share on other sites
Quote:
 Original post by MrRowlNot quite sure if you've found the solution, but:1. You need to apply the minimum of:1.1 The tangential impulse given by frictionCoef * normalImpulse1.2 The tangential impulse that would result in zero tangential velocity.

Yes! That's exactly what I'm doing :-)

Although I think I'll have a look at how I'm calculating #2. I'm getting the correct answer, but I'm using numerical analysis to home-in on the correct value over several iterations - looking at what you say, I may be able to calcularte it directly.
Quote:
 3. That Bourg book is absolutely terrible. Badly written, example code is (certainly was when I looked ages ago) a complete mess, and the demos are terrible. I use mine to prop up my monitor, and it's not too good even at doing that.

Yeah, I found this out pretty quickly, but I'm too cheap to buy another book :-D

##### Share on other sites
[quote]Original post by BattleMetalChris
Quote:
 Original post by peibolMoreover, none of the solids in the collision is free to move linearly as a result from the collision, the momentum is not conserved

Quote:
 They are free to move linearly, and momentum is conserved, it's just that the earth is so big compared to the car that you don't notice it move.

They are not free to move linearly in relation to each other: the brake is hold in position by the rest of the car, and the wheel is held in position by the axis. I didn't think you would include the friction of the wheel with the earth. Are they also colliding? I think there is a misunderstanding between collisions and contact forces. I'm pretty new to physics engines so maybe anything in contact is treated as a collision and I'm completely wrong. I really don't know.

##### Share on other sites
Quote:
 Original post by BattleMetalChrisBy the calculations you've given, in both spinning cases the stationary sphere ends up with exactly the same new angular velocity after the collision. However, in the case where the angular velocity is zero, it has zero angular velocity after the collision. This is clearly nonsense.

You are completely right here. I thought the equations behave differently, but now I see it. I should have checked more carefully before. Sorry.

##### Share on other sites

This topic is 2660 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628706
• Total Posts
2984309

• 23
• 10
• 9
• 13
• 13