๐ง Spatial Partitioning
Spatial partitioning is a technique for dividing a space into multiple sub-spaces, or partitions, to aid in the processing and management of data. It is used in a variety of applications, from collision detection to ray tracing. Here is a nice visualization of how it works (opens in a new tab).
A simple use case could be checking the distance between the player and nearby enemies in a game. If there are 100 enemies, you would have to check the distance between the player and all 100 enemies. If you divide the game world into 4 quadrants, you would only have to check the distance between the player and the enemies in the quadrant the player is in, resulting in a significant performance boost.
Here are some libraries to help you implement spatial partitioning in your projects.
2D
Quadtrees (opens in a new tab), R-trees (opens in a new tab), k-d trees (opens in a new tab) on Wikipedia
3D
Octrees (opens in a new tab) on Wikipedia
BVH
Bounding Volume Hierarchy: Wikipedia (opens in a new tab)