83 lines
1.8 KiB
Markdown
83 lines
1.8 KiB
Markdown
# 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
|
|
|
|
1. Create a build directory:
|
|
```bash
|
|
mkdir build
|
|
cd build
|
|
```
|
|
|
|
2. Configure with CMake:
|
|
```bash
|
|
cmake ..
|
|
```
|
|
|
|
3. Build the project:
|
|
```bash
|
|
make
|
|
```
|
|
|
|
To enable terminal plotting with ncurses, configure with:
|
|
```bash
|
|
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 mass
|
|
- `Simulator`: Manages the simulation of multiple bodies
|
|
- `units.hpp`: Contains physical constants and unit conversion utilities
|
|
|
|
Example usage:
|
|
|
|
```cpp
|
|
#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. |