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 / FilePurpose
lines.Point / Vector / Line / ImplicitGeometry primitives and helper operations for 2D calculations.
universe.ParticleStores position/velocity/mass/radius and updates dynamics from applied forces.
universe.UniverseHolds particle set and advances simulation state over dt time steps.
gui.UniversePanelMaps simulation coordinates to screen coordinates and renders particles.
universe.UniverseDataParses and validates input files to build initial simulation state.

Particle Class Highlights

  • Core fields: position, velocity, mass, and radius.
  • Key methods include forceFrom(Particle) and move(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

  1. Initialization: parse input file and build particles via UniverseData.
  2. Simulation loop: compute pairwise gravitational effects and integrate motion.
  3. Visualization: render updated particles in UniversePanel after 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

LayerResponsibility
Input and parsingLoad simulation config and validate particle initialization values.
Physics kernelCompute gravitational interactions and update kinematics.
Simulation controlAdvance global state and manage iteration rhythm.
RenderingTransform world coordinates and draw particles in Swing.