Finds intersection between two lines. This is JavaScript adaptation of Mukesh Prasad's work from Grapchis Gem II book. It is supposed to be very fast.
See also https://github.com/anvaka/isect a library that finds intersections in a given set of segments
var intersect = require('gintersect');
var intersection = intersect(
// first segment
-1, 1, // start
1, -1, // end
// second segment
-1, -1, // start
1, 1 // end
);
console.log(intersection);
// prints {x: 0, y: 0} - intersection point of two segmentsIf no intersection found return value is falsy:
var parallel = intersect(
// first segment
0, 1, // start
0, 2, // end
// second segment
1, 1, // start
1, 2 // end
);
console.log(parallel);
// prints null - two parallel segments do not intersect.With npm do:
npm install gintersect
MIT