[ your browser does not support the canvas tag ]


Jeff Thompson

The collision of objects underlies most game experiences and user-interfaces. Baseball bats collide with balls, zombies bump into walls, and Mario lands on platforms and stomps turtles. Even something as simple as clicking a button (a rectangle) with your mouse (a point) is a collision.

This book explains the algorithms behind those collisions using basic shapes like circles, rectangles, and lines so you can implement them into your own projects.

UPDATE! This site has been getting lots of visits which is awesome. I've made some changes so it will look better on mobile devices, make navigation easier, and tried to look over everything for mistakes. If you have any problems or suggestions, please post an issue on the project repository. Thanks!

Ready to get started? Skip ahead to the Table of Contents...


This book covers collisions between points, circles, rectangles, lines, polygons, and triangles. These examples are meant to be as readable and easily understood as possible. There are definitely faster, more efficient ways to detect these collisions, but this book is intended to be friendly and teach the principles with minimal math.

Each section include a description of the collision algorithm and an interactive example built using processing.js. You can view the source code for all the examples (and this book!) on GitHub.

NOTE! If you're on a mobile device, the examples might not work super well for you. They are designed for mouse input, so if you're getting frustrated or your finger is in the way, try the site on a computer.


As with any book, there's a lot more useful material than could be covered here. Things that aren't discussed are mostly left out because the math gets too complicated. Three-dimensional space isn't touched on. Ellipses, which seem like they should be pretty easy, are actually very difficult.

If there's a specific collision not covered that would be helpful, please please submit an issue with a request or, better yet, submit a working example that you've built!


If you find code that doesn't run correctly, an algorithm that isn't explained quite right, or a typo, please report them at this project's GitHub repository. Thanks for your help!


OK, let's write some code! Click the link at the bottom the page, or the arrows at the top, to move to the next chapter. The Collision Detection link at the top will take you back to the Table of Contents.

NEXT: Table Of Contents