Distance from point to plane

Here’s a quick sketch of how to calculate the distance from a point P = (x1,y1,z1) to a plane determined by normal vector N = (A,B,C) and point Q = (x0,y0,z0).

The equation for this plane is A(x-x0) + B(y -y0) + C(z -z0) = 0. (Or we might write the equation as Ax + By + Cz + D = 0, where D = -Ax0 -By0 -Cz0.) In the below CVT, I’ve drawn P in red and Q in yellow. To simplify the figure, I’ve fixed the plane. Although you can move Q around, it is confined to lie in the plane.

To calculate the distance from point P to the plane, I’ve dropped a perpendicular from the point P to the plane, drawing it as a gray line. The point R where the perpendicular hits the plane is drawn in green. R is the point on the plane closest to P. Hence the distance from P to the plane is the distance from P to R, or the length of the gray line. (You cannot move R directly by dragging on it, as its position is determined by P. It will move as you move P.)

Next, we calculate an expression for a unit normal vector, i.e., a normal vector of length one. It is simply N divided by its length. We’ll use the notation n for the unit normal vector:

n = -N---
||N || = √--(A,B,-C-)----
  A2 + B2 + C2.
I’ve draw this unit normal vector n in green, shifted so its tail is fixed at the point R. (In this case, I haven’t drawn a ball at the end of n so the figure doesn’t get too cluttered.) The unit normal vector n looks short because I’ve draw the figure so that the x, y, and z axes each extend from -5 to 5.

Let v be the vector from Q to P (shown in blue). Since P = (x1,y1,z1) and Q = (x0,y0,z0), we calculate that v = (x1 -x0,y1 -y0,z1 -z0). The length of the gray line, i.e., the distance from P to the plane, is simply the length of the projection of v onto the unit normal vector n. Since n is length one, this distance is simply the absolute value of v n. We’ll label the distance d; it is

d = |v n|
= |(x1 - x0,y1 - y0,z1 - z0) n|
= |A (x  - x ) + B (y  - y ) + C (z  - z )|
----1----0-√------1---0--------1---0--
             A2 + B2  + C2. (1)
This distance is shown on the cyan slider labeled by d to the right of the figure.

Recall that we can also write the equation for the plane as Ax + By + Cz + D = 0, with D = -Ax0 -By0 -Cz0. We’ll substitute into the above formula, to arrive at the following expression for the distance from P = (x1,y1,z1) to the plane Ax + By + Cz + D = 0:

d = |Ax1  + By1 +  Cz1 + D |
---√---2-----2----2----
     A  +  B  + C. (2)
From this final formula, you can see that the distance didn’t depend on the point Q = (x0,y0,z0). As long as Q is in the plane Ax + By + Cz + D = 0, then we know that D = -Ax0 -By0 -Cz0. So, formula (1) is equivalent to formula (2) no matter where in the plane Q is. It’s clear from the figure how the distance d shouldn’t change as you move Q around in the plane. The vector v changes, but its projection onto n is constant.