We show how to calculate the distance between a point and a line. We first need to look at the distance between two points. Then we can use this to determine the distance between a point and a line. Finally, we extend this to the distance between a point and a plane as well as between lines and planes.

Distance between two points

Given two points equation and equation, we subtract one vector from the other to get a vector that points from equation to equation or vice versa. We then find the distance as the length of that vector:

    equation

Distance between a point and a line

Given a point equation a line equation and want to find their distance. We first need to normalize the line vector equation (let us call it equation). Then we find a vector that points from a point on the line to the point equation and we can simply use equation. Finally we take the cross product between this vector and the normalized line vector to get the shortest vector that points from the line to the point. Now we find the distance as the length of that vector:

(1)   equation

Distance between a point and a plane

Given a point equation and a plane, the distance is easily calculated using the Hessian normal form. If the plane is not in this form, we need to transform it to the normal form first. To get the Hessian normal form, we simply need to normalize the normal vector equation (let us call it equation). We then substitute the point equation into the plane equation for equation to find the distance:

(2)   equation

If the plane is in the cartesian form, we can also use this similar equation:

    equation

Distance between a line and a plane

Given a line equation and a plane that is parallel to it, we want to find their distance. We can use a point on the line and solve the problem for the distance between a point and a plane as shown above. An obvious choice for that point would be equation.

Distance between two lines

Given two lines equation and equation, we want to find the shortest distance. There will be a point on the first line and a point on the second line that will be closest to each other. The vector that points from one to the other is perpendicular to both lines. The cross product of the line vectors will give us this vector that is perpendicular to both of them. We normalize this perpendicular vector and get a vector between two arbitrary points on each line. Then we can use the dot product to project this vector onto the normalized perpendicular vector and get the distance as the length of it.

    equation

Distance between two planes

The two planes need to be parallel to each other to calculate their distance. You can pick an arbitrary point on one plane and find the distance as the problem of the distance between a point and a plane as shown above.

For further information on the distance between a point and a line, have a look at the Wikipedia article at http://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line.