Skip to main content
1 of 6

Here is a no-trig calculation, derived from straight-forward Grade 11 Trig and Physics. It assumes that the origin is the lowest point of the pendulum bob's suspension, that L is the length of the pendulum, and that the normal graphics convention of y increasing down, and x increasing to the right is adopted:

const float gravity = 9.8;

var xVelocity = 2.0;  // adjust this figure to taste; leave other start values as is
var yVelocity = 0.0;
var x = 0.0;
var y = 0.o;

while (true) {
  var xAcceleration = -g * (x/L) * (L-y)/L;
  var yAcceleration = -g * x * x / (L * L);
  
  x += xVelocity + xAcceleration/2;
  y+= yVelocity + yAcceleration/2;

  xVelocity += xAcceleration;
  yVelocity += yAcceleration;
}