# vihantyagi/3dto2d_projection architecture

> Architecture diagram of the GitHub repository vihantyagi/3dto2d_projection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vihantyagi/3dto2d_projection
- Repository: https://github.com/vihantyagi/3dto2d_projection

## Overview

##### Main components
- File Loader / Parser
- Data Model & Math Engine
– Stores 3D object data structures.
– Applies rotation matrices (X, Y) and orthographic projection to yield 2D coordinates (uses NumPy).
- UI Controller / Event Handler
– Captures mouse drag events from Tkinter, decides rotation angles, passes them to Math Engine.
- 2D Renderer / View
- Application Entry Point
– `main.py` orchestrates initialization: reads files, sets up model/state, starts the Tkinter main loop.
- External Dependencies
– NumPy (matrix operations)
– Tkinter (GUI toolkit)

##### Relationships and data flows
– Application Entry Point → invokes File Loader
– File Loader → populates Data Model
– UI Controller listens to user events → computes rotation deltas → calls Math Engine
– Math Engine → transforms Data Model → returns updated 2D points
– 2D Renderer ← draws updated 2D points each frame

##### Architectural/design principles
- Separation of Concerns (MVC-like):
– Model (object data, math)
– View (render)
– Controller (UI events)
- Data Flow is unidirectional per user action: Input → Model → View
- Modularization by functionality (parsing, math, rendering, event handling)
- Use of matrix math to avoid gimbal lock
- Orthographic projection assumes infinite camera distance (no perspective)

- Loader → Model
- Controller → Math Engine → Renderer
- Renderer → Canvas (Tkinter)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Entry Point
    Main["Application Entry Point (main.py)"]:::entry

    %% Input / Loader Layer
    subgraph "Input / Loader"
        FL["File Loader / Parser"]:::loader
        Objects[(objects/)]:::storage
        Colors[(colors.csv)]:::storage
    end

    %% Model / Math Layer
    subgraph "Model / Math"
        DM["Data Model & Math Engine"]:::model
    end

    %% Controller Layer
    subgraph "Controller (UI Events)"
        UI["UI Controller / Event Handler"]:::controller
    end

    %% View / Renderer Layer
    subgraph "View / Renderer"
        View["2D Renderer / View"]:::view
    end

    %% Demo Assets
    Demo[/Demo Assets/]:::assets

    %% External Dependencies
    Dependencies((External Dependencies)):::external

    %% Connections
    Main -->|invokes| FL
    Main -->|binds events| UI
    Main -->|initializes renderer| View

    FL -->|reads files| Objects
    FL -->|reads colors| Colors
    FL -->|populates| DM

    UI -->|calculates rotation deltas| DM
    DM -->|projects to 2D coords| View
    View -->|draws on| Dependencies

    Dependencies -->|matrix ops| DM
    Dependencies -->|GUI toolkit| UI
    Dependencies -->|canvas primitives| View

    Main -->|shows demos| Demo

    %% Click Events
    click Main "https://github.com/vihantyagi/3dto2d_projection/blob/main/main.py"
    click Objects "https://github.com/vihantyagi/3dto2d_projection/tree/main/objects/"
    click Colors "https://github.com/vihantyagi/3dto2d_projection/blob/main/colors.csv"
    click Demo "https://github.com/vihantyagi/3dto2d_projection/tree/main/demo/"

    %% Styles
    classDef loader fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef model fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef controller fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef view fill:#DDA0DD,stroke:#000,stroke-width:1px;
    classDef storage fill:#f9f,stroke:#000,stroke-width:1px;
    classDef assets fill:#f0f0f0,stroke:#000,stroke-width:1px;
    classDef external fill:#cccccc,stroke:#000,stroke-width:1px;
    classDef entry fill:#ffffff,stroke:#000,stroke-width:1px;
```
