3D Distance Formula

Last Updated : 31 Aug, 2026

The distance formula in 3D calculates the distance between two points, a point and a line, or a point and a plane in three-dimensional coordinates.

  • 3D geometry comes into the picture to model real-world quantities such as velocity, fluid flows, electrical signals, and many others.
  • Deals with points represented using three coordinate axes, namely x, y, and z, which are mutually perpendicular.

Distance Between Two Points in 3D

For two points A(x1, y1, z1) and B(x2, y2, z2) located in three-dimensional space, the 3D distance formula is given as

3d-distance-formula
Measuring Distance in 3D Space

In the case of origin, one of the points will be O(0, 0, 0), and hence we will use x1 = 0, y1 = 0, and z1 = 0 in the formula to calculate the distance.

Example: Calculate the distance between two points P(2, 5, 6) and Q(3, 4, 7).

Answer:

For point P, x1 = 2, y1 = 5, z1 = 6

For point Q, x2 = 3, y2 = 4, z2 = 7

Distance between P and Q is given as: PQ = √[(x2 - x1)2 + (y2 - y1)2 + (z2 - z1)2]

Now filling the values of coordinates in the above formula we get

PQ = √[(3 - 2)2 + (4 - 5)2 + (7 - 6)2]

⇒ PQ = √(1 + 1 + 1) = √3 units

Distance Between a Point and Origin in 3D

Like a 2D system, we can also calculate the distance between a point and the origin. In a 3D system, the coordinate of the origin is given as O(0, 0, 0). Hence, for calculating distance from the origin, we can take the coordinates of the origin as (0, 0, 0) and the point as (x, y, z). It does not matter which point we label as P or Q in the formula; the result remains the same.

The distance formula to calculate the distance between a point and origin in 3D is given in the image attached below:

2
Distance from the origin in 3D

Example: Calculate the distance between P(-1, 2, 4) and origin O.

Solution:

We know that the coordinates of the origin are O(0, 0, 0)

Hence, the Distance between origin O(0, 0, 0) and P(-1, 2, 4) is given as

OP = √(x2 + y2 + z2)

⇒ OP = √{(-1)2 + 22 + 42}

⇒ OP = √{1 + 4 + 16} = √21 units

Derivation of 3D Distance Formula Between Two Points

Distance-between-two-points-in-3d

Let there be two points P(x1, y1, z1) and Q(x2, y2, z2) in three-dimensional space, lying on rectangular axes. Through points P and Q, draw planes parallel to the coordinate plane. Thus, we get a rectangular parallelepiped in which PQ is a body diagonal.

Consider Point A adjacent to Q such that AP is a face diagonal. Now, AP is along one of the coordinate axes; hence, AP is perpendicular to AQ.

Using the Pythagorean Theorem

PQ2 = AP2 + AQ2 ... (i)

Now take a point M adjacent to P and A such that MQ is a body diagonal

AP2 = AM2 + PM2 ... (ii)

Putting the values of AP2 from (ii) to (i)

⇒ PQ2 = AM2 + PM2 + AQ2

PM = x2 - x1

AQ = y2 - y1

AM = z2 - z1

Hence, PQ2 = (x₂ - x₁)2 + (y₂ - y₁) + (z₂ - z₁)2

Hence, if PQ = d

Then distance formula between two points in 3D is given as

d2 = (x2 - x1)2 + (y2 - y1)2 + (z2 - z1)2

⇒ d = √[(x2 - x1)2 + (y2 - y1)2 + (z2 - z1)2]

If the distance is measured from the origin, then the 3D distance formula is given as

d = \sqrt{x^2 + y^2 + z^2}

Example 1: Find the distance between the points P (1, –3, 4) and Q (–4, 1, 2).

Solution:

Using the formula to calculate the distance between point P and Q, 

Distance (d) = √[(x2 - x1)2 + (y2 - y1)2 + (z2 - z1)2]

d = √[(-4-1)2+(1+3)2+(2-4)2] = √(25 + 16 + 4) = √45 units

Example 2: Show that the points P (–2, 3, 5), Q (1, 2, 3), and R (7, 0, –1) are collinear.

Solution:

We know that points are said to be collinear if they lie on a line.

 PQ = √{(1+2)2 + (2-3)2 + (3-5)2} = √{9+1+4} = √14 units

QR = √{(7-1)2 + (0-2)2+(-1-3)2} = √{36+4+16} = √56 = 2√14

PR = √{(7+2)2 + (0-3)2 + (-1-5)2} = √{81+9+36} = √126 = 3√14

As PQ + QR = PR  

