Skip to main content
🔬 Advanced

Afstandsformelberegner

Calculate the distance between two points using the distance formula. Enter coordinates (x1,y1) and (x2,y2) for instant results.

Sådan bruges denne lommeregner

  1. Indtast x₁
  2. Indtast y₁
  3. Indtast x₂
  4. Indtast y₂
  5. Klik på knappen Beregn
  6. Læs resultatet vist under lommeregneren

The Distance Formula Derivation

The distance formula calculates the straight-line (Euclidean) distance between two points (x₁,y₁) and (x₂,y₂): d = √((x₂-x₁)² + (y₂-y₁)²). This formula is a direct application of the Pythagorean theorem: the two points and the right-angle point (x₂,y₁) form a right triangle, with legs |x₂-x₁| and |y₂-y₁| and hypotenuse d.

Example: distance from (1,2) to (4,6). Δx = 3, Δy = 4. d = √(3² + 4²) = √(9+16) = √25 = 5. The 3-4-5 Pythagorean triple means these two points are exactly 5 units apart. In general, √((x₂-x₁)² + (y₂-y₁)²) may not simplify to a whole number.

The formula works in any direction — horizontal, vertical, or diagonal. For a horizontal segment (y₁=y₂): d = |x₂-x₁|. For a vertical segment (x₁=x₂): d = |y₂-y₁|. The general formula handles all cases consistently.

Distance in Higher Dimensions and Non-Euclidean Spaces

The Euclidean distance formula extends naturally to higher dimensions. In 3D: d = √((x₂-x₁)² + (y₂-y₁)² + (z₂-z₁)²). In n dimensions: d = √(Σᵢ(xᵢ₂-xᵢ₁)²). This is the Euclidean norm (L2 norm) of the difference vector. In machine learning, it's called the Euclidean distance or L2 distance between feature vectors.

Other distance metrics serve different purposes. The Manhattan distance (L1): d = |x₂-x₁| + |y₂-y₁| — the distance a taxi travels on a grid. The Chebyshev distance (L∞): d = max(|x₂-x₁|, |y₂-y₁|) — the distance a king moves on a chessboard. The Minkowski distance generalizes all of these.

On a sphere (like Earth's surface), straight-line distance is different from the great-circle distance (shortest path along the surface). The haversine formula calculates great-circle distance from latitude/longitude coordinates. This is essential for GPS, aviation routing, and geographic analysis.

Applications: Geometry, Physics, and Machine Learning

Distance calculations are fundamental across disciplines. In geometry: finding the radius of a circle given its center and a point on the circle; determining if a point lies inside a circle (d < r), on it (d = r), or outside (d > r); measuring lengths of geometric shapes.

In physics: calculating displacement (distance between start and end points, regardless of path), computing gravitational or electrical force (proportional to 1/d²), and ray-sphere intersection in computer graphics (solving for d in ray tracing algorithms).

In machine learning and data science: k-nearest neighbors (kNN) classifies points by the k closest training examples. k-means clustering assigns points to the nearest cluster centroid. Support vector machines find decision boundaries that maximize the minimum distance (margin) between classes. Distance metrics are the backbone of these algorithms, making the distance formula one of the most computationally used equations in modern technology.

Sidst opdateret: March 2026

Frequently Asked Questions

What is the distance between two identical points?

Zero. If (x₁,y₁) = (x₂,y₂), then d = √((0)² + (0)²) = 0. A point has zero distance to itself.

Does it matter which point is (x₁,y₁) and which is (x₂,y₂)?

No. The distance formula gives the same result either way because the differences are squared: (x₂-x₁)² = (x₁-x₂)². Distance is symmetric.

How do I find the distance in 3D space?

Extend the formula: d = √((x₂-x₁)² + (y₂-y₁)² + (z₂-z₁)²). For example, distance from (1,2,3) to (4,6,3): d = √(9+16+0) = √25 = 5.