# Difference between non-parallel hyperplanes

Assuming suppose we have 2 hyperplanes $$H_1, H_2$$ in $$\mathbb{R}^n$$ described parametrically by variables $$T = [t_1 ... t_n]^T$$ as:

$$H_1 = \mathcal{H}_1 T + T_{10}$$ $$H_2 = \mathcal{H}_2 T + T_{20}$$

I want to be able abstractly describe the "minimum" distance between $$H_1, H_2$$ and have some kind of method of computing it.

In the event that $$H_1, H_2$$ embed into two different parallel (n-1) dimensional hyperplanes $$P_1, P_2$$ techniques described in here apply.

But if you're in a situation of say $$2$$ skew lines, in $$\mathbb{R}^3$$ then those techniques are no longer relevant, and while the problem can be made into a convex optimization problem, I feel there should be some natural "algebraic" closed form here, that doesn't resort to modeling this is as a quadratic program.

NOTE: $$H_1, H_2$$ need not have the same dimensions. (i.e.) matrices $$\mathcal H_1, \mathcal H_2$$ can have null-space dimension anywhere from $$0$$ to $$n$$

Some work:

So I thought about this some more and come up with the following concrete answer:

Given points P,Q on the affine spaces they can be expressed as $$\mathcal{H} T_1, \mathcal{H} T_2$$ respectively.

$$D(\mathcal{H}T_1,\mathcal HT_2)^2 = (\mathcal{H}T_1 - \mathcal HT_2)^T (\mathcal{H}T_1 - \mathcal HT_2)$$

It follows that the point minimizing this distance arises from looking at

$$\frac{ \partial D}{ \partial t_i} = 0$$

w.r.t each of the $$2n$$ parameters.

This is a system of linear equations.

A concrete example below:

$$H_1 = \begin{pmatrix} 2t \\ 3t\\ t \end{pmatrix} + \begin{pmatrix} 1 \\ 2 \\ 2 \end{pmatrix}$$

$$H_2 = \begin{pmatrix} 5s \\ 2s\\ 2s \end{pmatrix} + \begin{pmatrix} 3 \\ 5 \\ 1 \end{pmatrix}$$

Our distance is given as $$D' =D(t,s)^2 =(2t+1-5s-3)^2 + (3t+2 - 2s-5)^2 + (t+2-2s-1)^2$$

So it follows the solution to the system

$$\frac{\partial D'}{\partial t}= 2(2)(2t+1-5s-3) + 2(3)(3t+2 - 2s-5) + 2(t+2-2s-1) = 0$$

$$\frac{\partial D'}{\partial s} = -2(5)(2t+1-5s-3) - 2(2)(3t+2 - 2s-5) - 2(2)(t+2-2s-1) = 0$$

Is the unique closest point.

I suspect there is some "elegant" way to express this as an inversion of familiar matrices.

• For skew lines in $\mathbb R^3$, a geometric solution involves finding a line that intersects and is orthogonal to them both. You might be able to generalize this to a pair of flats.
– amd
Feb 18, 2019 at 7:07
• Hyperplane always means a $1$ codimensional (affine) subspace. It seems you only assume $H_1,H_2$ are affine subspaces. Feb 18, 2019 at 7:39
• that is correct, affine subspace is what i meant to say Feb 18, 2019 at 7:51