# Perpendicular distance from a hyperplane

Let the hyperplane equation be $$\theta^Tx + \theta_0 = 0.$$ Let p be any point. Find the signed perpendicular distance between the point and the hyperplane. (Answer in terms of $$\theta^Tx$$, $$\theta_0$$, and $$p$$; you may not answer using $$x$$)

My attempt: $$(p-x)*\theta^T*(\frac1{len\theta^T})$$ Then I distribute the $$\theta^T$$: $$p*\theta^T - x*\theta^T*(\frac1{len\theta^T})$$ The middle term can be re-written as $$\theta_0$$ from the equation we of the hyperplane.

We'll end up with $$p*\theta^T + \theta_0*(\frac1{len\theta^T})$$

(Btw, $$len\theta^T$$ is the lengths of $$\theta^T$$)

• Be very careful about the order of multiplicands. Given the original equation, $(p-x)\theta^T$ produces a matrix, not a scalar as you intend. – amd Feb 9 '19 at 1:29
• But (p - x) produces a vector and $\theta^T$ is also a vector, so the dot product of two vectors must also be a vector? Right? – BigBear Feb 9 '19 at 2:01
• The dot product of two vectors is a scalar – David M. Feb 9 '19 at 3:19
• Matrix multiplication, and this includes vectors, is not commutative. $p-x$ is an $n\times 1$ vector; $\theta^T$ is a $1\times n$ vector. $(p-x)\theta^T$ is therefore an $n\times n$ matrix. $\theta^T(p-x)$, on the other hand, is a $1\times1$ matrix—a scalar. Both appear in a standard formula for orthogonal projection, so you’d be well advised to learn the difference. – amd Feb 9 '19 at 3:46

Geometrically $$\theta$$ is a normal vector to the hyperplane $$H$$. Then we must draw a line $$l$$ from $$p$$ in the direction of $$\theta$$ and compute the distance between $$p$$ and $$q \in l\cap H$$.
Every point in $$l$$ is written as $$p+ t\theta$$ for some $$t\in \mathbb{R}$$. To find the point of intersection with $$H$$ we just set the equation $$0 = \theta^T( p + t\theta) + \theta_0 = \theta^T\cdot p + t\theta^T\cdot \theta + \theta_0$$ Solving for $$t$$ we get $$t = \frac{-\theta_0 - \theta^T\cdot p}{\|\theta\|^2}$$. Hence $$q = p + \frac{-\theta_0 - \theta^T\cdot p}{\|\theta\|^2}\theta$$ Now we head to the signed distance. We have that $$(p-q)^T\cdot \frac{\theta}{\|\theta\|} = \frac{\theta_0 + \theta^T\cdot p}{\|\theta\|}$$ Note that $$\|q-p\| = \left\| \frac{-\theta_0 - \theta^T\cdot p}{\|\theta\|^2}\theta \right\| = \frac{|\theta_0 + \theta^T\cdot p|}{\|\theta\|}$$ which is the absolute value of the signed distance.
Hi I am showing with one example. For finding the distance between Plane($$\theta$$ and $$\theta_0$$) and point $$x$$. $$D=\dfrac{||\theta x+\theta_0||}{||\theta||}$$
Signed distance=$$\dfrac{(\theta x+\theta_0)}{||\theta||}$$ Reference: http://mathworld.wolfram.com/Point-PlaneDistance.html