Spherical Pendulum

Spherical Pendulum models a particle under the influence of gravity that is constrained to stay on a spherical surface.  The simplest example is that of a pendulum that is free to swing in any direction.  This problem is most conveniently solved using spherical coordinates (r, θ, φ) where r is the radius, θ is the angle the pendulum makes with respect to the vertical z-axis, and φ is the rotation angle about the z-axis.  These polar coordinates are converted into Cartesian (x, y, z) coordinates after every time step to position the pendulum bob in a three-dimensional Ejs world view.

Differential equations for (θ, φ) are easily derived using Lagrangian mechanics. The Langranian equation for θ yields:

.

Because the angular momentum about the z-axis Lz is conserved, we need only solve the θ equation.  The φ rate of change for any value of θ  is computed by solving for dφ/dt using the (fixed) value of Lz. that is computed from the initial conditions:

.