PDA

View Full Version : "Friction" problem



tezzutezzu
October 12th, 2010, 06:22 AM
Hello there,

I'm trying to write an algorithm to constantly decelerate a spinning wheel with velocity of 10 so that when the speed reaches 0 the wheel would have rotated 360 degrees from the position where it started decelerating.

At the moment I'm using a "friction" value to slow down the wheel velocity so that the wheel rotates exactly 360 degrees. This value though, is found empirically and it works only for that amount of degrees, instead I would like to find an equation from where I can retrieve that friction value for any number of degrees.

Here is the pseudo code I'm using for every frame:




if(decelerating) {
rotationVelocity *= friction;
}

wheel.rotation += rotationVelocity;



How can I find that friction value?

Thanks!

D

TOdorus
October 12th, 2010, 10:59 PM
http://en.wikipedia.org/wiki/Logarithm

http://www.gskinner.com/blog/archives/2009/11/calculating_log.html

TheCanadian
October 13th, 2010, 01:12 AM
This is kind of off the top of my head but something like this would work I think:

var u:Number = 10; //initial velocity in degrees / frame
var s:Number = 360; //displacement in degrees

var a:Number = u * u / (2 * s); //acceleration in degrees / frame^2

circle.onEnterFrame = function():Void {
if(u >= a) this._rotation += (u -= a);
else delete this.onEnterFrame;
}

tezzutezzu
October 13th, 2010, 07:15 AM
Thanks TheCanadian. You're awesome!

If it's ok with you, could you give me an insight on how you got to that result?

tezzutezzu
October 13th, 2010, 10:13 AM
Hey theCanadian,

I was able to get the acceleration from this formula:

http://upload.wikimedia.org/math/4/2/c/42cf393328ab255ac2ccdb283ed34032.png

and

http://upload.wikimedia.org/math/6/6/b/66b96349fd86021f13bf77d5ec850e97.png

where:
t is the time
x(t) is the amount of space traveled in a uniformed accelerated motion
x0 is the starting point
vx0 is the starting velocity
and a is of course the acceleration we want to find

therefore

http://imgur.com/FCSj5.png

http://mathbin.net/equation_previews/11298_0.png

TheCanadian
October 13th, 2010, 12:25 PM
v^2 = u^2 + 2as

It's just one of the basic 1D physics formulas which I'm sure was derived exactly as you just did :)