Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var crossLines = function(px1,px2,py1,py2,x3,x4,y3,y4){
- var x1 = Math.floor(Math.min(px1, px2)),x2 = Math.floor(Math.max(px1, px2)),y1 = Math.floor(Math.min(py1, py2)),y2 = Math.floor(Math.max(py1, py2));
- x3 = Math.floor(x3);x4 = Math.floor(x4);y3 = Math.floor(y3);y4 = Math.floor(y4);
- var dDet = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
- if (dDet == 0)
- return false;
- var uLDet = (x1 * y2 - y1 * x2);
- var dLDet = (x3 * y4 - y3 * x4);
- var Px = Math.floor((uLDet * (x3 - x4) - (x1 - x2) * dLDet) / dDet);
- var Py = Math.floor((uLDet * (y3 - y4) - (y1 - y2) * dLDet) / dDet);
- if (Px >= x1 && Px <= x2 && Py >= y1 && Py <= y2 && Px >= x3 && Px <= x4 && Py >= y3 && Py <= y4)
- return true;
- return false;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement