一种有效的方式来模拟许多粒子碰撞? [英] An efficient way to simulate many particle collisions?

查看:764
本文介绍了一种有效的方式来模拟许多粒子碰撞?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个小程序,模拟多粒子碰撞,开始先在2D(我将其扩展到3D以后),到(三维)模拟收敛对玻尔兹曼分布,也看怎么分配演变中的2D。

I would like to write a small program simulating many particle collisions, starting first in 2D (I would extend it to 3D later on), to (in 3D) simulate the convergence towards the Boltzmann distribution and also to see how the distribution evolves in 2D.

我还没有开始编程,所以请不要问code样品,这是一个应该帮我上手比较普遍的问题。这里对我来说是没有问题的背后问题的物理学,它是相当的事实,我将不得不模拟至少200-500粒,实现了pretty的不错的速度分布。我想这样做是实时的。

I have not yet started programming, so please don't ask for code samples, it is a rather general question that should help me get started. There is no problem for me with the physics behind this problem, it is rather the fact that I will have to simulate at least 200-500 particles, to achieve a pretty good speed distribution. And I would like to do that in real time.

现在,每一个时间步长,我先更新所有粒子的位置,然后检查是否有碰撞,更新新的速度向量。然而,这包括了很多checkings的,因为我会看每一个粒子经过与所有其他粒子发生碰撞。 我发现<一href="http://stackoverflow.com/questions/6811721/efficient-algorithm-for-collisions-in-2d-game">this张贴或多或少同样的问题,该方法使用也有唯一一个我能想到的。不过,我很害怕,这将不是实时很好地工作,因为这将涉及到太多的碰撞检测。

Now, for every time step, I would update first the position of all the particles and then check for collisions, to update the new velocity vector. That, however, includes a lot of checkings, since I would have to see if every single particle undergoes a collision with every other particle. I found this post to more or less the same problem and the approach used there was also the only one I can think of. I am afraid, however, that this will not work very well in real time, because it would involve too many collision checks.

所以,现在?即使这个方法将明智的工作表现(让说40FPS),有谁能够想到的办法,以避免不必要的碰撞检查

So now: Even if this approach will work performance wise (getting say 40fps), can anybody think of a way to avoid unnecessary collision checks?

我自己的想法是分手了董事会(或3D:空间)为正方形(立方体)至少有颗粒的直径尺寸和仅实现碰撞检测,如果两个粒子的中心是一个办法内网格adjecent方块...

My own idea was splitting up the board (or in 3D: space) into squares (cubes) that have dimensions at least of the diameters of the particles and implement a way of only checking for collisions if the centres of two particles are within adjecent squares in the grid...

我会很高兴地听到更多的想法,因为我想尽可能多的增加粒子的数量,因为我可以,仍然有一个实时的计算/模拟回事。

I would be happy to hear more ideas, as I would like to increase the amount of particles as much as I can and still have a real time calculation/simulation going on.

编辑:所有碰撞是完全弹性碰撞,没有任何其他力做功的颗粒。最初的情况下,我将实现由用户选择一些变量来确定选择随机起始位置和速度。

All collisions are purely elastic collisions without any other forces doing work on the particles. The initial situation I will implement to be determined by some variables chosen by the user to choose random starting positions and velocities.

EDIT2:我找到了一个好和非常有益的一篇关于粒子碰撞的此处。希望它可以帮助一些人有兴趣更深入。

I found a good and very helpful paper on the simulation of particle collision here. Hopefully it might help some People that are interested in more depth.

推荐答案

如果你想起来了,粒子移动的计划是一个真正的3D系统,其中三个维度 X 和时间( T )。

If you think of it, particles moving on a plan are really a 3D system where the three dimensions are x, y and time (t).

让我们说时间步云从 T0 T1 。对于每个粒子,可以创建一个3D线段从 P0(X0,Y0,T0) P1(X1,Y1,T1)基于当前粒子的位置,速度和方向。

Let's say a "time step" goes from t0 to t1. For each particle, you create a 3D line segment going from P0(x0, y0, t0) to P1(x1, y1, t1) based on current particle position, velocity and direction.

分区的三维空间中一个三维网格,并且每一个三维线段链接到细胞中,这跨越

Partition the 3D space in a 3D grid, and link each 3D line segments to the cells it cross.

现在,每个网格单元应进行检查。如果它连接于0或1的段,它无需进一步检查(如检查它标记)。如果它包含2个或多个细分市场,你需要检查它们之间的碰撞:计算3D碰撞点成色,缩短了两段结束在这一点上(并删除链接细胞,他们不越过了),创建两个新的细分市场,从铂打算来新计算 P1 据点粒子的新方向/速度。这些新线段添加到网格,并为选中标记细胞。添加一个线段到电网把所有的交叉单元为未选中状态。

Now, each grid cell should be checked. If it's linked to 0 or 1 segments, it need no further check (mark it as checked). If it contains 2 or more segments, you need to check for collision between them: compute the 3D collision point Pt, shorten the two segments to end at this point (and remove link to cells they doesn't cross anymore), create two new segments going from Pt to newly computed P1 points according to the new direction/velocity of particles. Add these new line segments to the grid and mark the cell as checked. Adding a line segment to the grid turn all crossed cells to unchecked state.

当没有更多选中单元网格中,你已经解决了您的时间步长。

When there is no more unchecked cells in your grid, you've resolved your time step.

修改

  • 对于3D粒子,适应上述溶液4D。
  • 在八叉树的三维空间划分网格的一个很好的形式在这种情况下,你可以冒泡检查/ unnchecked状态,快速找到需要注意的细胞。

这篇关于一种有效的方式来模拟许多粒子碰撞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