Signed distance from a point to a plane (source code)

= Signed distance from a point to a plane
{title2=$s=\mathbf n\cdot\mathbf p-d$}

Orient the <plane> $\mathbf n\cdot\mathbf r=d$ with a <unit normal> $\mathbf n$. A <point> $\mathbf p$ then has <signed distance from a point to a plane>
$$
s=\mathbf n\cdot\mathbf p-d.
$$
Its <absolute value> is the ordinary <distance from a point to a plane>. The <closest point on a plane> is $\mathbf p-s\mathbf n$, so the <displacement> from the <point> to its <orthogonal projection onto a plane> is $-s\mathbf n$. Reversing the <unit normal> and $d$ reverses $s$ without changing the <plane> or the <distance from a point to a plane>. A <sphere> of <radius> $q$ centred at $\mathbf p$ has <sphere-plane intersection> radius $\sqrt{q^2-s^2}$ when $|s|<q$.

For a general, not necessarily unit, <normal vector> $\mathbf n_0$ in $\mathbf n_0\cdot\mathbf x=d_0$, the oriented distance is $(\mathbf n_0\cdot\mathbf p-d_0)/\|\mathbf n_0\|$. In the worked example of <distance from a point to a plane>, orientation toward $(2,-1,2)$ assigns $+8/3$ to $(4,1,2)$; reversing that <unit normal> assigns $-8/3$. The <closest point on a plane> and the unsigned distance are unaffected.