1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Creating a simple Friction model

  1. Dec 18, 2011 #1
    Hello everyone ^^ I'm amateur programmer, making games for a hobby.

    I'm trying to design a physical simulation engine here, and one thing i'm struggling with is modelling friction in code. I don't recall ever learning much about it in school, or perhaps i didn't pay enough attention, but regardless, i'm struggling somewhat to understand the concept.

    My loose understanding of (dry) friction, is that it's created between moving objects, and acts to deplete their kinetic energy/momentum, gradually reducing velocity while they're in contact. As this is a game, it doesn't need to be 100% accurate, just "good enough". So i can afford to make plenty of assumptions such as uniform roughness, and not caring too much about how much surface area is in contact.

    What i'm interested in is creating a simple model for dry kinetic friction. I want to be able to assign some arbitrary friction value to a game object, and calculate a coefficient from the two friction values of any relevant pair of objects. Presumably at the end up, i'd have some value to either subtract from, or multiply by, the two objects' velocities. (i'm not sure which, how proportional is this?)

    my first thought with this problem was simply creating a multiplier value for each object (such as 0.3) and multiplying the other object's velocity by that value each second it's in contact with that object. I have a feeling that this is a bit TOO simple though, and i'm also worried about stopping. In conventional dry friction, objects generally DO come to a stop quite quickly, don't they? i'm thinking that just using a multiplier would result in the object getting perpetually slower and slower, but never fully coming to rest.

    Is proper friction code going to bring objects fully to rest? or should i be using some cutoff velocity below which an object can be considered nonmoving, and set to 0?

    If it helps any, i'm 23, i have mostly just a highschool education, and some general familiarty with basic physics concepts. i'm a little bit more knowledgeable than the laywoman, but not too much.

    Any advice, thoughts, and pointers in the right direction, are greatly appreciated ^_^
  2. jcsd
  3. Dec 18, 2011 #2

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    You can assign each object a roughness factor which add to make a coefficient of friction.
    The friction force is the perpendicular contact force scaled by the coefficient.

    If you want a speed-based model, then each roughness factor creates a drag coefficient - the (quick and dirty) energy loss due to drag should be the drag coefficient times speed-cubed, so you can get a terminal velocity.

    Tweak the values of the roughness factors for the sensitivity you want.

    For more detail, find an open-source program that handles friction and see how they do it. There are a lot of models of varying physicality.
  4. Dec 19, 2011 #3
    Reassign frequencies to all your particles. Then you can determine friction by simple addition/subtraction. That's what I had to do a couple months ago. It makes particle models smoother with less load on the server that you would get from complicated algorithms.
  5. Dec 19, 2011 #4
    simple addition ? what are rough ballpark figures for friction values. say substances like dirt, concrete, etc.
    reading around a bit, it seems like coefficients of higher than 1 are quite rare, and wikipedia makes no mention of coefficients higher than 2. I'm perplexed as to what this means, though.]

    i'm not quite following you here. does this contact force have something to do with the object's weight? i'm guesing, when both are on top of each other, the contact force is the weight of the upper object? maybe i'm wrong there.

    by scaled do you mean multiplied by, just to be clear ?

    i'm not certain what you mean by a speed based model. what you're describing sounds like more of a way to model air/water friction? i guess it's all the same esentially. would that model be exclusive to the other one?

    a good idea, certainly. i'm thinking of having look at Box2D. my coding language here is AS3 by the way (flash). i opted to write my own engine, rather than using Box2D, mainly for learning purposes. ^^

    not certain what this is about. i'm not using particles at all yet, and i don't generally plan to involve them much with physics when i do. it's mostly a rigid body engine, and it's a client app, so i on't have any servers to worry about
  6. Dec 19, 2011 #5
    i've come across something else on the matter that's confusing me also. the wikipedia page has a table about halfway down, Approximate coefficients of friction. The values listed here just don't seem to add up.

    for example, the coefficient of steel on steel is shown as 0.8, so if this should be calculated with addition, does that not mean the roughness value of steel would be 0.4 (half).

    just underneath that though, the coefficient of steel and PTFE is 0.04. how can that be? unless ptfe has a negative roughness, and actually causes objects to accelerate ?

    i can't seem to make sense of this.
  7. Dec 19, 2011 #6
    Friction is a complicated phenomenon and there's no simple way to model it, even in "real life". The best you can do is measure different coefficients and compute tables of them.
  8. Dec 19, 2011 #7
    Simply put, force of friction is the coefficient of friction x the normal force...or the force pushing the object into the ground (or whever it's rubing against). This can indeed be the object's weight (on flat ground), but if something is on top of it, then it's the two object's weights added together, as the second object is directly contributing in pressing the surfaces together. If something else is pushing it into the ground (such as aerodynamic pressure, centrifugal force, a human hand, etc.), that force needs to be added also.

    If a 1 kg block of steel is sliding on steel, for example, and only the block's weight is pushing them togheter, then the force of friction is .8 x 9.81 N = 7.8 N

    If the same block of steel is sliding on PTFE, then .04 x 9.81 N = .4 N

    Theoretically, surface area doesn't matter.

    Coefficient of friction is always given for two objects sliding against each other. That's why you have steeel/steel or steel/PTFE. It wouldn't make sense to just give the coefficient for one object, as the object needs to rub against something for there to be friction. Don't think of it as "roughness" as there are more complicating factors than that. Just take the given coefficient and go with it.

    Once you can solve for the friction force using the simple formula, you can then figure out how fast that force will slow down an object. Force is mass x acceleration.


    So the 1kg block of steel rubbing against steel will slow down at 7.8 / 1 kg = 7.8 m/s^2
    On PTFE, it will slow down at .4 / 7.8 = .05 m/s^2

    For a simple computer program, this textbook simplification of friction should be sufficient.
  9. Dec 19, 2011 #8
    I disagree !

    I've been looking through the source code of Box2D. The formula used there is sqrt(friction1*friction2), where 1 and 2 are arbitrary user-assigned values for friction of a single object

    with a range of sensible input values, i find that this gives sensible outputs. most notably it allows either input to drive the coefficient towards 0, and it means that the coefficient of x on x is always x. I'm sure it's not perfect, but it's "good enough" and it adequately fits the task of a simple model.

    I'm going to use this formula for now, so that's my first part done.

    The next part as far as i can see, is in two steps:

    1. Calculate the kinetic energy lost from the friction (converted to heat or whatever)
    2. Calculate the change in velocity from the lost kinetic energy.

    So, the first of those steps; wikipedia has this formula, which i need a little help deciphering:

    ok, i have the friction coefficient.
    i'm not sure about d. is that distance in metres? it's not documented. i don't know exactly what X is either, i'm guessing a normalised directional vector ?

    and what is that squiggly line in the middle ?
    Last edited by a moderator: Apr 19, 2017
  10. Dec 19, 2011 #9

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    You mean the "d" in the integral?
    But you know that's just the notation for an infinitesimal change ... in this case: "dx" ?
  11. Dec 19, 2011 #10

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    If you like - as you've seen, some computer models multiply factors together. You asked for a simple model - this is one. There are many others.
    You don't care - you just want your simulation to "feel" right.

    You need to read more on the physics of friction then.

    Generally it just means that you won't expect the friction force to be bigger than how hard the two surfaces are pressing against each other. Friction models don't only cover fine-grained irregularites.

    The contact force is whatever is pressing the two objects together in your simulation.


    Generally, energy loss due to a contact is proportional to the roughness of the surfaces and the strength of the contact.

    The harder you push two surfaces together, the more friction you get.
    The rougher the surfaces, the more friction you get.

    These are very simple models which exclude large amounts of the generality of physics.
    How you track motion will be important to which model you choose.
    If you keep track of energies, then you want to describe friction effects in terms of energy losses, if you track speed, then you'll be better having a "slowing effect" - drag. If you are modelling everything with forces and pressures, then the force model is used.

    I'm sorry, I thought you already had a computer program you wanted to add friction effects to. This should be making sense in terms of your program. You are simulating a bunch of stuff moving around - each object has, say, a position and momentum vector, and some sort of geometric factor to handle collisions?

    If you simulate aircraft, then you want a drag coefficient for when you fly through clouds or smoke or something (for a simple model - the drag of normal air would be included in the default dynamics.) If this is penguins sliding on ice, then you want some sort of roughness factor to cover snow, dirt, and rocks while the contact force will handle the effect of different slopes. See what I mean?

    Which means you only need a simple model that can be tweaked for verisimilitude.

    You can drive yourself nuts trying to simulate everything that could possibly happen.
    Isolate the bit you need and simulate that.
  12. Dec 20, 2011 #11
    i think that simple addition was a bit too simple though, and wouldn't accomplish the goal of feeling right. for example it would have needed both objects to b extrmely smoooth in order to get a low friction coefficient, which doesn't make sense (as opposed to one)

    i get what you mean. i am ccurrently usiong a velocity based model then. although i question if there's any purpose in tracking energy, as i can just calculate it on the fly (0.5*mass*velocity squared)

    a friend is under the belief that the speed of the moving object affects the friction force imparted on it. or to put it another way, an object's rate of deceleration should fall as it becomes slower. is there any truth to this ?
  13. Dec 20, 2011 #12
    thanks for the help everyone, especially Lsos and Simon Bridge. I believe i now have all the information i need, and i'm beginning work on implementing friction ^^ For now i've decided not to support sloped surfaces, to make this simpler. but i will probably add them later.

    I wouldn't consider this issue closed yet, i may still run into problems, and i'll come back and ask for additional help if so.
  14. Dec 20, 2011 #13

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    You get the idea. Your simulation can be as complicated as you are prepared to work. Have fun :)

    Aside: if you have mainly smooth surfaces, you may prefer to define a "smoothness" (inverse roughness) for each instead.

    Depends on the exact form your simulation takes.
    It is often computationally simpler to model energies than forces or velocities ... but it may not be. Use the one that makes the math easier - if it is easier for you, you make fewer mistakes but if it is easier for the computer, you get more efficient calculations ... the usual balancing act.

    Air resistance is speed dependent - usually modeled as a drag-coefficient times speed-cubed. This is what gets you your terminal velocity when falling.

    Contact friction is proportional to the contact force - usually called a normal-force because it acts normal to the surface. Note: it does not depend on the contact area at all.

    There are two contact frictions - static and kinetic. Friction removes more energy just to start the object moving than it does to keep the object moving.

    All three come into play in a car: internal losses are mainly kinetic - moving parts - external losses are mostly drag, while static friction actually helps.

    You get drag from air and the fact you have to keep deforming the tires.

    Static friction (tires and road) drives the car forward.

    More simply:

    A block sliding at constant speed has: F=kmg (motive force equals friction - friction=k times weight. In your case k=bs: b=block roughness and s is for the surface. Alternatively: smoothness, q =1/k for F = mg/q.)

    Work done by the motive force over distance dx is dW=F.dx=kmg.dx
    If the block is pushed by an energy source supplying power P = dW/dt - that would be P=kmgv

    If some speed u < P/kmg then the block speeds up until u = v.

    Happy hacking :)
  15. Jan 7, 2012 #14
    hi everyone. I got distracted over the xmas holidays, but i did eventually get around to implementing friction. I've decided to implement it as a Newton force (dynamically converted into an acceleration depending on mass) and this is working great. All bugs now more or less ironed out, and i'm happy! thanks a lot everyone!
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook