Created
November 15, 2022 09:22
-
-
Save marmakoide/6890d920a5f6931c0f4c7548f8b6ea51 to your computer and use it in GitHub Desktop.
Check if an axis aligned bounding box intersects the segment [AB]. Box extents are half the size of the box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def aabox_segment_3d_intersecting(box_center, box_extents, A, B): | |
M = (A + B) / 2 - box_center | |
AB = B - A | |
if numpy.any(numpy.fabs(M) > box_extents + .5 * numpy.fabs(AB)): | |
return False | |
U = AB / numpy.sqrt(numpy.sum(AB ** 2)) | |
abs_U = numpy.fabs(U) | |
abs_W = numpy.fabs(numpy.cross(U, M)) | |
if abs_W[0] > box_extents[1] * abs_U[2] + box_extents[2] * abs_U[1]: | |
return False | |
if abs_W[1] > box_extents[2] * abs_U[0] + box_extents[0] * abs_U[2]: | |
return False | |
if abs_W[2] > box_extents[0] * abs_U[1] + box_extents[1] * abs_U[0]: | |
return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment