A physics-based golf swing and ball trajectory simulator with an interactive GUI built using Tkinter and Matplotlib.
- Python 3.12+ is recommended for best compatibility
- Third-party packages:
matplotlib,numpy - Standard library:
tkinter,math,cmath,sys
pip install matplotlib numpyOn some Linux systems, tkinter may need to be installed separately:
# Debian/Ubuntu
sudo apt-get install python3-tk
# Fedora
sudo dnf install python3-tkinterpython Main.pyThe simulator models a two-degree-of-freedom golf swing using torque-driven angular mechanics. Users can configure:
- Golfer parameters -- gender, weight, shoulder radius, arm length
- Club parameters -- head/shaft mass and length
- Swing conditions -- swing plane angle, initial/impact arm angle, wrist-cock angle, swing type (Type I / Type II)
- Torques -- arm torque, wrist-cock torque (with automatic optimization)
Three numerical solution methods are available, all based on 4th-order Runge-Kutta integration.
The ball flight model includes drag, lift, spin (Magnus effect), and wind. Configurable parameters:
- Ball mass, diameter, drag/lift coefficients
- Coefficient of restitution (COR)
- Air density, wind speed/direction
- Clubhead loft angle, launch angles, spin angles
Swing plots: Tracks, angles, angular velocities, angular accelerations, clubhead velocity, torques, arm length, and moment of inertia.
Ball trajectory plots: X-Z (elevation), X-Y (horizontal), Y-Z (lateral), and 3D flight path.
The full technical report (two-rod swing model, aerodynamic equations, simulation cases, and user's guide) is available as Sphinx documentation under docs/.
To build:
pip install sphinx sphinx-rtd-theme
cd docs
sphinx-build -b html . _build/htmlThen open docs/_build/html/index.html in your browser.
| File | Description |
|---|---|
Main.py |
GUI application entry point |
BasicFunc.py |
Core swing physics |
BasicFunc2.py |
Ball trajectory physics |
AppFunc.py |
Swing simulation functions |
AppFunc2.py |
Ball trajectory simulation functions |
Plot.py |
Swing visualization |
Plot2.py |
Ball trajectory visualization |
Case1.py - Case10.py |
Standalone example cases |
ISC License -- Copyright (c) 2026, Cheng-Chin Chiang