Skip to main content
Reordering for better intuition on the numbers
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

For each axis, compute whether the intervals spanned by the two boxes are...

  • 0 -1: separatedoverlapped (minA >< maxB or minB >& maxA > minB)

  • 1   0: adjacent (minA == maxB or minB == maxA)

  • 2+1: overlappedseparated (minA < maxB & maxA > minBmaxB or minB < maxA & maxB > minBmaxA)

Return the leastgreatest result you found on any axis.

(ie. The boxes are "overlapping" only if theytheir intervals overlap on all axesevery axis. Being "adjacent" on any axis trumps overlapped, and "separated" trumps all)

The numbers I used to label the cases are arbitrary - I picked -1,0,1 to represent the sign of the distance between the boxes: positive if separated, negative if overlapped, and exactly zero if just in contact.

For each axis, compute whether the intervals spanned by the two boxes are...

  • 0: separated (minA > maxB or minB > maxA)

  • 1: adjacent (minA == maxB or minB == maxA)

  • 2: overlapped (minA < maxB & maxA > minB or minB < maxA & maxB > minB)

Return the least result you found on any axis.

(ie. The boxes are "overlapping" only if they overlap on all axes. Being "adjacent" on any axis trumps overlapped, and "separated" trumps all)

For each axis, compute whether the intervals spanned by the two boxes are...

  •  -1: overlapped (minA < maxB & maxA > minB)

  •    0: adjacent (minA == maxB or minB == maxA)

  • +1: separated (minA > maxB or minB > maxA)

Return the greatest result you found on any axis.

(ie. The boxes are "overlapping" only if their intervals overlap on every axis. Being "adjacent" on any axis trumps overlapped, and "separated" trumps all)

The numbers I used to label the cases are arbitrary - I picked -1,0,1 to represent the sign of the distance between the boxes: positive if separated, negative if overlapped, and exactly zero if just in contact.

Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

For each axis, compute whether the intervals spanned by the two boxes are...

  • 0: separated (minA > maxB or minB > maxA)

  • 1: adjacent (minA == maxB or minB == maxA)

  • 2: overlapped (minA < maxB & maxA > minB or minB < maxA & maxB > minB)

Return the least result you found on any axis.

(ie. The boxes are "overlapping" only if they overlap on all axes. Being "adjacent" on any axis trumps overlapped, and "separated" trumps all)