Formula to project a vector onto a plane

I have a reference plane formed by 3 points in $\mathbb{R}^3$ – $A, B$ and $C$. I have a 4th point, $D$. I would like to project the vector $\vec{BD}$ onto the reference plane as well as project vector $\vec{BD}$ onto the plane orthogonal to the reference plane at vector $\vec{AB}$. Ultimately, I need the angle between $\vec{AB}$ and $\vec{BD}$ both when the vectors are projected on to the reference plane as well as the orthogonal plane. I have completed tutorials on projecting a vector onto a line in $\mathbb{R}^2$ but haven’t figured out how to translate that to $\mathbb{R}^3$…

Please note the diagram only shows the reference plane as parallel to the $xy$ plane for the sake of convenience. In my examples, the reference plane could be at any orientation. I am using 3D coordinate data from an electromagnetic motion tracker and the reference plane will be constantly moving. I understand the cross product of the two vectors $\vec{AB} \times \vec{BC}$ results in the normal vector to their plane. I have 2 different methods to calculate that but am a little lost once I get to this point. I have seen both unit vector notation and column vector notation but am confused by moving between the different styles. It would be most helpful if you could tell me the formal name of the notation/equations you use. I know the scalar equation of a plane through point $(a,b,c)$ with normal $\hat{n} = [n_1, n_2, n_3]$ is:
$$
n_1(x-a) + n_2(y-b) +n_3(z-c) = 0
$$
and the standard linear equation definition is:
$$
Ax + By + Cz = D
$$
but I could use some tips on when the equation is $=D$ and when it is $=0$ as well as any additional equations for a plane and in which circumstances the different forms are appropriate. I hope I’ve made sense here. Thanks for any help you can provide.
enter image description here

Solutions Collecting From Web of "Formula to project a vector onto a plane"

If $A$,$B$,$C$ are not on the same line, then $\vec{AB}\times \vec{BC}$ will give you the direction of your reference plane normal vector $\hat{n}_1$. I think you should know how to do the normalization so that $|\hat{n}_1|=1$

Then the projection of $\vec{BD}$ on the reference plane is $\vec{BD}-(\vec{BD}\cdot \hat{n}_1)\hat{n}_1$

Another plane $\hat{n}_2$ orthogonal to the reference plane ABC can be found as
$\vec{AB}\times\hat{n}_1$ (again you need to normalize it). Then the projection of $\vec{BD}$ on that plane can alsow be found in a similar way as shown for the first plane.

  1. Obtain the equation of the reference plane by ${\bf n}:=\vec{AB}\times\vec{AC}$, the left hand side of equation will be the scalar product ${\bf n}\cdot{\bf v}$ where $\bf v$ is the (vector from origin to the) variable point of the equation, and the right hand side is a constant, such that e.g. ${\bf v}=A$ has to satisfy it, that is, the equation will be

${\bf n}\cdot{\bf v}={\bf n}\cdot A\,$.

  • Calculate orthogonal and parallel components of $\vec{BD}$ relative to $\bf n$: we look for vectors $\vec{BD}_\perp$ and $\vec{BD}_\| $ such that $\vec{BD}=\vec{BD}_\perp+\vec{BD}_\| $, $\ \vec{BD}_\perp\ \perp\ {\bf n}$ and $\ \vec{BD}_\| \,\parallel\,{\bf n}$.
    That means, $\vec{BD}_\|=\lambda{\bf n}$ for some $\lambda\in\Bbb R$ and $\vec{BD}_\perp\cdot{\bf n}=0$. Using this and scalar multiplying by $\bf n$:
    $$\vec{BD}\cdot{\bf n}=0+\lambda\cdot{\bf n}^2$$
    this enables you to compute $\lambda$, hence $\vec{BD}_\|$ then $\vec{BD}_\perp:=\vec{BD}-\vec{BD}_\|$.
  • Do the same for the other reference plane, (one of) its normal vector will be ${\bf n}\times\vec{AB}$.
  • The angle $\varphi$ of vectors ${\bf u}$ and ${\bf v}$ can be calculated by the following formula:
    $$\cos\varphi=\frac{{\bf u}\cdot{\bf v}}{|{\bf u}|\,|{\bf v}|} \,.$$