This is way more intricate than it needs to be. Game coders have all these old ideas floating around like quad trees and aabb collision detection which has gotten a lot of improvements over the years (a lot of which is just conceptual improvements). I really like PBD as a good alternative to the formulation linked above: https://www.youtube.com/c/TenMinutePhysics.