Skip to content

nitya-d/shm-pendulum-simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SHM Pendulum Simulation

An interactive simulation of a driven-damped pendulum built with VPython/GlowScript. Originally written as a high school project: a first attempt at computational physics and learning to turn physical equations into working code. It's not perfect, but it was the project that got me interested in the overlap between physics and computer science.

Simulation screenshot

Try the interactive version


Physics

The simulation models a pendulum governed by:

θ'' = -(g/L)sin(θ) - bθ' + F₀cos(ω₀t)

where:

  • g is gravitational acceleration
  • L is pendulum length
  • b is the damping coefficient
  • F₀ is the driving force amplitude
  • ω₀ = √(g/L) is the natural frequency

The driving force is applied at the natural frequency, producing resonance behaviour when combined with low damping. Time integration uses the Euler-Cromer method.

Features

  • Real-time 3D pendulum visualisation
  • Adjustable parameters via sliders:
    • Pendulum length and bob mass
    • Gravitational acceleration (e.g. set to 24.79 m/s² for Jupiter)
    • Damping coefficient
    • Driving force amplitude
    • Timestep dt
  • 6 live graphs: position, velocity, acceleration, theta, KE/PE/total energy, and a phase space plot (θ vs dθ/dt), the phase space portrait shows the transition from simple oscillation to chaotic motion as driving force increases
  • Reset button to restore all parameters and clear graphs

Running locally

Requires Python 3.11 (vpython has known compatibility issues with Python 3.12+).

pip install vpython
python main.py

This opens the simulation in your browser via a local server.

GlowScript

The code runs as-is on glowscript.org. Just remove the from vpython import * import line, as GlowScript provides all built-ins globally.

About

Driven-damped pendulum simulation with real-time parameter sliders and phase space plotting. Built with VPython/GlowScript

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages