Advertisement
vlatkovski

Check if 2 lines intersect

Jun 3rd, 2018
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. struct point {
  2.     int x;
  3.     int y;
  4. }
  5. //https://stackoverflow.com/users/14637/thomas
  6. bool isintersecting(point& p1, point& p2, point& q1, point& q2) {
  7.     return (((q1.x-p1.x)*(p2.y-p1.y) - (q1.y-p1.y)*(p2.x-p1.x))
  8.             * ((q2.x-p1.x)*(p2.y-p1.y) - (q2.y-p1.y)*(p2.x-p1.x)) < 0)
  9.             &&
  10.            (((p1.x-q1.x)*(q2.y-q1.y) - (p1.y-q1.y)*(q2.x-q1.x))
  11.             * ((p2.x-q1.x)*(q2.y-q1.y) - (p2.y-q1.y)*(q2.x-q1.x)) < 0);
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement