快速nbody算法/解决方案(使用opengl/c ++/??)

pol*_*lux 5 c++ opengl performance

我正在研究一个(c ++,opengl)项目,我需要有很多影响彼此的粒子,如果我是正确的,这被称为nbody问题.有人知道这样的算法有什么解决方案.

我知道barnes hut算法,也许我可以偷看openCL,虽然我不仅仅想知道你是否可以使用其他解决方案.

我将创建的代码有很多:

for(int i = 0; i < num_particles; ++i) {
  for(int j = i+1, j < num_particles; ++j)
     dist = distance(particles[i],particles[j]);
     if(dist > limit) {....}
  }
}
Run Code Online (Sandbox Code Playgroud)

亲切的问候,Pollux

Sta*_*fan 3

Kd 树非常适合在最大距离处查找所有对象(在本例中为粒子)。如果树是平衡的,则查找是O(log n)