Consider the hyperplanes $\{x | P_1^T \cdot x + q_1 = 0\}$ and $\{x | P_2^T\cdot x + q_2 = 0\}$ in $\mathbb{R}^n$. Let $C \in \mathbb{R}^n$ and we want to compute te distance from $C$ to the intersection of these hyperplanes.
Solution
Let $x = C + a \cdot \frac{P_1}{\|P_1\|} + b\cdot \frac{P_2}{\|P_2\|}$ then from $$ \begin{cases} P_1^T \cdot \left( C + a \cdot \frac{P_1}{\|P_1\|} + b\cdot \frac{P_2}{\|P_2\|}\right) + q_1 = 0\\ P_2^T \cdot \left( C + a \cdot \frac{P_1}{\|P_1\|} + b\cdot \frac{P_2}{\|P_2\|}\right) + q_2 = 0 \end{cases} $$ one gets $$ \begin{bmatrix} \|P_1\| &\frac{P_1^T\cdot P_2}{\|P_1\|}\\ \frac{P_2^T\cdot P_1}{\|P_2\|} &\|P_2\|\end{bmatrix} \cdot \begin{bmatrix} a\\ b\end{bmatrix} = \begin{bmatrix} -q1 - P_1^T\cdot C\\ -q_2 - P_2^T\cdot C\end{bmatrix} $$ therefore $$ \begin{bmatrix} a\\ b\end{bmatrix} = \begin{bmatrix} \|P_1\| &\frac{P_1^T\cdot P_2}{\|P_1\|}\\ \frac{P_2^T\cdot P_1}{\|P_2\|} &\|P_2\|\end{bmatrix}^{-1} \cdot \begin{bmatrix} -q1 - P_1^T\cdot C\\ -q_2 - P_2^T\cdot C\end{bmatrix} $$ Finally one gets the distance as $\|x - C\|^2 = a^2 + b^2 + 2\cdot a\cdot b\cdot \frac{P_1^T\cdot P_2}{\|P_1\|\cdot \|P_2\|}$
Question
Is the derivation correct? I have seen in this post a solution with Lagranje multipliers, but although somehow similar at some point, not exactly as what I am doing here