Skip to content

C++ Implementation of Barnes Hut N-Body solution using OpenGL

Notifications You must be signed in to change notification settings

shutch42/BH-2D-N-Body

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Barnes-Hut 2D N-Body Solution

Summary:

This is the Barnes-Hut solution to the N-Body problem written in C++. It's much faster than my previous solution, and it renders in real-time using the freeGLUT library.

Implementation:

  • Masses are stored inside of the Body class
  • Bodies are loaded into a vector/list to represent the system of masses
  • For every time step, the position and velocity of each mass is re-calculated and overwritten in the vector of bodies
  • These calculations are estimated using an quadTree, which shortens the number of calculations by grouping masses together
  • After the position and velocity are calculated, masses are displayed using points in openGL
  • This runs infinitely, or until a mass escapes the area that the quadTree covers

Results:

1,500 Mass Simulation:

Sim

With QuadTree Displayed:

Quad

Future Improvements:

  • Add multithreading
  • Implement in 3D
  • Add controls to zoom/move around in simulation
  • Collision Handling
  • Allow quadTree to expand/collapse to simulation size, rather than keeping it a static size

About

C++ Implementation of Barnes Hut N-Body solution using OpenGL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published