2
$\begingroup$

in my application, I needed to detect collision between 2 3D objects. To make it simple I can represent a object as a bounding box. So actually the task reduced to detect collision between 2 boxes in 3D space. The problem that I cannot make these bounding boxes to be axis aligned. The objects look like the following image:

enter image description here

Unfortunately all the algorithms I've found in the Internet suppose that all the boxes are axis-aligned. It seems to me that this is a common mathematical problem and can be solved using some well known algorithms. Unfortunately I'm not a mathematician so I would be very grateful if someone can offer a solution to this problem.

$\endgroup$

1 Answer 1

3
$\begingroup$

Write two functions: (1) point in 3D box, and (2) segment intersect rectangle in 3D. Point in box is a conjunction of six left-of-plane checks. For (2), solve for the point of intersection between the line containing the segment and the plane containing the rectangle. Then check if that point is on the segment, and if so, in the rectangle.

Then box $B_1$ intersects box $B_2$ if any corner of $B_1$ is inside $B_2$, or if any of the $12$ edges of $B_1$ intersects any of the $6$ faces of $B_2$. This can be sped up a bit by ordering the tests (for example, if no edge of $B_1$ intersects a face of $B_2$, then you need only check one corner of $B_1$ inside/outside $B_2$).

$\endgroup$
2
  • $\begingroup$ Thanks for the response @Joseph O'Rourke. Can you please provide some link to an article or whatever like this? It's a little hard for me to figure out exactly how this should be done. $\endgroup$
    – folibis
    Commented Sep 2, 2020 at 12:40
  • $\begingroup$ @folibis: You might need to explore a bit of computational geometry. Maybe start here: How to find 3D rectangle intersection with segment?. $\endgroup$ Commented Sep 2, 2020 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.