Sign in to follow this  
AndyGil

pendulum / swing effect

Recommended Posts

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.

Thanks
Andy

Share this post


Link to post
Share on other sites
I would try using the equations here [url="http://en.wikipedia.org/wiki/Pendulum_(mathematics)"]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

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


theta += thetaDot*dt;
thetaDot += thetaDoubleDot*dt;
[/code]

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

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

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