In my game I have 3 points that create a triangular plane similar to the image below but with uniform coordinates:
Each tringle is made of 3 points e.g.
P0 (x,y,z)
P1 (x,y,z)
P2 (x,y,z)
I also have the point:
P (x,y,z)
As shown in the diagram below, is is possible to tell if the plane created by P0, P1 & P2 passes through P?
I have looked online however all results do not seem to fit the problem in a programming orientated approach. Ideally i'd like to pass the coordinates to a function/equation and get a true/false result.
Thanks


The solution has two phases:
Find if the point belongs to the plane. The easiest way is to calculate the distance of point to the plane, by projecting along the plane normal $\mathbf{n} = {\rm UnitVector}[ \mathbf{P}_0 \times \mathbf{P}_1 + \mathbf{P}_1 \times \mathbf{P}_2 + \mathbf{P}_2 \times \mathbf{P}_0] $ $$ d= \mathbf{n} \cdot (\mathbf{P}-\mathbf{P}_0) \approx 0 $$ NOTE: here $\cdot$ is the vector dot product and $\times$ the vector cross product.
Find the barycentric coordinates of the point $w_0$, $w_1$ and $w_2$ and check if all values are between zero and one, $0 \le w_i \le 1$.
This is accomplished using a matrix $\mathcal{A}$ with columns the homogeneous coordinates of the three points $$\mathcal{A} = \left| \matrix{x_0 & x_1 & x_2 \\ y_0 & y_1 & y_2 \\ z_0 & z_1 & z_2 \\ 1 & 1 & 1 } \right| $$
The barycentric coordinates are found with the pseudo-inverse of $\pmatrix{\mathbf{P} \\ 1} = \mathcal{A} \mathbf{w}$ $$ \pmatrix{w_0 \\ w_1 \\ w_2} = \left(\mathcal{A}^\top \mathcal{A} \right)^{-1} \mathcal{A}^\top \pmatrix{x\\y\\z\\1} $$ where $\pmatrix{x&y&z&1}^\top$ are the homogeneous coordinates of the point in question.
Example:
Find normal vector $$ \mathbf{n} = \frac{ (\mathbf{P}_1-\mathbf{P}_0) \times (\mathbf{P}_2-\mathbf{P}_0)}{ \| (\mathbf{P}_1-\mathbf{P}_0) \times (\mathbf{P}_2-\mathbf{P}_0) \| } = \pmatrix{0 \\ -\frac{2}{\sqrt{5}} \\ \frac{1}{\sqrt{5}} }$$
Check that distance to plane is zero $$d = \mathbf{n} \cdot (\mathbf{P}-\mathbf{P}_1) = 0\;\checkmark$$
Build coefficient matrix $$\mathcal{A} = \left| \matrix{\mathbf{P}_0 & \mathbf{P}_1 & \mathbf{P}_2 \\ 1 & 1 & 1} \right| = \left| \matrix{1 & 5 & 2\\ 1 & 1 & 3 \\ 1 & 1 & 5 \\ 1 & 1 & 1} \right| $$
Find barycentric coordinates
$$\pmatrix{w_0 \\ w_1 \\ w_2} = \left( \left| \matrix{1 & 5 & 2\\ 1 & 1 & 3 \\ 1 & 1 & 5 \\ 1 & 1 & 1} \right|^\top \left| \matrix{1 & 5 & 2\\ 1 & 1 & 3 \\ 1 & 1 & 5 \\ 1 & 1 & 1} \right| \right)^{-1} \left| \matrix{1 & 5 & 2\\ 1 & 1 & 3 \\ 1 & 1 & 5 \\ 1 & 1 & 1} \right|^\top \pmatrix{3\\2\\3\\1} = \pmatrix{\frac{1}{8} \\ \frac{3}{8} \\ \frac{1}{2} } $$
You can find the barycentric coordinates $w_0$, $w_1$ and $w_2$ from the above system of equations after some of the linear algebra is worked out
$$ \begin{bmatrix} 1 + \mathbf{P}_0 \cdot \mathbf{P}_0 && 1 + \mathbf{P}_0 \cdot \mathbf{P}_1 && 1 + \mathbf{P}_0 \cdot \mathbf{P}_2 \\ 1 + \mathbf{P}_1 \cdot \mathbf{P}_0 && 1 + \mathbf{P}_1 \cdot \mathbf{P}_1 && 1 + \mathbf{P}_1 \cdot \mathbf{P}_2 \\ 1 + \mathbf{P}_2 \cdot \mathbf{P}_0 && 1 + \mathbf{P}_2 \cdot \mathbf{P}_1 && 1 + \mathbf{P}_2 \cdot \mathbf{P}_2 \end{bmatrix} \begin{pmatrix} w_A \\ w_B \\ w_C \end{pmatrix} = \begin{pmatrix} 1 + \mathbf{P}_0 \cdot \mathbf{P} \\ 1 + \mathbf{P}_1 \cdot \mathbf{P} \\ 1 + \mathbf{P}_2 \cdot \mathbf{P} \end{pmatrix} $$
See related answer on how to check if a point is inside a triangle in 2D.