Skip to main content
gamedev.net
🔒 Locked

damped pendulum

Started by nataku92 Jan 22, 2006 at 12:33 AM 3 replies 1.1k views
Original Post
nataku92
nataku92
How would I add a dampening constant to a simple pendulum with the following code: vel -= 9.8*Math.sin(theta)*dt; theta += vel*dt/RADIUS; Thanks
erissian
erissian
vel -= 9.8*Math.sin(theta)*dt*exp(-b*dt);

Where b is some positive number.

[Edited by - erissian on January 22, 2006 9:37:31 AM]
We''re sorry, but you don''t have the clearance to read this post. Please exit your browser at this time. (Code 23)
nataku92
nataku92
hm...I can change the general speed of the pendulum using that but I'm looking for dampening where the pendulum will slow down and eventually stop
erissian
erissian
Whoops, I misread that.
vel -= 9.8*Math.sin(theta)*dt;
vel *= exp(-b*dt);
theta += vel*dt/RADIUS;

That's a traditional dampening factor for oscillations.
As you keep calling this function, that exp(-b*dt) term will keep multiplying itself. After n iterations, the factor becomes exp(-b*dt*n). As n increases to infinity, -b*dt*n approaches negative infinity, and that means exp(-b*dt*n) approaches 0.

So calling vel *= exp(-b*dt) repeatedly reduces the velocity to 0 over time. You control how fast by increasing b.
We''re sorry, but you don''t have the clearance to read this post. Please exit your browser at this time. (Code 23)
nataku92
nataku92
Thanks, it works perfectly! :D

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.