TITLE: Check if a point is inside a rectangular shaped area (3D)?
QUESTION [15 upvotes]: 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?

REPLY [8 votes]: Given $p_1,p_2,p_4,p_5$ vertices of your cuboid, and $p_v$ the point to test for intersection with the cuboid, compute:
$$\begin{matrix}
i=p_2-p_1\\ 
j=p_4-p_1\\ 
k=p_5-p_1\\
v=p_v-p_1\\
\end{matrix}$$
then, if
$$\begin{matrix}
0<v\cdot i<i\cdot i\\
0<v\cdot j<j\cdot j\\
0<v\cdot k<k\cdot k
\end{matrix}$$
The point is within the cuboid.