hi. For small pendulum movements the formula is reduced and the actual motion is called "simple harmonic motion". "For small movements" means sin(theta) ~= theta and theta is the angle between the pendulum and the world surface normal.
So for small angles, this motion (simple harmonic motion) is described by: F = -k*x which is also observed in springs. At any location x away from the steady state location, the force applied is equal to some constant times x. "k" is constant of spring. Higher "k" means smaller period.
-(--------o--------)+
...............O...
<--x-->
"O" is the oscillating body, and "o" is the origin where the body will not move if it was left free.
Ok, by knowing this equation you should be able to write the code:
F = -k.x
you know "k" and you initially define an "x"
so for this k and x you find F. Note that minus sign actually defines the direction of the force. If x is positive force is negative meaning that it forces to left(assuming left is negative right is positive).
Once you have F, define an "m" which stands for mass. The heavier the body the higher the period(time elapsed for one "lap")
then,
a = F/m
where "a" is acceleration. Rest is easy. Once you have "a" simply
v = a*dt
where v is speed and dt is the time elapsed between each update of equations.
then,
x = x + v*dt
where you find a new x. Voila!
Note that at the beginning I said for small angles, but during a game or something nobody will recognize this. Since this is the absolutely correct formula for spring oscillation it does a decent job for pendulums also. However if you really need a perfect formula (for a science project or something) you can still use the computer easily, but it needs some more physics which I cannot explain without some drawings, if so e-mail me and I'll try my best.
I hope this helps, I am always bad at explaining things to others.
PS: I just found that period = 2*pi*sqrt(m/k). Note that it does not depend on initial x

Edited by - oztanharmanci on July 23, 2001 12:44:34 PM