Sign in to follow this  

pendulum / swing effect

Recommended Posts

AndyGil    100
Hi, im trying to impliment a pendulum or swing effect and finding it a little difficult to get good results.

Ive googled and read and seen the forumulas to work out the period etc but im struggerling to convert these into comupter programming.

For now all im trying to do is a simple pendulum movement with dampening.

Anyone know how i could go about it?

Any language code is fine, im using C++ & lua.


Share this post

Link to post
Share on other sites
p0pes    99
I would try using the equations here [url=""]http://en.wikipedia....m_(mathematics)[/url] for angular accleration (equation 1) and angular rate (equation 2) and then in an update loop do something like

thetaDot = sqrt(2*g/l*(cos(theta) - cos(theta0)));
thetaDoubleDot = -g*sin(theta)/l;

theta += thetaDot*dt;
thetaDot += thetaDoubleDot*dt;

where "l" is the pendulum length, "g" is gravity and "dt" is your update time step.

And then you can just draw your sphere or whatever is on the pendulum based off of theta and the pendulum length "l"

To add it damping you could just add a drag term to thetaDot term and make it something like

thetaDot = sqrt(2*g/l*(cos(theta) - cos(theta0))) - dragTerm;

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this