Project Overview
Universe-Simulation-Java is a 2D gravitational particle simulator based on Newtonian mechanics. It models particle interactions over time and visualizes them in a Swing interface.
The project emphasizes clean object-oriented separation between geometry primitives, physics logic, simulation orchestration, data loading, and rendering.
Technologies and Tools
- Java (core implementation and simulation loop).
- Swing for desktop visualization.
- Newtonian mechanics for force and motion updates.
- Object-oriented design across geometry, physics, GUI and parsing layers.
- Text-based input configuration for reproducible initial states.
Purpose
The goal is to simulate and visualize how particles evolve under mutual gravitational attraction in a bounded 2D universe.
This creates an intuitive educational environment to inspect force interactions, orbital-like behavior, and stability trade-offs under discrete time integration.
Key Features
- Real-time 2D simulation with GUI rendering.
- Physics and visualization concerns are decoupled.
- Initial conditions loaded from structured text files.
- Scalable rendering for different universe radii and particle sets.
Project Structure
gui/UniversePanel.java: Swing rendering panel.lines/Point.java,Vector.java,Line.java,Implicit.java: geometry and math utilities.universe/Particle.java: particle state and force/motion operations.universe/Universe.java: simulation coordinator and time advancement.universe/UniverseData.java: input parsing and initialization.data/universes/: initial condition datasets.
Main Classes
| Class / File | Purpose |
|---|---|
| lines.Point / Vector / Line / Implicit | Geometry primitives and helper operations for 2D calculations. |
| universe.Particle | Stores position/velocity/mass/radius and updates dynamics from applied forces. |
| universe.Universe | Holds particle set and advances simulation state over dt time steps. |
| gui.UniversePanel | Maps simulation coordinates to screen coordinates and renders particles. |
| universe.UniverseData | Parses and validates input files to build initial simulation state. |
Particle Class Highlights
- Core fields:
position,velocity,mass, andradius. - Key methods include
forceFrom(Particle)andmove(Vector force, double dt). - Represents each body as both a physical entity and renderable primitive.
Universe Class Highlights
- Stores particle collection and simulation radius.
- Main step method
advance(double dt)computes interactions and updates all particles. - Acts as the orchestrator between data model and rendering layer.
How It Works
- Initialization: parse input file and build particles via
UniverseData. - Simulation loop: compute pairwise gravitational effects and integrate motion.
- Visualization: render updated particles in
UniversePanelafter each step.
Simulation Notes
The original project detail page includes an interactive DOM-based preview script. In this portfolio content layer, that behavior is represented as static explanation plus snapshots for compatibility and maintainability.
The numerical behavior still reflects the same conceptual pipeline: pairwise force accumulation, time-step integration, and repeated repaint cycles.


Architecture Summary
| Layer | Responsibility |
|---|---|
| Input and parsing | Load simulation config and validate particle initialization values. |
| Physics kernel | Compute gravitational interactions and update kinematics. |
| Simulation control | Advance global state and manage iteration rhythm. |
| Rendering | Transform world coordinates and draw particles in Swing. |


