Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. function crosses = crossesLine(xOld, yOld, x, y, xLine, yLine)
  2. p1=[xOld, yOld];
  3. q1 = [x,y];
  4. p2 = [xLine(1), yLine(1)];
  5. o1 = orientationMy(p1, q1, p2);
  6. o2 = orientationMy([xOld, yOld], [x,y], [xLine(2), yLine(2)]);
  7. o3 = orientationMy([xLine(1), yLine(1)], [xLine(2), yLine(2)], [xOld, yOld]);
  8. o4 = orientationMy([xLine(1), yLine(1)], [xLine(2), yLine(2)], [x, y]);
  9.  
  10. crosses = 0;
  11. if (o1 ~= o2)
  12. if(o3 ~= o4)
  13. crosses = 1;
  14. end;
  15. end;
  16.  
  17. return;
  18. end
  19.  
  20.  
  21. function ret = orientationMy(p,q,r)
  22. val = (q(2) - p(2)) * (r(1) - q(1)) - (q(1) - p(1)) * (r(2) - q(2));
  23.  
  24.  
  25. if val == 0
  26. ret = 0; %coliner
  27. else
  28. if val > 0
  29. ret = 1; %clockwise
  30. else
  31. ret = 2; %coutnerclockwise
  32. end;
  33. end;
  34.  
  35. return;
  36. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement