Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. function orient(x1, y1, x2, y2, x3, y3){
  2. return x2*y3 + x1*y2 + y1*x3 - y1*x2 - y2*x3 - y3*x1;
  3. }
  4.  
  5.  
  6. function areIntersecting(x1, y1, x2, y2, x3, y3, x4, y4){
  7. let o1 = orient(x1, y1, x3, y3, x4, y4);
  8. let o2 = orient(x2, y2, x3, y3, x4, y4);
  9. let o3 = orient(x3, y3, x1, y1, x2, y2);
  10. let o4 = orient(x4, y4, x1, y1, x2, y2);
  11. if (o1==0 || o2==0 || o3==0 || o4==0){return 0;}
  12. return ((o1>0)^(o2>0)) && ((o3>0)^(o4>0));
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement