projects / spring-pendulum

Spring-Pendulum Simulation

A case study in turning a coupled nonlinear model into an interactive web tool: define the equations, choose a stable numerical method, and expose the right controls so users can learn from parameter changes.

1) Model and governing equations

The state is represented by [r,θ,r˙,θ˙]\left[r,\theta,\dot{r},\dot{\theta}\right] where rr is spring length and θ\theta is angular displacement from the vertical. The model includes gravity, spring restoring force, and damping in radial and angular directions.

r¨=gcos(θ)km(rl0)crr˙\ddot{r}=g\cos(\theta)-\frac{k}{m}(r-l_0)-c_r\dot{r}
θ¨=grsin(θ)cθθ˙\ddot{\theta}=-\frac{g}{r}\sin(\theta)-c_{\theta}\dot{\theta}

These equations produce rich motion regimes depending on initial conditions and stiffness-to-mass ratio.

2) Numerical solution strategy

The simulator uses a fixed-step RK4 integrator with user-controlled Δt\Delta t and end time tendt_{\mathrm{end}}. RK4 offers a practical balance: significantly better local accuracy than Euler while keeping implementation simple and predictable for browser playback.

The trajectory quality depends on timestep choice. Smaller Δt\Delta t improves fidelity but increases compute and rendering load. Larger timesteps run faster but can smooth out fast dynamics and reduce trust in the trace.