Check if a point is inside a rectangular shaped area (3D)?

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:

  • The dot product $u.x$ is between $u.P_1$ and $u.P_2$
  • The dot product $v.x$ is between $v.P_1$ and $v.P_4$
  • The dot product $w.x$ is between $w.P_1$ and $w.P_5$

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.


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.