# devyanyadav/4d-physics-sandbox architecture

> Architecture diagram of the GitHub repository devyanyadav/4d-physics-sandbox, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/devyanyadav/4d-physics-sandbox
- Repository: https://github.com/devyanyadav/4d-physics-sandbox

## Overview

This is a small interactive 4D physics sandbox. Users steer a camera and control simulation time and boundaries while the app advances charged, massive tesseracts, projects them into a 2D view, and draws the scene. The runtime is centered in main.py, with geometry, camera/rotation, projection and physics helpers. physics.py also contains a standalone integrator-comparison and energy-drift analysis. The excerpts show the main runtime calls; unsampled drawing details are kept within the main-loop component.

Main entry points: [`main.py`](https://github.com/devyanyadav/4d-physics-sandbox/blob/main/main.py) (Simulation loop), [`tesseract.py`](https://github.com/devyanyadav/4d-physics-sandbox/blob/main/tesseract.py) (Tesseract model), [`camera.py`](https://github.com/devyanyadav/4d-physics-sandbox/blob/main/camera.py) (Camera controls), [`physics.py`](https://github.com/devyanyadav/4d-physics-sandbox/blob/main/physics.py) (RK4 integrator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Sandbox runtime"]
  node_loop["Simulation loop<br/>[main.py]"]
end

subgraph group_view["4D view and geometry"]
  node_tesseract["Tesseract model<br/>[tesseract.py]"]
  node_geometry["Edges and bounds<br/>[functions.py]"]
  node_camera["Camera controls<br/>[camera.py]"]
  node_rotation["4D rotations<br/>[rotation.py]"]
  node_view_transform["View transforms<br/>[functions.py]"]
  node_projection["Projection and clipping<br/>[functions.py]"]
end

subgraph group_physics["Physics and analysis"]
  node_integrator["RK4 integrator<br/>[physics.py]"]
  node_forces["Force calculation<br/>[physics.py]"]
  node_boundaries["Wall collisions<br/>[functions.py]"]
  node_drift_analysis["Integrator analysis<br/>[physics.py]"]
end

node_user(("Sandbox user"))

node_user -->|"controls"| node_loop
node_loop -->|"creates models"| node_tesseract
node_loop -->|"builds geometry"| node_geometry
node_tesseract -->|"gets edge list"| node_geometry
node_loop -->|"updates camera"| node_camera
node_camera -->|"uses rotation matrices"| node_rotation
node_loop -->|"rotates objects"| node_rotation
node_loop -->|"transforms view"| node_view_transform
node_loop -->|"projects vertices"| node_projection
node_loop -->|"advances state"| node_integrator
node_integrator -->|"computes acceleration"| node_forces
node_loop -->|"applies walls"| node_boundaries

click node_loop "https://github.com/devyanyadav/4d-physics-sandbox/blob/main/main.py"
click node_tesseract "https://github.com/devyanyadav/4d-physics-sandbox/blob/main/tesseract.py"
click node_geometry "https://github.com/devyanyadav/4d-physics-sandbox/blob/main/functions.py"
click node_camera "https://github.com/devyanyadav/4d-physics-sandbox/blob/main/camera.py"
click node_rotation "https://github.com/devyanyadav/4d-physics-sandbox/blob/main/rotation.py"
click node_view_transform "https://github.com/devyanyadav/4d-physics-sandbox/blob/main/functions.py"
click node_projection "https://github.com/devyanyadav/4d-physics-sandbox/blob/main/functions.py"
click node_integrator "https://github.com/devyanyadav/4d-physics-sandbox/blob/main/physics.py"
click node_forces "https://github.com/devyanyadav/4d-physics-sandbox/blob/main/physics.py"
click node_boundaries "https://github.com/devyanyadav/4d-physics-sandbox/blob/main/functions.py"
click node_drift_analysis "https://github.com/devyanyadav/4d-physics-sandbox/blob/main/physics.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_loop,node_user toneBlue
class node_tesseract,node_geometry,node_camera,node_rotation,node_view_transform,node_projection toneAmber
class node_integrator,node_forces,node_boundaries,node_drift_analysis toneMint
```

## Components

### Sandbox runtime

- [Simulation loop](https://github.com/devyanyadav/4d-physics-sandbox/blob/main/main.py): `main.py`

### 4D view and geometry

- [Tesseract model](https://github.com/devyanyadav/4d-physics-sandbox/blob/main/tesseract.py): `tesseract.py`
- [Edges and bounds](https://github.com/devyanyadav/4d-physics-sandbox/blob/main/functions.py): `functions.py`
- [Camera controls](https://github.com/devyanyadav/4d-physics-sandbox/blob/main/camera.py): `camera.py`
- [4D rotations](https://github.com/devyanyadav/4d-physics-sandbox/blob/main/rotation.py): `rotation.py`
- [View transforms](https://github.com/devyanyadav/4d-physics-sandbox/blob/main/functions.py): `functions.py`
- [Projection and clipping](https://github.com/devyanyadav/4d-physics-sandbox/blob/main/functions.py): `functions.py`

### Physics and analysis

- [RK4 integrator](https://github.com/devyanyadav/4d-physics-sandbox/blob/main/physics.py): `physics.py`
- [Force calculation](https://github.com/devyanyadav/4d-physics-sandbox/blob/main/physics.py): `physics.py`
- [Wall collisions](https://github.com/devyanyadav/4d-physics-sandbox/blob/main/functions.py): `functions.py`
- [Integrator analysis](https://github.com/devyanyadav/4d-physics-sandbox/blob/main/physics.py): `physics.py`

### Other components

- **Sandbox user**

## Connections

- Sandbox user → Simulation loop: controls (evidence: `main.py`)
- Simulation loop → Tesseract model: creates models (evidence: `main.py`)
- Simulation loop → Edges and bounds: builds geometry (evidence: `main.py`)
- Tesseract model → Edges and bounds: gets edge list (evidence: `tesseract.py`)
- Simulation loop → Camera controls: updates camera (evidence: `main.py`)
- Camera controls → 4D rotations: uses rotation matrices (evidence: `camera.py`)
- Simulation loop → 4D rotations: rotates objects (evidence: `main.py`)
- Simulation loop → View transforms: transforms view (evidence: `main.py`)
- Simulation loop → Projection and clipping: projects vertices (evidence: `main.py`)
- Simulation loop → RK4 integrator: advances state (evidence: `main.py`)
- RK4 integrator → Force calculation: computes acceleration (evidence: `physics.py`)
- Simulation loop → Wall collisions: applies walls (evidence: `main.py`)
