Writing collision detection is really fun. There’s enough in this article to take it and then build a tiny rigid body physics simulation - you only need to add gravity and then work out the forces two rectangles impart on each other when they collide. There’s a change to the center of mass velocity and a change to the rotation velocity.<p>One thing that makes it easier IMO is to use Y-up coordinates. Instead of putting the origin top-left like the article, use bottom-left. If you need, convert screen coordinates to your “world space” and back in some code that is outside of the collision & simulation. There’s no reason to be stuck with the default coordinates, or have to think upside down. (Intersection when “top bound of R1 is less than bottom bound of R2” sounds backwards to me.)<p>Another fun part is accelerating collision detection / simulation. This algorithm in the demo code is O(n^2) in total edges, I believe. But you don’t need to change the algorithm necessarily, you can speed it up dramatically with an acceleration structure of some kind. It’s a fun weekend project and satisfying to suddenly be able to add thousands of polygons to your sim without locking up the machine.