Fórmula da Distância entre Pontos

A Fórmula da Distância calcula o comprimento do segmento de reta entre dois pontos no plano cartesiano. d = √((x2 − x1)² + (y2 − y1)²). É uma aplicação direta do Teorema de Pitágoras: o segmento entre os dois pontos é a hipotenusa de um triângulo retângulo formado pelas diferenças entre coordenadas.

Point 1
Point 2

Try a worked example

Como usar

  1. 1

    Informe as coordenadas do primeiro ponto (x1, y1).

  2. 2

    Informe as coordenadas do segundo ponto (x2, y2).

  3. 3

    Veja a distância calculada automaticamente.

Perguntas frequentes

Ratings & Reviews

Rate this tool

Sign in to rate and review this tool.

Loading reviews…

What is the distance formula?

The distance formula calculates the straight-line distance between two points on a coordinate plane. For two 2D points (x₁, y₁) and (x₂, y₂), the formula is:

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

It's a direct application of the Pythagorean theorem: if you draw the line connecting two points and complete a right triangle (one leg horizontal, one vertical), the line is the hypotenuse. The horizontal leg has length |x₂ − x₁|, the vertical leg has length |y₂ − y₁|, and the hypotenuse² = leg₁² + leg₂² gives the squared distance. Take the square root and you have the actual distance.

For 3D coordinates (x₁, y₁, z₁) and (x₂, y₂, z₂), the formula extends naturally by adding the z-axis:

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

Geometrically, the 3D distance is the diagonal through a rectangular box whose edges are the three coordinate differences.

How to use the calculator

Five steps:

  1. Pick 2D mode (just x and y) or 3D mode (x, y, z) using the toggle at the top.
  2. Enter the coordinates of the first point — x₁, y₁, and z₁ if in 3D.
  3. Enter the coordinates of the second point — x₂, y₂, and z₂ if in 3D.
  4. Read the distance result, which appears with the formula plugged in below it.
  5. Click any of the worked examples to load classic cases (the 3-4-5 right triangle, unit square diagonal, etc.) and see the calculator in action.

The calculator updates as you type — there's no Calculate button. Negative coordinates and decimals are both fine. The output box shows the formula with your values substituted in, so you can verify the math.

Worked example: the classic 3-4-5

The most famous distance-formula example: from (0, 0) to (3, 4).

d = √((3 − 0)² + (4 − 0)²)
  = √(9 + 16)
  = √25
  = 5

This works because 3, 4, and 5 form a Pythagorean triple — three integers where a² + b² = c². Other Pythagorean triples include 5-12-13, 8-15-17, 7-24-25, 20-21-29 — and any integer multiple of any of these (6-8-10, 9-12-15, 10-24-26, etc.). Knowing a few triples lets you spot easy distance-formula problems mentally.

If the points were further apart — say (0, 0) to (5, 12) — the same logic applies: d = √(25 + 144) = √169 = 13. Those are the legs of a 5-12-13 triangle.

Why the formula uses square root

Because the Pythagorean theorem gives you the squared distance, not the distance itself. Taking the square root extracts the actual length.

This has practical implications:

  • Distances are always non-negative. The square of any real number is non-negative, so the sum of squares is non-negative, so the square root is real and non-negative. The formula can't produce a negative distance — and if it ever did, that would signal a bug.
  • Order doesn't matter. Distance from A to B equals distance from B to A. (x₂ − x₁)² is the same as (x₁ − x₂)² because squaring drops the sign. So the formula is symmetric.
  • Squaring suppresses small differences. A point at (0, 0.001) is barely distance 0.001 from the origin — the squared term is 0.000001, essentially zero. Squaring concentrates emphasis on the larger terms, which is exactly the right behavior for distance.

Common mistakes

Three errors students (and adults) make repeatedly:

1. Forgetting to square BEFORE adding. The formula is √((x₂−x₁)² + (y₂−y₁)²), not √((x₂−x₁) + (y₂−y₁))². If you add the differences first and then square, you get the wrong answer for any non-axis-aligned line.