Hence P, Q, and R are collinear.

Distance of Point From a Line

The distance of a point from a line is the perpendicular distance from the point to the line.

Suppose we have to find the distance of a point P(x₀, y₀, z₀) from line l; then the formula is,

Distance (d) = \frac{ \left|\overline{P_{0}P_{1}} \times  \overline{s} \right| }{ |\overline{s}| }

Where 's' is the directing vector of line l.

Example: Find the distance from point P(-6, 1, 21) to a line \frac{x+4}{3}=\frac{y+5}{1}=\frac{z+1}{1} ?

Solution:

Let Line L : \frac{(x+4)}3 = \frac{(y+5)}1 = \frac{(z+1)}1 = t

P(-6, 1, 21) and P'(3t-4, t-5, t-1)

\overline{PP'} = \begin{vmatrix}{3t-4-(-6)} \\ {t-5-1} \\ {t-1-21}\end{vmatrix}  

\overline{PP'} = \begin{vmatrix}{3t+2} \\ {t-6} \\ {t-22}\end{vmatrix}

Now, \overline{PP'}* \overline{s}  = 0 ,

\begin{vmatrix}{3t+2} \\ {t-6} \\ {t-22}\end{vmatrix} . \begin{vmatrix}{3} \\ {1} \\ {1}\end{vmatrix} = 0

⇒ 9t + 6+t -6+t-22 = 0, 11t - 22=0 and t=2

\overline{PP'} = \begin{vmatrix}{3(2)+2} \\ {(2)-6} \\ {(2)-22}\end{vmatrix}

\overline{PP'} = \begin{vmatrix}{8} \\ {-4} \\ {-20}\end{vmatrix}

\overline{PP'} = 4\begin{vmatrix}{2} \\ {-1} \\ {-5}\end{vmatrix}

⇒ d = |\overline{PP'}|= 4 \sqrt{4+1+25} = 4 \sqrt{30}

Distance of a Point from a Plane

The distance from a point to a plane is the perpendicular distance from a point on a plane.

3
Distance of a point from a plane

If Qx + Ry + Sz + T = 0 is a plane equation, then the distance from point P(Px, Py, Pz) to the plane can be found using the following formula:

Distance (d) = \frac{ \left|Q\cdot P_x+R\cdot P_y+S\cdot P_z+T\right| }{ \sqrt{Q^2+R^2+S^2} }

Example: Find the distance between plane 2x + 4y - 4z - 6 = 0 and point P(0, 3, 6).

Solution:

Using the formula: 

Distance (d) = \frac{ |2(0) + 4(3) + (-4)(6) + (-6)| }{ \sqrt{4^2+2^2+(-4^2)} }

⇒ d = \frac{ |0 + 12 - 24 - 6| }{ \sqrt{16+4+16} }

⇒ d = \frac{ |-18| }{ \sqrt{36} }

⇒ d = \frac{18}{ {6} } = 3

Distance Between Parallel Lines

The distance between any two parallel lines is the perpendicular distance from any point on one line to the other line.

4
Distance between two parallel lines

Suppose there are two parallel lines y = mx + c1 and y = mx + c2; then the formula is,

Distance (d) = \frac{|c_2-c_1|}{ \sqrt{1+m^2} }

If the equations of two parallel lines are given as

ax + by + d1 = 0 and ax + by + d2 = 0, then the formula is,

Distance (d) = \frac{|d_2-d_1|}{ \sqrt{a^2+b^2} }

Where a and b are the coefficients of variables x and y in the line.

Example 1: Find the distance between parallel lines y = 2x + 10 and y = 2x + 12.

Solution:

The lines y = 2x + 10 and y = 2x + 12 are in form y = mx + c.

Where c1​ = 10, c2 ​= 12, m = 2 

Using formula, the distance (d) =  |12-10|/√(1 + 22) = 2/√5

Example 2: Find the distance between two parallel lines 4x + 3y + 6 = 0 and 4x + 3y - 3 = 0

Solution:

The lines given are 4x + 3y + 6 = 0 and 4x + 3y - 3 = 0. Both lines are in the form ax + by + d = 0.

Hence, d1 ​= 6, d2 ​= −3, a = 4, b = 3 

Using the formula for this case, distance (d) will be calculated as:

⇒ d = \frac{|d2-d1|}{ \sqrt{a^2+b^2} }

⇒ d = \frac{|-3-6|}{ \sqrt{4^2+3^2} }

⇒ d = |-9|/√(16 + 9)

⇒ d = 9/√25

⇒ d = 9/5

Comment

Explore