Daily Shaarli

All links of one day in a single page.

August 16, 2024

Sort, sweep, and prune: Collision detection algorithms ยท leanrada.com

The naive collision detection algorithm takes O(n^2) by checking pairwise intersection. To improve the performance, sort the objects by x coordinates, scan from left to right and only check intersection if a.right < b.left. This method can be extended into 2D to further eliminate the necessary comparisons. Finally, note that insertion sort is more performant on mostly sorted lists than quick sorts, so it's more suitable in this case.