2. Mixing up subtraction order. (x₂ − x₁)² and (x₁ − x₂)² are the same value (squaring drops the sign), but it's easy to miscompute by hand if the signs flip mid-calculation. The calculator handles this; pen-and-paper users should pick one direction and stick with it.

3. Forgetting the square root. The squared distance is √((x₂−x₁)² + (y₂−y₁)²)². If you stop at the sum-of-squares step, you have the squared distance, not the distance itself. For two points (0, 0) and (3, 4), the squared distance is 25, but the actual distance is √25 = 5.

Beyond 2D and 3D

The distance formula generalizes to any number of dimensions:

d = √(Σᵢ (yᵢ − xᵢ)²)

where the sum runs over each coordinate dimension. In machine learning, this is called Euclidean distance and is one of the most common ways to measure how "different" two data points are. A 100-dimensional Euclidean distance follows the exact same pattern: square each coordinate-wise difference, sum them, take the square root.

Other distance metrics exist for different purposes — Manhattan distance (sum of absolute differences, useful when motion is grid-constrained), cosine distance (angle between vectors, useful for normalizing for magnitude), Hamming distance (count of differing positions, useful for strings or binary vectors). Euclidean is the default when "distance" isn't otherwise specified.

What the calculator doesn't handle

One important limitation: this calculator computes flat-plane Euclidean distance. It's not appropriate for:

  • GPS coordinates (latitude, longitude). Earth is curved. For nearby points (under a few miles), the error is small enough to ignore. For city-to-city or longer distances, you need the haversine formula (great-circle distance) which accounts for Earth's curvature. New York to London via the Euclidean formula would underestimate by hundreds of miles.
  • Distances on a sphere or other curved surface. Same issue — Euclidean only works in flat (Cartesian) coordinates.
  • Distances between vectors in non-Euclidean spaces like hyperbolic geometry, used in some physics and visualization contexts.

For everyday math, physics, computer graphics, game development, geometry homework, and 2D/3D space generally — Euclidean is what you want.

Related calculators

  • For aspect-ratio math (computing diagonal sizes from width and height), the Aspect Ratio Calculator handles screen-and-image proportions.
  • For statistical mean/median/mode of a dataset, use the Average Calculator.
  • For geometric mean (relevant when distances multiply, like compound growth), the Geometric Mean Calculator.
  • For the inverse — given a distance and one endpoint, finding the other — that's a separate calculation (typically requires a direction angle); not currently in this tool.

Frequently asked questions

What is the distance formula?

The distance formula calculates the straight-line distance between two points on a coordinate plane: d = √((x₂−x₁)² + (y₂−y₁)²). It's the Pythagorean theorem applied to coordinate geometry.

How do I find the distance between two points?

Take the difference of x-coordinates, square it. Take the difference of y-coordinates, square it. Add them together. Take the square root. That's the distance. For (0, 0) to (3, 4): differences 3 and 4, squared = 9 and 16, summed = 25, square root = 5.

What's the distance between (0, 0) and (3, 4)?

Exactly 5. This is the famous 3-4-5 right triangle from middle school geometry. The horizontal leg is 3, the vertical leg is 4, the hypotenuse (which is the distance from origin to point) is 5.

Is the distance formula the same as the Pythagorean theorem?

It's an application of it. The Pythagorean theorem says a² + b² = c² for any right triangle. The distance formula uses this by treating the line between two points as the hypotenuse and the coordinate differences as the legs. Take the square root of both sides of the Pythagorean equation, plug in the leg formulas, and you have the distance formula.

What's the 3D distance formula?

d = √((x₂−x₁)² + (y₂−y₁)² + (z₂−z₁)²). Same as the 2D formula but with the z-axis added. Geometrically, it's the diagonal through a rectangular box whose edges are the x, y, and z coordinate differences. This calculator's 3D mode handles it directly.

Can I use this for GPS distances?

Only roughly. GPS coordinates are spherical, but the distance formula assumes flat coordinates. For nearby points (a few miles or less) the error is negligible. For city-to-city distances, use the haversine formula or Google's distance API — both account for Earth's curvature, which the distance formula doesn't.

Is my input saved or sent anywhere?

No. The calculation runs entirely in your browser using JavaScript — nothing is sent to a server, logged, or stored.