# calc velocity on inclined plane with friction

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

## Recommended Posts

Hey, so in a 2d physics engine I have an inclined plane with a frictional value. Along with a "player" that has a mass. The player object will have an initial x and y velocity and hit an inclined plane that has a slope (theta) along with a friction coefficient. 1. How do I calculate the new speed using the initial speed, mass, gravity, friction coefficient of slope, and angle of slope for both the x and y directions over a period of time (delta). (This must work even if the slope is 0°) 2. How does acceleration factor in? You must accelerate down the slope, how is this calculated. Any help is appreciated! Thanks

##### Share on other sites
What have you tried?

Side questions: what's the coefficient of restitution? can the object roll down the hill? Why do you assume the object will continue to slide down the hill and not come to a stop? how accurate of a friction model are you interested in? Are you familiar with vectors? is this a 2d side scroller or a 3d game?

##### Share on other sites
Quote:
 what's the coefficient of restitution?

There isn't a coefficient of restitution. Only friction coefficient between the object and the surface

Quote:
 can the object roll down the hill?

no

Quote:
 Why do you assume the object will continue to slide down the hill and not come to a stop?

I do think that it will come to a stop. I'm hoping that when the object is on the slope it will already have an initial velocity vector. So I want to calculate the final velocity vector using the initial velocity when it hits the slope along with the friction coeffecient I have between the two objects, and of course theta.

Quote:
 how accurate of a friction model are you interested in?

Not super accurate. The physics engine itself is pretty basic. The objects all have acceleration and velocity vectors. Basic Bounding Box / Proximity collision models. I have the players working in game but they slide forever because there is no friction to stop them. I want to apply friction to my players on all surfaces, which could include slopes (defined by two x/y positions).

Quote:
 Are you familiar with vectors? is this a 2d side scroller or a 3d game?

2d side scroller

##### Share on other sites
Constant deceleration:
void ApplyFriction( Vector& velocity, float rate ){  float speed = velocity.Length( );  if( speed == 0.0f ) return;  velocity /= speed;  rate = min( rate, speed );  speed -= rate;  velocity *= speed;}

##### Share on other sites
Thanks for the suggestion but I'm not quite sure that is what I am looking for. I am looking for something more along the lines of a formula.

Such as (keep in mind I am making this up)
Vfx = Vix + (mg)(cos(theta)) * (frictionCoefficient)

Or something similar to that so I can calculate the new speed of the player based on the initial speed of the player and factor in the slope of the incline and the friction coefficient.

##### Share on other sites
You should not be concerned with theta, cosine, or independent components. (ie x, y, z) You should treat everything as vectors and use vector operations such as dot product and cross product.

Why does my solution not achieve the results you desire? You'd also need to integrate the force from gravity projected onto the normal.

If you apply friction after the acceleration of gravity, it should be able to diminish any gravity acceleration rate less than the friction rate, bringing the object to a stop.

If the acceleration of gravity (after being projected onto the normal) is greater than the friction rate, then the object will continue to slide.

With constant accelerations there are only a few outcomes.

If accGravity == accFriction then velocity remains constant
if accGravity > accFriction then velocity increases continuously
if accGraivty < accFriction then velocity will diminish to zero.

So your three potential "final" velocities are: the same, infinity, and zero.

The rate that the velocity will change is (accGravity - accFriction).

[Edited by - bzroom on May 4, 2010 2:54:55 PM]

##### Share on other sites
Hmm... the project is an actionscript project so I have written the engine myself. So far everything works with the exception of friction. I wrote a class called Vector2D that stores the x and y components of a vector and has math operations in it. So far with all of the math I am doing I am mostly working with the x and y components of the vector independtly. This is really the first physics engine I have written. It is for a college project.

Quote:
 You should not be concerned with theta, cosine, or independent components. (ie x, y, z) You should treat everything as vectors and use vector operations such as dot product and cross product.

How can I apply cross/dot product to the problem at hand?

Quote:
 You'd also need to integrate the force from gravity projected onto the normal.

How do I project the force of gravity (9.81 m/s) to the normal of the surface since gravity acts in the y direction?

Quote:
 If you apply friction after the acceleration of gravity, it should be able to diminish any gravity acceleration rate less than the friction rate, bringing the object to a stop.

Gravity has already been calculated into the speed of the player before the friction function will be called. To keep it simple for now, lets say the friction coefficient is .8. How could the amount of friction ever be greater than the amount of gravity? Am I comparing mg*frictionCoefficient to mg?

Like I've said so far I have been working with x/y components of my vectors. Is there a better solution? After re-examining the problem from a physics stand point I have realized that what I actually need to solve for is the new acceleration of the object, and then the acceleration values should slow the object down over time (unless the above ideas will work better)?

##### Share on other sites
Calling apply gravity alone (assuming you're rectifying penetration) the body will ride along the surface, accelerating down hills, and decelerating as it goes up them.

Deceleration rate is not a coefficient. It's a rate, as in m/s^2. How ever you come up with this rate is up to you, may choose to use the normal force and a coefficient. But ultimately it's just going to result in some deceleration rate.

Vec3 ProjectOntoPlane( const Vec3& input, const Vec3& planeNormal ){	return input - planeNormal * Dot( input, planeNormal );}void ApplyGravity( Vec3& vel, const Vec3& surfaceNormal, float gravity, float deltaTime ){	Vec3 deltaV( 0, gravity * deltaTime, 0 );	vel += ProjectOntoPlane( deltaV, surfaceNormal );}void ApplyFriction( Vec3& vel, float friction, float deltaTime ){	float speed = vel.Length( );	if( speed == 0.0f ) return;	friction = min( friction * deltaTime, speed );	float newSpeed = speed - friction;	vel *= newSpeed / speed;	}void UpdateBody( Body& body, float deltaTime ){	const float gravityRate = -9.8f;	const float decelerationRate = 2.f;	Vec3 surfaceNormal = body.SittingOn( ).Normal;	ApplyGravity( body.Vel, surfaceNormal, gravityRate, deltaTime );	ApplyFriction( body.Vel, decelerationRate, deltaTime );	body.Pos += body.Vel * deltaTime;}

You can see here that the effective gravity rate is dependent on the dot product between gravity and the surface normal. The effective gravity rate will be zero if the surface is level. In that case the deceleration rate is significantly higher and will stop the object from moving.

##### Share on other sites
wow great stuff! I think this is exactally what I was looking for. They don't teach it like that in physics lol. I really appriciate all the help! I'm gonna work on implementing some of it tomorrow I'll let you know how it goes.

##### Share on other sites
So I got most of it working. The thing that I am not seeing with your example is mass. The deceleration due to friction should take into consideration the mass of the object. As in the real world it will take much longer for a semi truck to stop than a car. Any suggestions to how mass can be worked in to work with friction?

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633767
• Total Posts
3013739
×