Mathematics

Distance Formula: 2D/3D

The distance formula calculates the straight-line distance between two points in coordinate space. In two dimensions, points (x₁, y₁) and (x₂, y₂) are separated by d = √[(x₂ − x₁)² + (y₂ − y₁)²]. In three dimensions, a third coordinate difference is added: d = √[(x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²]. Both formulas come directly from the Pythagorean theorem. Squaring the coordinate differences removes their signs, adding them combines perpendicular displacement components, and the square root converts the squared distance back to an ordinary length. The distance formula works regardless of which point is labeled first because reversing both coordinate differences changes their signs but not their squares. It is used throughout coordinate geometry, circles, lines, vectors, solid geometry, and practical position calculations.

2D Distance Formula

For points:

P₁ = (x₁, y₁)

and:

P₂ = (x₂, y₂)

the 2D distance formula is:

d = √[(x₂ − x₁)² + (y₂ − y₁)²]

where:

d = straight-line distance

The formula measures Euclidean distance: the shortest straight-line path between the two points in the plane.

It is one of the central coordinate relationships in Geometry & Trigonometry.

Basic 2D Distance Example

Find the distance between:

A = (1, 2)

and:

B = (5, 5)

Calculate coordinate changes:

Δx = 5 − 1 = 4

Δy = 5 − 2 = 3

Then:

d = √(4² + 3²)

= √(16 + 9)

= √25

Therefore:

d = 5

The points are 5 units apart.

Why the Distance Formula Works

Plot two points and draw horizontal and vertical segments connecting their coordinate levels.

These components create a right triangle.

Its horizontal leg has length:

|x₂ − x₁|

Its vertical leg has length:

|y₂ − y₁|

The segment connecting the original points is the hypotenuse.

Using the Pythagorean Theorem:

a² + b² = c²

gives:

(x₂ − x₁)² + (y₂ − y₁)² = d²

Taking the nonnegative square root:

d = √[(x₂ − x₁)² + (y₂ − y₁)²]

Why Absolute Values Are Not Required

The horizontal distance is technically:

|x₂ − x₁|

and the vertical distance is:

|y₂ − y₁|

But once these values are squared:

|x₂ − x₁|² = (x₂ − x₁)²

So the absolute-value symbols are unnecessary inside the distance formula.

For example:

(2 − 7)² = (−5)² = 25

and:

(7 − 2)² = 5² = 25

Either subtraction order produces the same squared contribution.

Point Order Does Not Change Distance

For points A and B:

distance(A, B) = distance(B, A)

Suppose:

A = (−2, 3)

B = (4, 8)

Using B − A:

d = √[(4 + 2)² + (8 − 3)²]

= √(36 + 25)

= √61

Using A − B:

d = √[(−2 − 4)² + (3 − 8)²]

= √(36 + 25)

= √61

Distance is symmetric.

Example With Negative Coordinates

Find the distance between:

P = (−3, −2)

and:

Q = (4, 4)

Coordinate differences:

Δx = 4 − (−3) = 7

Δy = 4 − (−2) = 6

Therefore:

d = √(7² + 6²)

= √(49 + 36)

= √85

Approximately:

d ≈ 9.22

Parentheses are particularly important when subtracting negative coordinates.

Horizontal Distance

If two points have the same y-coordinate:

y₁ = y₂

then:

y₂ − y₁ = 0

The distance formula becomes:

d = √[(x₂ − x₁)²]

so:

d = |x₂ − x₁|

For:

(2, 5)

and:

(11, 5)

the distance is:

|11 − 2| = 9

Vertical Distance

If two points have the same x-coordinate:

x₁ = x₂

then:

x₂ − x₁ = 0

Therefore:

d = |y₂ − y₁|

For:

(4, −3)

and:

(4, 8)

the distance is:

|8 − (−3)|

= 11

The full formula automatically reduces to this simpler result.

Distance From the Origin

The origin is:

O = (0, 0)

For a point:

P = (x, y)

the distance from the origin is:

d = √[(x − 0)² + (y − 0)²]

Therefore:

d = √(x² + y²)

For:

P = (6, 8)

we get:

d = √(36 + 64)

= 10

This relationship appears repeatedly in circle and vector geometry.

3D Distance Formula

For points:

P₁ = (x₁, y₁, z₁)

and:

P₂ = (x₂, y₂, z₂)

the 3D distance formula is:

d = √[(x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²]

The third term accounts for displacement along the z-axis.

Like the 2D formula, it measures straight-line Euclidean distance.

Basic 3D Example

Find the distance between:

A = (1, 2, 3)

and:

B = (5, 5, 15)

Coordinate changes:

Δx = 4

Δy = 3

Δz = 12

Therefore:

d = √(4² + 3² + 12²)

= √(16 + 9 + 144)

= √169

Thus:

d = 13

Why the 3D Formula Works

First combine two perpendicular components:

√[(Δx)² + (Δy)²]

This gives the planar displacement.

That planar displacement is perpendicular to the z-direction.

Apply the Pythagorean theorem again:

d² = [(Δx)² + (Δy)²] + (Δz)²

Therefore:

d = √[(Δx)² + (Δy)² + (Δz)²]

Three-dimensional distance is therefore a direct extension of the 2D formula.

Distance From the 3D Origin

For:

P = (x, y, z)

and origin:

O = (0, 0, 0)

the distance is:

d = √(x² + y² + z²)

For:

P = (2, 3, 6)

we get:

d = √(4 + 9 + 36)

= √49

= 7

This is also the magnitude formula for a three-dimensional position vector.

Distance Formula and Vector Magnitude

The displacement from:

A = (x₁, y₁)

to:

B = (x₂, y₂)

can be represented as a vector:

v = (x₂ − x₁, y₂ − y₁)

Its Vector Magnitude is:

|v| = √[(x₂ − x₁)² + (y₂ − y₁)²]

Therefore:

distance(A, B) = |BA|

The distance formula and vector magnitude are the same Euclidean length relationship expressed in different contexts.

Distance Formula and Vector Operations

Vector Operations provide a compact way to generalize distance.

For position vectors p and q:

d = |qp|

In n dimensions:

d = √[(q₁ − p₁)² + (q₂ − p₂)² + … + (qₙ − pₙ)²]

Thus the familiar 2D and 3D formulas are special cases of a broader vector-space definition.

Distance and the Midpoint Formula

The Midpoint Formula finds the point halfway between two endpoints:

M = ((x₁ + x₂)/2, (y₁ + y₂)/2)

If M is truly the midpoint, then:

distance(A, M) = distance(M, B)

For:

A = (0, 0)

B = (6, 8)

the midpoint is:

M = (3, 4)

Then:

AM = √(3² + 4²) = 5

and:

MB = √(3² + 4²) = 5

while:

AB = 10

Distance and Slope

The Slope between two points is:

m = (y₂ − y₁)/(x₂ − x₁)

Slope measures direction as rise over run.

Distance measures total straight-line length:

d = √[(run)² + (rise)²]

The two quantities therefore use the same coordinate changes for different purposes.

For:

Δx = 4

Δy = 3

slope is:

3/4

while distance is:

5

Distance and a Line Through Two Points

When constructing a Line From Two Points, coordinate differences determine slope and the distance formula determines the segment length between the chosen points.

For:

A = (2, 1)

B = (8, 9)

we have:

slope = 8/6 = 4/3

and:

distance = √(6² + 8²)

= 10

The line extends infinitely, while the distance refers only to the segment joining A and B.

Distance and Point-Slope Form

The Point-Slope Form equation:

y − y₁ = m(x − x₁)

uses one point and slope to describe an entire line.

If a second point on that line is known, the distance formula can measure the finite segment between them.

These concepts are related but distinct:

slope → direction

distance → length

line equation → entire set of collinear points

Distance and Circle Equations

A Circle Equation is built directly from the distance formula.

A circle centered at:

(h, k)

contains every point:

(x, y)

whose distance from the center is r.

Therefore:

√[(x − h)² + (y − k)²] = r

Square both sides:

(x − h)² + (y − k)² = r²

So the standard circle equation is simply a fixed-distance condition.

Circle Radius From Two Points

Suppose a circle has center:

C = (2, −1)

and passes through:

P = (7, 11)

The radius is:

r = √[(7 − 2)² + (11 + 1)²]

= √(25 + 144)

= 13

Therefore the circle equation is:

(x − 2)² + (y + 1)² = 169

Diameter From Coordinate Endpoints

Suppose the endpoints of a diameter are:

A = (−2, 1)

B = (4, 9)

Then:

d = √[(4 + 2)² + (9 − 1)²]

= √(36 + 64)

= 10

So the radius is:

r = 5

The circle’s Circle Area is:

A = 25π

and circumference is:

C = 10π

Distance and Chord Length

If the endpoints of a circle chord are known in coordinates, Chord Length can be found directly with the distance formula.

Suppose:

A = (−4, 3)

B = (4, 3)

Then:

c = √[(4 − (−4))² + (3 − 3)²]

= √64

= 8

This agrees with the circle-specific chord geometry if the center and radius are also known.

Distance From Center to Chord

Suppose a circle has radius:

r = 13

and a chord lies perpendicular distance:

d = 5

from the center.

The chord formula uses:

c = 2√(r² − d²)

This is itself derived from the Pythagorean distance relationship.

Thus the distance formula underlies many specialized circle formulas even when coordinates are not explicitly shown.

Distance Between Opposite Corners of a Rectangle

For a rectangle of width w and height h, the diagonal is:

d = √(w² + h²)

This is the distance formula with coordinate changes:

Δx = w

Δy = h

For:

w = 6

h = 8

we get:

d = 10

The rectangle can be positioned anywhere in the coordinate plane without changing this diagonal length.

Distance in an Axial Cylinder Cross Section

A plane through the axis of a cylinder creates a rectangle with dimensions:

2r

and:

h

Its diagonal is:

d = √[(2r)² + h²]

This relationship can supply a missing dimension before calculating Cylinder Volume or Cylinder Surface Area.

Cylinder Example

Suppose an axial cylinder cross section has:

diagonal = 13

height = 5

Then:

(2r)² + 5² = 13²

(2r)² = 144

2r = 12

Therefore:

r = 6

Cylinder volume becomes:

V = π(6²)(5)

= 180π

The distance relationship identifies the radius before the solid formula is applied.

Distance in Cone Geometry

An axial cross section of a right circular cone produces right triangles with legs:

r

and:

h

and hypotenuse:

Therefore:

ℓ = √(r² + h²)

This is again a 2D distance formula.

The slant height ℓ can then be used in Cone Surface Area, while r and h determine Cone Volume.

Distance in Frustum Geometry

A right conical frustum has:

larger radius R

smaller radius r

vertical height h

A cross section through the axis produces a right triangle whose horizontal leg is:

R − r

and vertical leg is:

h

Therefore its slant height is:

ℓ = √[h² + (R − r)²]

That slant geometry complements the Frustum Volume calculation, which uses the two radii and perpendicular height directly.

Distance Between Points With Fractions

Find the distance between:

A = (1/2, 3/2)

and:

B = (7/2, 11/2)

Coordinate differences:

Δx = 3

Δy = 4

Therefore:

d = √(3² + 4²)

= 5

Fractional coordinates do not change the formula.

Simplifying coordinate differences first often makes the arithmetic easier.

Distance Between Decimal Coordinates

Suppose:

A = (1.2, −0.5)

B = (4.2, 3.5)

Then:

Δx = 3

Δy = 4

Therefore:

d = 5

If coordinates are measured values rather than exact values, the final distance may need to be rounded according to the measurement precision.

Distance Formula With an Unknown Coordinate

The distance formula can be used backward.

Suppose:

A = (1, 2)

B = (x, 6)

and:

AB = 5

Then:

5 = √[(x − 1)² + (6 − 2)²]

Square:

25 = (x − 1)² + 16

Therefore:

(x − 1)² = 9

So:

x − 1 = ±3

Hence:

x = 4

or:

x = −2

Two points can be the same distance from A while lying on opposite sides horizontally.

Why Two Solutions Can Occur

A fixed-distance condition describes a circle.

If:

distance from A = 5

then every solution lies on a circle of radius 5 centered at A.

Restricting one coordinate, such as:

y = 6

can intersect that circle in two points.

That is why solving a distance equation may produce two valid coordinate solutions.

Perpendicular Bisector Interpretation

Points equidistant from two fixed points A and B lie on the perpendicular bisector of segment AB.

Suppose point P satisfies:

PA = PB

Using the distance formula:

√[(x − x₁)² + (y − y₁)²]

= √[(x − x₂)² + (y − y₂)²]

Squaring and simplifying produces a linear equation for the perpendicular bisector.

This is an important bridge between distance and locus geometry.

Example of a Perpendicular Bisector

Let:

A = (0, 0)

B = (6, 0)

Set distances equal:

√(x² + y²) = √[(x − 6)² + y²]

Square:

x² + y² = x² − 12x + 36 + y²

Therefore:

12x = 36

x = 3

The perpendicular bisector is the vertical line:

x = 3

Distance Between Two 3D Points

Suppose:

P = (−2, 1, 4)

Q = (3, 5, −8)

Differences:

Δx = 5

Δy = 4

Δz = −12

Then:

d = √(25 + 16 + 144)

= √185

Approximately:

d ≈ 13.60

The negative z-difference contributes positively after squaring.

3D Box Diagonal

A rectangular box with side lengths:

l, w, h

has space diagonal:

d = √(l² + w² + h²)

This is exactly the 3D distance formula.

For dimensions:

3, 4, 12

the diagonal is:

d = √(9 + 16 + 144)

= 13

This extends the familiar 3-4-5 relationship into three dimensions.

General n-Dimensional Distance

The same principle extends beyond three coordinates.

For points:

P = (p₁, p₂, …, pₙ)

and:

Q = (q₁, q₂, …, qₙ)

Euclidean distance is:

d = √Σ(qᵢ − pᵢ)²

The 2D formula has two squared coordinate differences.

The 3D formula has three.

Higher-dimensional geometry simply continues the same pattern.

Distance and Exterior-Angle Geometry

The Exterior Angles of polygons concern directional turning rather than coordinate length.

However, coordinate-defined polygons often require both ideas.

The distance formula can determine side lengths between vertices, while exterior-angle relationships determine how the direction changes from side to side.

This distinction keeps linear measurement separate from angular measurement.

Distance and Degrees and Radians

The distance formula itself contains no angular unit, but coordinate problems may combine distance with an angle.

For example, if a displacement of length d makes angle θ with the x-axis:

Δx = d cosθ

Δy = d sinθ

The Degrees and Radians used for θ must match the trigonometric evaluation.

Then:

d = √[(Δx)² + (Δy)²]

reconstructs the original displacement length.

Units of Distance

Distance uses linear units.

If coordinates are measured in:

meters

then the resulting distance is in:

meters

If coordinates are in:

centimeters

distance is in centimeters.

Although the formula squares coordinate differences internally, the final square root returns the measurement to linear units.

Exact Versus Approximate Distance

For:

d = √13

the exact answer is:

√13

Approximately:

d ≈ 3.61

If an exact radical is acceptable, it preserves full precision.

A decimal approximation should usually be rounded only at the final step.

Checking a Distance Formula Answer

A useful check is to compare the distance with the individual coordinate changes.

For 2D points:

d ≥ |Δx|

and:

d ≥ |Δy|

because the hypotenuse of a right triangle cannot be shorter than either leg.

For:

Δx = 6

Δy = 8

a result smaller than 8 cannot be correct.

The expected value is:

10

Common Distance Formula Mistakes

A frequent mistake is failing to square each coordinate difference separately.

The correct formula is:

√[(x₂ − x₁)² + (y₂ − y₁)²]

not:

√[(x₂ − x₁ + y₂ − y₁)²]

Another error is forgetting parentheses around negative coordinates.

For example:

4 − (−3) = 7

not:

1

In 3D, include the z-coordinate difference.

Do not forget the final square root.

Distance cannot be negative.

The result uses linear units, not square units.

Finally, maintain the same subtraction order within each coordinate pair. You may use point 2 minus point 1 or point 1 minus point 2, but mixing corresponding coordinates incorrectly can change the result.

Frequently Asked Questions

What is the 2D distance formula?

d = √[(x₂ − x₁)² + (y₂ − y₁)²]

What is the 3D distance formula?

d = √[(x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²]

Where does the distance formula come from?

It comes from the Pythagorean theorem.

Does point order matter?

No. Reversing the coordinate differences changes their signs but not their squares.

Can distance be negative?

No. Euclidean distance is always nonnegative.

What is the distance from (0,0) to (x,y)?

√(x² + y²)

What is the distance from (0,0,0) to (x,y,z)?

√(x² + y² + z²)

How do you find a circle radius from its center and a point?

Use the distance formula between the center and that point.

Distance between two points is the magnitude of their displacement vector.

What is the diagonal of a rectangle?

d = √(w² + h²)

What is the space diagonal of a rectangular box?

d = √(l² + w² + h²)

Why are coordinate differences squared?

Squaring removes direction signs and allows perpendicular displacement components to combine using the Pythagorean theorem.

How can I check a distance answer?

Confirm it is nonnegative and at least as large as the magnitude of each individual coordinate difference.

Mehran Khan

Mehran Khan is the primary author at The Logic Library and CEO & Founder of One Digit Media. With 10+ years of experience in software engineering, SEO, and digital publishing, he uses a research-led approach to Logics, Maths, Tech, Formulas, Science, and AI.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button