How yonko-sid/rutherford-experiment-simulation works
Purpose and executable entry point
This is a native C++20/SDL3 desktop simulation of Rutherford gold-foil scattering. It visually launches alpha particles toward a central gold-atom column, numerically applies Coulomb repulsion, and renders deflected trajectories. The application entry point, SDL initialization, event loop, camera behavior, and rendering reside in rutherford.cpp.
Build and runtime boundary
CMake builds one SDL3-linked executable from the simulation/UI and physics translation units. The project targets C++20 and requires SDL3 for windowing, input, and 2D rendering. Build configuration is in Cmakelists.txt; it includes an MSYS2-oriented prefix-path assumption that may need adjustment outside Windows.
Physics domain model
The physics API defines physical constants, particle/nucleus state, and simulation-facing declarations in physics.h. It models positively charged alpha particles and gold nuclei using real-scale quantities: charge, mass, nuclear radii, particle speed, detector boundary, and Coulomb’s constant.
Force calculation and collision boundary
physics.cpp is the numerical core. For each alpha/nucleus interaction it calculates Coulomb repulsion from separation distance. A minimum separation equal to the combined nuclear/alpha radii clamps close approaches, preventing singular forces and numerical tunneling through a nucleus. Gold nuclei act as fixed scattering centers; alpha particles are the moving entities.
Time integration and lifecycle
The renderer-driven frame loop in rutherford.cpp advances active particles through the physics module in physics.cpp. Each simulation frame is split into 1,000 micro-steps using a tuned femtosecond-scale timestep, prioritizing stability at high alpha velocity and femtometer nuclear distances. Particles exceeding roughly 1.05 times the detector radius are removed to bound memory growth.
Input, control flow, and visualization
SDL events in rutherford.cpp control particle emission, pausing, camera pan/zoom, view tilt, reset, and exit. Pause gates physics advancement but leaves event processing and rendering active, enabling inspection of existing trajectories. The rendering layer converts the physical scene—foil/nuclei, detector boundary, and particle trajectories—into screen-space using camera state.
Primary flow
1. SDL setup and scene initialization occur in rutherford.cpp.
2. User input emits alpha particles or changes simulation/camera state.
3. When unpaused, rutherford.cpp invokes physics updates from physics.cpp.
4. Physics applies sub-stepped Coulomb acceleration, clamping, integration, and out-of-bound cleanup.
5. The updated particle collection is rendered through SDL3 each frame.
Main entry points: rutherford.cpp Application entry & frame loop · physics.h Alpha particles · physics.cpp Physics update · Cmakelists.txt CMake build
Components 15
SDL Application
- Application entry & frame loop · Owns SDL setup, events, frame advancement, and rendering.
rutherford.cpp - Input controls · Controls emission, pause, reset, exit, and camera state.
rutherford.cpp - Scene state · Contains particles, nuclei, detector, and camera state.
rutherford.cpp - Pause gate · Stops physics advancement while events and rendering continue.
rutherford.cpp - Camera transform · Maps physical coordinates to screen space with pan, zoom, and tilt.
rutherford.cpp - SDL scene renderer · Draws foil nuclei, detector boundary, and trajectories.
rutherford.cpp
Physics Engine
- Physics API & model · Defines constants plus alpha-particle and gold-nucleus state.
physics.h - Alpha particles · Positively charged particles launched toward the foil.
physics.h - Gold nuclei · Fixed positively charged Coulomb centers.
physics.h - Physics update · Advances active alpha particles against fixed nuclei.
physics.cpp - Coulomb force & clamp · Clamps separation to combined radii to avoid singular forces.
physics.cpp - Micro-step integration · Uses 1,000 femtosecond-scale sub-steps per frame.
physics.cpp - Detector-bound cleanup · Removes particles beyond about 1.05 detector radii.
physics.cpp
Build & Runtime
- CMake build · Builds the C++20 SDL3 executable.
Cmakelists.txt - SDL3 · Provides windowing, events, and 2D rendering.
Connections 25
- CMake build → Application entry & frame loop: builds
- CMake build → Physics update: builds
- CMake build → SDL3: links
- Application entry & frame loop → SDL3: initializes and uses
- Application entry & frame loop → Input controls: processes
- Input controls → Scene state: changes
- Input controls → Pause gate: toggles
- Input controls → Camera transform: controls
- Input controls → Alpha particles: emits
- Application entry & frame loop → Pause gate: checks
- Pause gate → Physics update: gates advancement
- Application entry & frame loop → Physics update: advances each frame
- Physics API & model → Physics update: declares interface and state
- Physics update → Coulomb force & clamp: calculates
- Coulomb force & clamp → Micro-step integration: supplies acceleration
- Micro-step integration → Alpha particles: updates position and velocity
- Gold nuclei → Coulomb force & clamp: repels
- Alpha particles → Coulomb force & clamp: interacts with
- Micro-step integration → Detector-bound cleanup: passes updated particles
- Detector-bound cleanup → Alpha particles: removes out-of-bounds
- Application entry & frame loop → SDL scene renderer: renders each frame
- Scene state → SDL scene renderer: provides physical scene
- Camera transform → SDL scene renderer: provides screen transform
- Alpha particles → SDL scene renderer: draws trajectories
- Gold nuclei → SDL scene renderer: draws foil