<p>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.</p>
<p>Then box <span class="math-container">$B_1$</span> intersects box <span class="math-container">$B_2$</span> if any corner of <span class="math-container">$B_1$</span> is inside <span class="math-container">$B_2$</span>, or if any of the <span class="math-container">$12$</span> edges of <span class="math-container">$B_1$</span> intersects any of the <span class="math-container">$6$</span> faces of <span class="math-container">$B_2$</span>.
This can be sped up a bit by ordering the tests (for example, if no edge of <span class="math-container">$B_1$</span> intersects a face of <span class="math-container">$B_2$</span>, then you need only check one corner of <span class="math-container">$B_1$</span> inside/outside <span class="math-container">$B_2$</span>).</p>

CC BY-SA 4.0
2020-09-02T12:40:51.230Z
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.
folibis
CC BY-SA 4.0
2020-09-02T12:43:33.507Z
@folibis: You might need to explore a bit of computational geometry. Maybe start here: [How to find 3D rectangle intersection with segment?](https://math.stackexchange.com/q/2741180/237).
Joseph O'Rourke
CC BY-SA 4.0
2020-09-02T12:23:22.900Z
2020-09-02T14:28:46.693Z
2020-09-02T14:28:46.693Z
Joseph O'Rourke
<p>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:</p>
<p><a href="https://i.sstatic.net/6uVLS.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/6uVLS.png" alt="enter image description here" /></a></p>
<p>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.</p>

<3d><computational-geometry>
Detect collision for non axis-aligned bounding boxes
folibis
# Detect collision for non axis-aligned bounding boxes

(Asked by: username_0 on 2020-09-02)

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](https://i.sstatic.net/6uVLS.png)](https://i.sstatic.net/6uVLS.png)

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.

**Tags:** 3d, computational-geometry


---

## 1 answers

### Answer by username_1 on 2020-09-02. Score: 3

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$).

> **Comments:**
> **username_0**: Thanks for the response @username_1. 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.  
> **username_1**: @username_0: You might need to explore a bit of computational geometry. Maybe start here: [How to find 3D rectangle intersection with segment?](https://math.stackexchange.com/q/2741180/237).  

---

