# Distance Between Two Lines: Formula and Examples

## TL;DR

The distance between two lines is the length of the shortest segment joining them, measured perpendicular to both. For parallel lines \( ax + by + c_1 = 0 \) and \( ax + by + c_2 = 0 \), it is \( d = \frac{|c_2 - c_1|}{\sqrt{a^2 + b^2}} \); for skew lines in 3D, it uses the cross product. This article defines both cases and works through examples.

## Why "The Distance Between Two Lines" Is Only One Number When The Lines Never Meet

The **distance between two lines** is the length of the shortest segment connecting them, and it is always measured **perpendicular** to both lines. Two lines fall into three cases: **intersecting** (distance 0), **parallel** (a constant perpendicular gap), and - in 3D only - **skew** (non-parallel lines that never meet, joined by a unique common perpendicular). This builds directly on the [distance of a point from a line](/content/math/geometry/distance-of-a-point-from-a-line/index.html); for the plane it lives in, see [coordinate geometry](/content/math/geometry/coordinate-geometry/index.html).

By the end you will identify the case, apply the right formula, and compute the distance for parallel lines in the plane and skew lines in space.

## The Parallel-Lines Formula (2D)

Two lines are **parallel** when they have the same slope and never meet. Their perpendicular distance is the same everywhere, so you can measure it at any convenient point.

Write both lines with **identical** \( a \) and \( b \) coefficients:

\[ ax + by + c_1 = 0 \quad \text{and} \quad ax + by + c_2 = 0 \]

Then the distance is:

\[ d = \frac{|c_2 - c_1|}{\sqrt{a^2 + b^2}} \]

Here \( a \) and \( b \) are the shared coefficients of \( x \) and \( y \), and \( c_1, c_2 \) are the two constants. The absolute value keeps the distance positive regardless of order.

If the lines are given in slope form \( y = mx + c_1 \) and \( y = mx + c_2 \), rewrite as \( mx - y + c_1 = 0 \), giving:

\[ d = \frac{|c_2 - c_1|}{\sqrt{m^2 + 1}} \]

## The Skew-Lines Formula (3D)

In three dimensions, two non-parallel lines that never intersect are **skew**. Write the lines in vector form:

\[ \vec{r_1} = \vec{a_1} + t \vec{b_1}, \quad \vec{r_2} = \vec{a_2} + s \vec{b_2} \]

Then:

\[ d = \frac{|(\vec{a_2} - \vec{a_1}) \cdot (\vec{b_1} \times \vec{b_2})|}{|\vec{b_1} \times \vec{b_2}|} \]

The **cross product** \( \vec{b_1} \times \vec{b_2} \) is a vector perpendicular to both lines' directions; the **dot product** in the numerator projects the gap between the lines onto that common perpendicular.

## Examples Of The Distance Between Two Lines

### Example 1

**Find the distance between \( 3x + 4y + 7 = 0 \) and \( 3x + 4y - 5 = 0 \).**

The coefficients \( a = 3, b = 4 \) match, so the lines are parallel. Thus, \( c_1 = 7, c_2 = -5 \).

\[ d = \frac{|c_2 - c_1|}{\sqrt{9 + 16}} = \frac{12}{5} = 2.4 \text{ units.} \]

### Example 2

**Find the distance between \( 2x + 4y = 5 \) and \( x + 2y = 1 \).**

These lines do not share the same coefficients. Scale the second line first:

\[ 2x + 4y = 2 \quad \text{and} \quad 2x + 4y - 5 = 0. \]

Now calculate:

\[ d = \frac{|c_2 - c_1|}{\sqrt{4 + 16}} = \frac{3}{\sqrt{20}} \approx 0.671 \text{ units.} \]

### Example 3

**Find the distance between the lines \( y=2x+3 \) and \( y=2x−4 \).**

Rewrite as \( 2x - y + 3 = 0 \) and \( 2x - y - 4 = 0 \):

\[ d = \frac{|-4 - 3|}{\sqrt{4 + 1}} = \frac{7}{\sqrt{5}} \approx 3.13 \text{ units.} \]

### Example 4

**Two lines cross at the point (1,2). What is the distance between them?**

The distance is zero. Intersecting lines share a point, so the shortest distance between them is 0.

### Example 5

**Find the distance between the skew lines \( \vec{r_1}=(0,0,0)+t(1,0,0) \) and \( \vec{r_2}=(0,1,1)+s(0,1,0) \).**

Calculating gives:

\[ d = 1 \text{ unit.} \]

### Example 6

**Are the lines with directions \( \vec{b_1}=(1,2,3) \) and \( \vec{b_2}=(2,4,6) \) skew?**

The directions are parallel. Use the parallel-distance approach.

## Conclusion

- The **distance between two lines** is the shortest, always-perpendicular segment joining them.
- Two lines are **intersecting** (distance 0), **parallel**, or **skew** (3D only).
- Always check the case first: a zero cross product means parallel, not skew.
