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 and , we subtract one vector from the other to get a vector that points from to or vice versa. We then find the distance as the length of that vector:

## Distance between a point and a line

Given a point a line and want to find their distance. We first need to normalize the line vector (let us call it ). Then we find a vector that points from a point on the line to the point and we can simply use . 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)

## Distance between a point and a plane

Given a point 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 (let us call it ). We then substitute the point into the plane equation for to find the distance:

(2)

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

## Distance between a line and a plane

Given a line 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 .

## Distance between two lines

Given two lines and , 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.

## 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.