INTRODUCTION
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.
WHAT'S COVERED HERE?
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 these examples are intended to teach the principles with minimal math.
Each section include a description of the collision algorithm and an interactive example. You can view the source code for all the examples (and this book!) on GitHub.
WHAT'S NOT?
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 send an email with a request (or better yet, submit an example!).
ISSUES?
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!
LET'S DO IT!
OK, let's write some code! Click the arrows above to move through the book. The "Collision Detection" link at the top will take you back to the Table of Contents.