Search code examples
collision-detection

Sweep and Prune: where does temporal coherence come in?


I am researching various collision detection algorithms, one of them being sweep and prune. I think I have a good understanding of how it works; you store a sorted list of endpoints for each axis and during each update I have to keep the list sorted. Below is the link to one of the web pages I've found that helped me understand this algorithm:

http://jitter-physics.com/wordpress/?tag=sweep-and-prune

However, I'm not too clear about how temporal coherence is being implemented in the code. I understand that it takes advantage of the fact that objects move very little in consecutive time frames, but I don't quite see how it can be implemented.

Can someone shed some light onto this situation?


Solution

  • I think I may have found the answer to my own question. Temporal coherence merely reduces the amount of work to be done for narrow phase collision detection. I was examining the code in the below link.

    http://www.koders.com/java/fidB3D3D9D154CE69A671A799D52E7C44C104DF9537.aspx?s=w.a

    I think this is where temporal coherence comes into play: when an object pair is considered for collision and it goes into narrow phase collision, the array of endpoints will be sorted. Until the endpoints need to be sorted again, there is no need to look for object pairs to be considered for narrow phase collision because the if statement at line 76 will never be true. If that's the case, then the code follows the principle of temporal coherence: in small time steps, the object configurations will change so little that it will not warrant an array sort; nothing will be rearranged in the array. Therefore the amount of narrow phase collision will be reduced.