如果你能满足以下条件:
0) All collisions are locally binary - that is to say
collisions only occur for pairs of particles, not triples etc,
1) you can predict the future time for a collision between
objects i and j from knowledge of their dynamics (assuming that no other
collision occurs first)
2) you know how to process the physics/dynamicseac of the collision
那么您应该能够执行以下操作:
令 Tpq 是粒子 p 和 q 之间碰撞的预测时间,而 Vp (Vq) 是保持每个粒子 p (q) 的局部动力学的结构(即它的速度、位置、弹簧常数等)
对于 n 个粒子...
Initialise by calculating all Tpq (p,q in 1..n)
Store the n^2 values of Tpq in a Priority Queue (PQ)
repeat
extract first Tpq from the PQ
Advance the time to Tpq
process the collision (i.e. update Vp and Vq according to your dynamics)
remove all Tpi, and Tiq (i in 1..n) from the PQ
// these will be invalid now as the changes in Vp, Vq means the
// previously calculated collision of p and q with any other particle
// i might occur sooner, later or not at all
recalculate new Tpi and Tiq (i in 1..n) and insert in the PQ
until done
初始设置成本为 o(n^2),但重复循环应为 O(nlogn) - 移除和替换 2n-1 个无效冲突的成本。这对于中等数量的粒子(最多数百个)是相当有效的。它的好处是您只需要在碰撞时处理事物,而不是等间隔的时间步长。这对于人口稀少的模拟来说特别有效。