src/Collision.js
/**
 * Helper intersection function. Checks if two lines intersect.
 *
 * @param {LineSegment2} a Line A
 * @param {LineSegment2} b Line B
 * @return {Object} An object is returned with intersection point and time if they intersect, otherwise null.
 */
Helper intersection function. Checks if two lines intersect.
@param {LineSegment2} a Line A
@param {LineSegment2} b Line B
@return {Object} An object is returned with intersection point and time if they intersect, otherwise null.
Helper intersection function . Checks if two lines intersect . @param { LineSegment2 } a Line A @param { LineSegment2 } b Line B @return { Object } An object is returned with intersection point and time if they intersect otherwise null .
function IntersectLineSegments(a, b) {
    var a1 = Signed2DTriArea(a.a, a.b, b.b);
    var a2 = Signed2DTriArea(a.a, a.b, b.a);
    if (a1 * a2 < 0) {
        var a3 = Signed2DTriArea(b.a, b.b, a.a);
        var a4 = a3 + a2 - a1;
        if (a3 * a4 < 0) {
            var intersectionTime = a3 / (a3 - a4);
            var intersectionPoint = new Vec2(a.b.x, a.b.y);
            intersectionPoint.sub(a.a);
            intersectionPoint.mul(intersectionTime);
            intersectionPoint.add(a.a);
            return {intersectionPoint: intersectionPoint,intersectionTime : intersectionTime};
        }
    }
    return null;
}
function IntersectLineSegments ( a , b ) { var a1 = Signed2DTriArea ( a . a , a . b , b . b ) ; var a2 = Signed2DTriArea ( a . a , a . b , b . a ) ; if ( a1 * a2 < 0 ) { var a3 = Signed2DTriArea ( b . a , b . b , a . a ) ; var a4 = a3 + a2 - a1 ; if ( a3 * a4 < 0 ) { var intersectionTime = a3 / ( a3 - a4 ) ; var intersectionPoint = new Vec2 ( a . b . x , a . b . y ) ; intersectionPoint . sub ( a . a ) ; intersectionPoint . mul ( intersectionTime ) ; intersectionPoint . add ( a . a ) ; return { intersectionPoint : intersectionPoint , intersectionTime : intersectionTime } ; } } return null ; }
Helper intersection function.
Helper intersection function .
// intersectionPoint = a.a + intersectionTime * (a.b - a.a);