🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Pool physics

Started by
5 comments, last by tasseloff 19 years, 2 months ago
hi, i don't know if any of you read "Physics on the Back of a Cocktail Napkin" from http://www.gamasutra.com/features/20000516/lander_01.htm but im having lots of trouble to figure out how he applied the physics in the small demo program he gives...Basically, he says that to to verify if a ball is rolling or sliding, it has to satisfy "v = Rw" where w is the angular velocity, yet in his demo program he doesn't calculate that velocity anywhere, instead he does this :

			FdotN = g_Gravity.y / curBall->oneOverM;		// Gravity
			// Calculate Vt Velocity Tangent to Normal Plane
			MAKEVECTOR(contactN,0.0f, 1.0f, 0.0f)
			VdotN = DotProduct(&contactN,&curBall->v);
			ScaleVector(&contactN, VdotN, &Vn);
			VectorDifference(&curBall->v, &Vn, &Vt);
			Vmag = VectorSquaredLength(&Vt);
			// Check if Velocity is faster then threshold
			if (Vmag > STATIC_THRESHOLD)		// Use Kinetic Friction model
			{
				NormalizeVector(&Vt);
				ScaleVector(&Vt, (FdotN * g_Ckf), &Vt);
				VectorSum(&curBall->f,&Vt,&curBall->f);
			}
			else	// Use Static Friction Model
			{
				Vmag = Vmag / STATIC_THRESHOLD;
				NormalizeVector(&Vt);
				ScaleVector(&Vt, (FdotN * g_Csf * Vmag), &Vt);  // Scale Friction by Velocity
				VectorSum(&curBall->f,&Vt,&curBall->f);

im really having trouble to understand what he does in this code to verify if the ball is rolling or not...anyone good at physics could help me out...im really desesperate here :(
Advertisement
this has nothing to do with sliding or rolling. He is calculating the amount of tangencial velocity, and apply a different friction model.

He should really use C++ and operators, that's a lot clearer.

V = Ball.V + Ball.W ^ (Pcontact - Ball.P);
N = Vector(0, 1, 0);

Vn = (V * N) * N;
Vt = V - Vn;
float vt = Vt.Length();

if (vt > threshold)
{
// do dynamic friction
}
else
{
// do static friction
}

V badsically is the contact velocity, which is V = Vball + Wball ^ Rball;

Vball is the translation velocity of the ball, Wball is the angular velocity, Rball is vector from point of contact (bottom of the ball) to centre of the ball.

now,

if the ball slides, through the calculations above, Vt will then have a a magnitude > threshold => dynamic friction

if the ball doesn't slide, Vt will have a magnitude < threshold => static friction.

Everything is better with Metal.

Lol, oliii it's actually kind of funny how much knowledge you have about physics. Every time somebody posts asking about physics, you're the first one to reply. Did you major in physics or something?
so what you're saying is that he just uses different frictions depending on the velocity of the ball??
im not sure to understand why he would do that, unless its to somehow emulate the different frictions that are present when the ball is rolling and when its sliding...???

and also in the code you re-wrote you have the angular velocity Ball.W....but i don't see that anywhere in his code :|
I wish I was good at physics. That's just basic rigid bodies, and pretty much as far as I can stretch. There are far far more complex things, unfortunately.

Quote:
so what you're saying is that he just uses different frictions depending on the velocity of the ball??
im not sure to understand why he would do that, unless its to somehow emulate the different frictions that are present when the ball is rolling and when its sliding...???


that's the way friction works, at least in the coulomb model. THere is static friciton and dynamic friciton. For static friciton, think of a heavy box on a floor. THink of how much force you need to produce to make the box move from stand-still. That's static friction. If the box was on ice, a very small force would be necessary. If the box was on sand, you'd need a lot more force. Also, you can imagine a crate on an shallow incline. The crate will not slide, due to static friction. However, nudge it, and it will start to slide, and probably keep on sliding.

Now the box is moving, think of how much force you have to produce to keep the box moving at the same speed. That's dynamic friction. Also, the dynamic friction is generally smaller thasn the static friction.

Again, with moving a box on the floor, the first push is the hardest. Once it's going, it will be easier.

So that's why there is two friction model.

For a ball, the contact velocity of a ball on the table will be 0 if the ball is rolling. It's hard to picture, but imagine the ball not rolling at all. Then the cotnact velocity will be equal to the linear velocity of the ball. The rotation cancel it out. So, the contact velocity is very small, meaning you have to use static friciton model. That is important, else, your ball will keep on rolling with an infenitisimal velocity if you just use the kinetic fricion model, when it shouldn't. That static friction force will put a full stop to the motion of the ball (due to the need for a startup force to make the ball move from 0 velocity).

Equally, for car tyres on a straight road, the contact velocity at the point where the tyre is free-rolling will be 0. Once the car starts turning, the contact velocity will change, producing grip forces (tangent friciton forces) that makes the car turn. When the car accelerate, it's the same principle. The contact velocity between the tyre and the road change, producing friciton force which in turn excerts a force on the car and push it forward.

Tyres being complex rubbery things, it's not exactly like that. The tyre will deform first, and you get all sorts of transcient forces coming into play, and it's all a mess. And I'm not even considering the problem when the rubber particles slip and twist and loose grip at a microscopic level, that make the squeeling sound.

But for pool balls, you can consider them totally rigid and undeformable.

Now, static friction is quite problematic, since it produces a state change in the object. From not-moving to moving and vice versa.

anyway, the equations he uses...

// Use Kinetic Friction model
if (Vmag > STATIC_THRESHOLD)
{
NormalizeVector(&Vt);
ScaleVector(&Vt, (FdotN * g_Ckf), &Vt);
VectorSum(&curBall->f,&Vt,&curBall->f);
}

in my language translates to

if (Vmag > STATIC_THRESHOLD)
{
Vector Direction = Vt / Vmag;
Ball.Force += (FdotN * g_Ckf) * Direction;
}
ok, that makes more sense.

Now, for this to work, FdotN has to be negative, which it is in the example of a pool ball game (F = gravity, pointing down, N pointing up, dot product < 0).

He is using the standard coulomb equation. The kinetic friction force on the ball is equal to the normal force on the ball times the coefficient of kinetic friciton. The direction of the force is opposite the tangencial velocity (the component of the velocity in the [X, Z] plane).


Now the static friciton, which is usually tricksy.

else // Use Static Friction Model
{
Vmag = Vmag / STATIC_THRESHOLD;
NormalizeVector(&Vt);
ScaleVector(&Vt, (FdotN * g_Csf * Vmag), &Vt);
// Scale Friction by Velocity
VectorSum(&curBall->f,&Vt,&curBall->f);
}

translation ...


else
{
Vector Direction = Vt / Vmag;
Ball.Force += (FdotN * g_Csf * (Vmag / STATIC_THRESHOLD)) * Direction;
}

ok...

STATIC_THRESHOLD is the point where the velocity is considered so small the ball should not be moving.

So, he is doing like the kinetic friction, but scaling it by the velocity ratio, which is kind of weird, and more likely a hack. I think he is trying to prevent the ball from jittering on the spot, by damping the friction as the velocity reduces. This will not make the ball stop.

Anyway, a weird equation that doesn't have any physical meaning, and is just to make the game look good enough.


as for the rotation, my guess is, he is not doing full on 3D rigid body dynamics, but hack the equations again. when he say V = r.W, then he must use W as a scalar, and assuming the ball only rolls along the veloctiy vector, which is fair enough. However, with a little more work, you could get a much more satisfying effect if the ball was allowed to roll with 3 degrees of freedom. THen you'd get all sorts of weird spin effects that makes pool and snooker the game it is.

Everything is better with Metal.

Hey guys.

I wrote that article years ago. The article talked more about rotational dynamics when it comes to determining when a ball is rolling true and when it is sliding relative to the surface.

Olii has the friction thing explained right as usual. Different coefficients for static and dynamic friction.

The demo however didn't have the rotational dynamics. I just ran out of time that month to finish the app (so I left the rotational dynamics part to be finished later). Of course I never got around to it.

It also was written in straight c for easy porting when C++ was not as common.

For a lecture at a high school I am giving, I am completely rewriting that code and some more on the article. The new version not only supports the rotational dynamics and friction but is fully 3D.

I will post a note when that is all written up. In the meantime if you have any other questions about that stuff, let me know.

-Jeff
Wow! i didn'T expect to get a reply from the author himself!
i will read in detail olii's post, i think it answers my question, i might have a few more afterwards.
I have to say your article was really helpful so far, what was confusing me was that you didn't apply all the physics you talked about but i can understand that you just didn't have time. Right now i am working on creating a player with AI that will make the best shot possible at a pool game.

Ill read on a bit more and let you know how it goes :)
thanks for a really good article and demo!

PS: thanks a lot for the good explanation olii

This topic is closed to new replies.

Advertisement