pikaliov

bbox intersection

May 24th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. def intersects_bboxs(x1, y1, x2, y2, x11, y11, x22, y22):
  2.     """
  3.    check if bboxs is intersects
  4.  
  5.    :param x1: 1st bbox
  6.    :param y1: 1st bbox
  7.    :param x2: 1st bbox
  8.    :param y2: 1st bbox
  9.    :param x11: 2d bbox
  10.    :param y11: 2d bbox
  11.    :param x22: 2d bbox
  12.    :param y22: 2d bbox
  13.    :return: True (if intersect); False (if not)
  14.    """
  15.     x2 = x1 + x2
  16.     y2 = y1 + y2
  17.     x22 = x11 + x22
  18.     y22 = y11 + y22
  19.     s1 = (x1 >= x11 and x1 <= x22) or (x2 >= x11 and x2 <= x22)
  20.     s2 = (y1 >= y11 and y1 <= y22) or (y2 >= y11 and y2 <= y22)
  21.     s3 = (x11 >= x1 and x11 <= x2) or (x22 >= x1 and x22 <= x2)
  22.     s4 = (y11 >= y1 and y11 <= y2) or (y22 >= y1 and y22 <= y2)
  23.     return (True if ((s1 and s2) or (s3 and s4)) or ((s1 and s4) or (s3 and s2)) else False)
Advertisement
Add Comment
Please, Sign In to add comment