{"id":24889028,"url":"https://github.com/oadultradeepfield/n-body-orbit-simulation","last_synced_at":"2025-10-16T06:30:28.938Z","repository":{"id":269908005,"uuid":"901720439","full_name":"oadultradeepfield/n-body-orbit-simulation","owner":"oadultradeepfield","description":"A C++/Go program for N-Body orbit simulations, built upon the previous 3-Body projects, with added support for spherical coordinates and collision.","archived":false,"fork":false,"pushed_at":"2025-01-25T06:13:02.000Z","size":8315,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-25T07:18:59.673Z","etag":null,"topics":["cpp","golang","gravity","python","simulation"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oadultradeepfield.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2024-12-11T07:30:35.000Z","updated_at":"2025-01-25T06:13:06.000Z","dependencies_parsed_at":"2024-12-27T05:17:20.082Z","dependency_job_id":"eccd5522-c14c-4dd2-aa93-97da1041486e","html_url":"https://github.com/oadultradeepfield/n-body-orbit-simulation","commit_stats":null,"previous_names":["oadultradeepfield/n-body-orbit-simulation"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oadultradeepfield%2Fn-body-orbit-simulation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oadultradeepfield%2Fn-body-orbit-simulation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oadultradeepfield%2Fn-body-orbit-simulation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oadultradeepfield%2Fn-body-orbit-simulation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oadultradeepfield","download_url":"https://codeload.github.com/oadultradeepfield/n-body-orbit-simulation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236684459,"owners_count":19188642,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["cpp","golang","gravity","python","simulation"],"created_at":"2025-02-01T16:16:34.425Z","updated_at":"2025-10-16T06:30:22.572Z","avatar_url":"https://github.com/oadultradeepfield.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# N-Body Orbit Simulation\n\n![C++](https://img.shields.io/badge/c++-%2300599C.svg?style=for-the-badge\u0026logo=c%2B%2B\u0026logoColor=white)\n![Python](https://img.shields.io/badge/python-3670A0?style=for-the-badge\u0026logo=python\u0026logoColor=ffdd54)\n\nThis repository builds upon my [previous work on 3-Body Simulation](https://github.com/oadultradeepfield/three-body-simulation/). While the core implementation remains unchanged, this version introduces support for both spherical and Cartesian coordinate systems in a unified configuration file. Note that the angle $\\theta$ is measured from the X-axis, while $\\phi$ is measured from the Z-axis down to the plane orthogonal to it. Additionally, it calculates changes in velocity resulting from momentum transfer during collisions, assuming elastic collisions.\n\n## Installation (Same as Previous)\n\n- Clone the repository and navigate to the project directory:\n\n  ```bash\n  git clone https://github.com/oadultradeepfield/n-body-simulation.git\n  cd n-body-simulation\n  ```\n\n- Create a build directory, generate the Makefile with CMake, and build the project:\n\n  ```bash\n  mkdir build\n  cd build\n  cmake ..\n  make\n  ```\n\n- Install Python dependencies for visualization:\n\n  ```bash\n  pip install -r python/requirements.txt\n  ```\n\n## Usage (Updated Configuration File)\n\n- Configure the simulation by editing the new unified `config.json` file. This file includes all the necessary configuration parameters for both the simulation and the bodies, as well as the coordinate system type. Example:\n\n  ```json\n  {\n    \"config\": {\n      \"G\": 6.6743e-11,\n      \"dt\": 1000,\n      \"total_time\": 3.16e7,\n      \"filename\": \"results/example_sun_earth_lagrangian_points.txt\",\n      \"collision_distance\": 1e-8\n    },\n    \"coordinates_type\": \"spherical\",\n    \"bodies\": [\n      {\n        \"_name\": \"Sun\",\n        \"mass\": 1.989e30,\n        \"position\": [0.0, 0.0, 1.5707963268],\n        \"velocity\": [0.0, 0.0, 0.0]\n      },\n      {\n        \"_name\": \"Earth\",\n        \"mass\": 5.972e24,\n        \"position\": [1.496e11, 0.0, 1.5707963268],\n        \"velocity\": [0.0, 2.9788e4, 0.0]\n      },\n      {\n        \"_name\": \"L1\",\n        \"mass\": 6500,\n        \"position\": [1.481e11, 0.0, 1.5707963268],\n        \"velocity\": [0.0, 2.9489e4, 0.0]\n      }\n    ]\n  }\n  ```\n\n  - `config.json` contains general simulation parameters like the gravitational constant `G`, time step `dt`, total time, output file, and collision distance.\n  - The `coordinates_type` specifies the coordinate system (`\"cartesian\"` or `\"spherical\"`).\n  - The `bodies` section lists the celestial bodies with their respective properties: `name`, `mass`, `position`, and `velocity`.\n  - If you are using Cartesian coordinates, make sure to input the coordinates as $x, y, z$. For spherical coordinates, use $r, \\theta, \\phi$ instead.\n  - Note that `_name` is optional; it is simply used to help guide the user when inputting multiple objects, making it easier to navigate through the configuration.\n\n- Run the simulation, specifying the coordinate system as a parameter (either `cartesian` or `spherical`):\n\n  ```bash\n  build/NBodyOrbit config.json\n  ```\n\n- Generate trajectory plots (optional):\n\n  ```bash\n  python3 python/plot.py --filename ./results/example_sun_earth_lagrangian_points.txt --N 7 --labels Sun,Earth,L1,L2,L3,L4,L5\n  ```\n\n  The output plot will be saved in the same directory as the `.txt` file.\n\n  |                               **Example 3D Trajectory**                               |                                **Example XY Projection**                                 |\n  | :-----------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------: |\n  | ![Example 3D Trajectory](/results/example_sun_earth_lagrangian_points_trajectory.png) | ![Example 2D Projection](/results/example_sun_earth_lagrangian_points_2d_projection.png) |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foadultradeepfield%2Fn-body-orbit-simulation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foadultradeepfield%2Fn-body-orbit-simulation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foadultradeepfield%2Fn-body-orbit-simulation/lists"}