Skip to content

dennwill/comphys-final

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pendulum Simulation

An interactive physics simulation of a pendulum in different environments (Air, Water, and Vacuum) using Python and Pygame.

Overview

This project simulates a simple pendulum's motion in three different environments, demonstrating key physics concepts such as:

  • Simple harmonic motion
  • Damping effects in different media
  • Energy conservation and transformation
  • Interactive physics manipulation

Features

  • Multiple Environments:
    • Air: Slight damping (0.999)
    • Water: Significant damping (0.95)
    • Vacuum: No damping (1.0)
  • Interactive Controls:
    • Click and drag to manipulate the pendulum
    • Adjust pendulum length using arrow keys
    • Reset pendulum position with spacebar
    • Switch environments using number keys (1, 2, 3)
  • Real-time Physics:
    • Accurate pendulum motion simulation
    • Visual trail of pendulum movement
    • Environment-specific visual effects
  • Visual Feedback:
    • Real-time angle and velocity display
    • Environment-specific backgrounds
    • Pressure gauge in vacuum mode
    • Water surface effects in water mode

Physics Background

1. Simple Pendulum Motion

The pendulum follows the classic simple pendulum equation:

θ'' = -(g/L)sin(θ)

where:

  • θ is the angle of displacement
  • g is gravitational acceleration (9.81 m/s²)
  • L is the length of the pendulum

2. Damping in Different Media

The simulation models different levels of energy loss:

  • Air: Very slight damping (0.999)
  • Water: Significant damping (0.95)
  • Vacuum: No damping (1.0)

3. Energy Conservation

The pendulum continuously converts between:

  • Potential Energy: U = mgh = mgL(1 - cos(θ))
  • Kinetic Energy: K = ½mv² = ½mL²ω²

Installation

  1. Ensure you have Python 3.x installed
  2. Install required packages:
pip install pygame

Usage

Run the simulation:

python main.py

Controls

  • 1: Switch to Air environment
  • 2: Switch to Water environment
  • 3: Switch to Vacuum environment
  • Left/Right Arrow: Adjust pendulum length
  • Space: Reset pendulum position
  • Mouse: Click and drag to manipulate pendulum
  • ESC: Quit simulation

Project Structure

  • main.py: Main simulation loop and user interface
  • pendulum.py: Pendulum physics implementation
  • decoration.py: Visual effects and environment rendering
  • constants.py: Simulation constants and configuration

Limitations

  • The damping coefficients are simplified models and not based on actual experimental data
  • The simulation uses basic Euler integration for physics calculations
  • Air and water resistance are modeled using simplified damping factors

Acknowledgments

  • Pygame library for graphics and user input handling
  • Physics principles based on classical mechanics
  • Inspired by educational physics simulations

About

Final Project of Computational Physics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages