Reviewed-on: #9
Orbital Simulator
A C++ implementation of an N-body orbital simulator with high-precision calculations.
Dependencies
- C++17 compatible compiler
- CMake 3.10 or higher
- Boost library (for high-precision decimal arithmetic)
- Optional: ncurses (for terminal plotting)
Building
- Create a build directory:
mkdir build
cd build
- Configure with CMake:
cmake ..
- Build the project:
make
To enable terminal plotting with ncurses, configure with:
cmake -DENABLE_NCURSES=ON ..
Usage
The simulator can be used to simulate orbital mechanics with high precision. The main components are:
Body
: Represents a celestial body with position, velocity, and massSimulator
: Manages the simulation of multiple bodiesunits.hpp
: Contains physical constants and unit conversion utilities
Example usage:
#include "simulator.hpp"
#include "units.hpp"
int main() {
// Create bodies
std::vector<Body> bodies;
// Earth
Position earth_pos{Decimal(0), Decimal(0), Decimal(0)};
Velocity earth_vel{Decimal(0), Decimal(0), Decimal(0)};
bodies.emplace_back(earth_pos, earth_vel, EARTH_MASS, "Earth");
// Moon
Position moon_pos{AU, Decimal(0), Decimal(0)};
Velocity moon_vel{Decimal(0), MOON_ORBITAL_VELOCITY, Decimal(0)};
bodies.emplace_back(moon_pos, moon_vel, MOON_MASS, "Moon");
// Create simulator
Simulator sim(bodies, 0.1, 100, "output.txt");
// Run simulation
sim.run(1000);
return 0;
}
Features
- High-precision decimal arithmetic using Boost.Multiprecision
- N-body gravitational simulation
- Progress tracking and checkpointing
- Optional terminal visualization
- Configurable simulation parameters
License
This project is open source and available under the MIT License.
Description
Languages
Rust
28.6%
TypeScript
28.5%
Python
25.1%
Shell
10.3%
CSS
5.5%
Other
2%