Advertisement
Guest User

Untitled

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