I am having a hard time figuring out if a 3D point lies in a cuboid (like the one in the picture below). I found a lot of examples to check if a point lies inside a rectangle in a 2D space for example this on but none for 3D space.
I have a cuboid in 3D space. This cuboid can be of any size and can have any rotation. I can calculate the vertices $P_1$ to $P_8$ of the cuboid.
Can anyone point me in a direction on how to determine if a point lies inside the cuboid?
Best Answer
The three important directions are $u=P_1-P_2$, $v=P_1-P_4$ and $w=P_1-P_5$. They are three perpendicular edges of the rectangular box.
A point $x$ lies within the box when the three following constraints are respected:
EDIT:
If the edges are not perpendicular, you need vectors that are perpendicular to the faces of the box. Using the cross-product, you can obtain them easily:
$$u=(P_1-P_4)\times(P_1-P_5)\\ v=(P_1-P_2)\times(P_1-P_5)\\ w=(P_1-P_2)\times(P_1-P_4)$$ then check the dot-products as before.