This is a simple raycasting algorithm that is designed to work with liabru's JavaScript based rigid body physics engine, matter.js.
I created this algorithm because the current build of matter.js has raycasting, but the raycast doesn't return any collision points, only the bodies that it collides with. With this algorithm, I get the list of collided bodies and then test against each edge on the body for an intersection point and some other stuff to get more detailed information about the collision.
- body - the body that the ray has collided with (Matter.Body object)
- point - the ray's intersection point (2D Vector)
- normal - the edge collision normal (2D Vector)
- verts - the start and end points of the collided edge ( [2D Vector, 2D Vector] )
matter.js: https://github.com/liabru/matter-js/
matter.js website: http://brm.io/matter-js/