function intersects(ax, ay, aax, aay, bx, by, bbx, bby){
var sax = aax - ax;
var say = aay - ay;
var sbx = bbx - bx;
var sby = bby - by;
var s = (-say * (ax - bx) + sax * (ay - by)) / (-sbx * say + sax * sby);
var t = ( sbx * (ay - by) - sby * (ax - bx)) / (-sbx * say + sax * sby);
if (s >= 0 && s <= 1 && t >= 0 && t <= 1) {
var x = ax + (t*sax);
var y = ay + (t*say);
return {x:x, y:y};
}
// not intersecting
return null;
}