src/index.js
function lineInt(l1,l2,precision){
    precision = precision || 0;
    var i = [0,0]; // point
    var a1, b1, c1, a2, b2, c2, det; // scalars
    a1 = l1[1][1] - l1[0][1];
    b1 = l1[0][0] - l1[1][0];
    c1 = a1 * l1[0][0] + b1 * l1[0][1];
    a2 = l2[1][1] - l2[0][1];
    b2 = l2[0][0] - l2[1][0];
    c2 = a2 * l2[0][0] + b2 * l2[0][1];
    det = a1 * b2 - a2*b1;
    if (!scalar_eq(det, 0, precision)) { // lines are not parallel
        i[0] = (b2 * c1 - b1 * c2) / det;
        i[1] = (a1 * c2 - a2 * c1) / det;
    }
    return i;
}
function lineInt(l1,l2,precision){
    precision = precision || 0;
    var i = [0,0]; // point
    var a1, b1, c1, a2, b2, c2, det; // scalars
    a1 = l1[1][1] - l1[0][1];
    b1 = l1[0][0] - l1[1][0];
    c1 = a1 * l1[0][0] + b1 * l1[0][1];
    a2 = l2[1][1] - l2[0][1];
    b2 = l2[0][0] - l2[1][0];
    c2 = a2 * l2[0][0] + b2 * l2[0][1];
    det = a1 * b2 - a2*b1;
    if (!scalar_eq(det, 0, precision)) { // lines are not parallel
        i[0] = (b2 * c1 - b1 * c2) / det;
        i[1] = (a1 * c2 - a2 * c1) / det;
    }
    return i;
}
function lineInt ( l1 , l2 , precision ) { precision = precision || 0 ; var i = [ 0 , 0 ] ; // point var a1 , b1 , c1 , a2 , b2 , c2 , det ; // scalars a1 = l1 [ 1 ] [ 1 ] - l1 [ 0 ] [ 1 ] ; b1 = l1 [ 0 ] [ 0 ] - l1 [ 1 ] [ 0 ] ; c1 = a1 * l1 [ 0 ] [ 0 ] + b1 * l1 [ 0 ] [ 1 ] ; a2 = l2 [ 1 ] [ 1 ] - l2 [ 0 ] [ 1 ] ; b2 = l2 [ 0 ] [ 0 ] - l2 [ 1 ] [ 0 ] ; c2 = a2 * l2 [ 0 ] [ 0 ] + b2 * l2 [ 0 ] [ 1 ] ; det = a1 * b2 - a2 * b1 ; if ( ! scalar_eq ( det , 0 , precision ) ) { // lines are not parallel i [ 0 ] = ( b2 * c1 - b1 * c2 ) / det ; i [ 1 ] = ( a1 * c2 - a2 * c1 ) / det ; } return i ; }
Compute the intersection between two lines.
@static
@method lineInt
@param  {Array}  l1          Line vector 1
@param  {Array}  l2          Line vector 2
@param  {Number} precision   Precision to use when checking if the lines are parallel
@return {Array}              The intersection point.
Compute the intersection between two lines .