Lessons : Collision Detection -> Polygon / Polygon (Linear Algebra)
Welcome to the collision detection linear algebra page!
In 2012, I met Warren Stokes online. He draws mazes. I had made a tilting maze game with Flash with the old trigonometry collision detection that I made in 2004, but it only worked with lines at 90 degree angles. We needed a collision detection that would work at any angle, like a pinball machine. I always thought that I would be a solid programmer if I could make a pinball game, and now was the time to do it.
So I Googled "The Intersection of Two Lines." It came up with a linear algebra formula that it called slope intersect form. That was the ticket! We were able to make the game, although it did have a rough appearance to it. It took over 300 hours to code and that's pretty big for a personal project considering how many other personal projects I have going on.
Here is the javascript implementation of my collision detection:
The linear algebra stuff is at the bottom of the collisionDetection.js script. Look for the isIntercepting() function.
Here is an example of it in action. You can drag the circles with the connecting lines. It will show you if the two lines are intersecting.
collisionDetectionIntersectionOfTwoLines.js
OK, here are the polygons! The sliding action on this javascript implementation needs to be smoother. It's got a point/point sticking going on. It's been a problem in the past and I've solved it before.
Go to the linear algebra collision detection part of my autobiography for a full expanation of how we achieve this all from the intersection of two lines.