{"id":25067323,"url":"https://github.com/ychaaby/octrees-barnes-hut-algorithm-simulation","last_synced_at":"2026-02-09T20:08:49.368Z","repository":{"id":263862621,"uuid":"722750618","full_name":"yChaaby/Octrees-Barnes-Hut-Algorithm-Simulation","owner":"yChaaby","description":"Octree data structure implimentation using python, 3D simulation with Matplotlib","archived":false,"fork":false,"pushed_at":"2025-01-21T23:23:21.000Z","size":51180,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-09T20:39:35.922Z","etag":null,"topics":["data-structures-and-algorithms","matplotlib","octtree","oop","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yChaaby.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-23T21:30:27.000Z","updated_at":"2025-02-16T23:15:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"bdc47950-7d04-4ca2-ab8a-a02c0afa865f","html_url":"https://github.com/yChaaby/Octrees-Barnes-Hut-Algorithm-Simulation","commit_stats":null,"previous_names":["ychaaby/octrees_similation"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yChaaby/Octrees-Barnes-Hut-Algorithm-Simulation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yChaaby%2FOctrees-Barnes-Hut-Algorithm-Simulation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yChaaby%2FOctrees-Barnes-Hut-Algorithm-Simulation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yChaaby%2FOctrees-Barnes-Hut-Algorithm-Simulation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yChaaby%2FOctrees-Barnes-Hut-Algorithm-Simulation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yChaaby","download_url":"https://codeload.github.com/yChaaby/Octrees-Barnes-Hut-Algorithm-Simulation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yChaaby%2FOctrees-Barnes-Hut-Algorithm-Simulation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29279342,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-09T19:05:41.198Z","status":"ssl_error","status_checked_at":"2026-02-09T19:05:37.449Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-structures-and-algorithms","matplotlib","octtree","oop","python"],"created_at":"2025-02-06T20:55:27.712Z","updated_at":"2026-02-09T20:08:49.339Z","avatar_url":"https://github.com/yChaaby.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Octree Simulation with Barnes-Hut Algorithm\n\n## Overview\n\nThis project implements the **Barnes-Hut algorithm** for simulating gravitational interactions in a system of stars using an **octree** data structure. The algorithm efficiently calculates the gravitational forces between particles by approximating distant interactions, reducing the computational complexity from **O(N^2)** to **O(N log N)**. \n\nThis simulation calculates accelerations and gravitational forces and visualizes the system in 3D using **Matplotlib**. The Barnes-Hut algorithm is widely used in astrophysics and particle simulations for its scalability and efficiency when dealing with large systems.\n\n### 3D Simulation Demo\n\n\n![Simulation Demo](images/image1.png)\n\n\n![Octree Structure](images/image2.png)\n\n\n![Gravitational Forces](images/image3.png)\n\n\n## Features\n\n- **Octree** data structure to partition space and optimize calculations.\n- **Barnes-Hut algorithm** to calculate gravitational forces and accelerations efficiently.\n- **3D visualization** of the simulation using Matplotlib.\n\n## Mathematical Formulas\n\nThe simulation uses fundamental principles of gravitational forces and accelerations to model the motion of stars.\n\n### 1. Gravitational Force\n\nThe gravitational force between two stars is given by **Newton's law of universal gravitation**:\n\n`F = G * (m_1 * m_2) / r^2`\n\nWhere:\n- `F` is the gravitational force between two stars.\n- `G` is the gravitational constant.\n- `m_1` and `m_2` are the masses of the two stars.\n- `r` is the distance between the two stars.\n\n### 2. Acceleration Due to Gravity\n\nThe acceleration `a` experienced by a star due to gravitational force is calculated using Newton's second law:\n\n`a = F / m`\n\nWhere:\n- `F` is the gravitational force calculated above.\n- `m` is the mass of the star.\n\n### 3. Barnes-Hut Approximation\n\nThe Barnes-Hut algorithm approximates the gravitational interaction between distant stars using a single \"center of mass\" for groups of stars. The force calculation is simplified based on a **theta** parameter, which controls the threshold for approximating distant interactions:\n\n`theta = s / d`\n\nWhere:\n- `s` is the size of the octant (or group of stars).\n- `d` is the distance between the center of mass of the octant and the star.\n\nIf `theta` is smaller than a given threshold, the octant is approximated as a single mass, and the force is calculated directly. Otherwise, the interaction is recursively computed with the children of the octree.\n\n\n## Usage\n\nTo run the simulation, simply execute the Python script:\n\n\n## Requirements\n\n- Python 3\n- OPP Concepts\n- Matplotlib\n- NumPy\n\n## Installation\n\n1. Clone the repository:\n    ```shell\n    git clone https://github.com/yChaaby/Octrees_Similation.git\n    ```\n\n2. Install required dependencies:\n    ```fish\n    pip install matplotlib numpy\n    ```\n\n## Usage\n\n1. To run the simulation:\n    ```powershell\n    python simulation.py\n    ```\n\n2. The simulation will display a 3D visualization of the stars and their interactions.\n\n## License\nNone ... it's all yours\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fychaaby%2Foctrees-barnes-hut-algorithm-simulation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fychaaby%2Foctrees-barnes-hut-algorithm-simulation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fychaaby%2Foctrees-barnes-hut-algorithm-simulation/lists"}