UNPKG

@dxzmpk/js-algorithms-data-structures

Version:

Algorithms and data-structures implemented on JavaScript

37 lines (19 loc) 1.7 kB
# Euclidean Distance In mathematics, the **Euclidean distance** between two points in Euclidean space is the length of a line segment between the two points. It can be calculated from the Cartesian coordinates of the points using the Pythagorean theorem, therefore occasionally being called the Pythagorean distance. ![Euclidean distance between two points](https://upload.wikimedia.org/wikipedia/commons/5/55/Euclidean_distance_2d.svg) ## Distance formulas ### One dimension The distance between any two points on the real line is the absolute value of the numerical difference of their coordinates ![One dimension formula](https://wikimedia.org/api/rest_v1/media/math/render/svg/7d75418dbec9482dbcb70f9063ad66e9cf7b5db9) ### Two dimensions ![Two dimensions formula](https://wikimedia.org/api/rest_v1/media/math/render/svg/9c0157084fd89f5f3d462efeedc47d3d7aa0b773) ### Higher dimensions In three dimensions, for points given by their Cartesian coordinates, the distance is ![Three dimensions formula](https://wikimedia.org/api/rest_v1/media/math/render/svg/d1d13a40a7b203b455ae6d4be8b3cce898bda625) Example: the distance between the two points `(8,2,6)` and `(3,5,7)`: ![3-dimension example](https://www.mathsisfun.com/algebra/images/dist-2-points-3d.svg) In general, for points given by Cartesian coordinates in `n`-dimensional Euclidean space, the distance is ![n-dimensional formula](https://wikimedia.org/api/rest_v1/media/math/render/svg/a0ef4fe055b2a51b4cca43a05e5d1cd93f758dcc) ## References - [Euclidean Distance on MathIsFun](https://www.mathsisfun.com/algebra/distance-2-points.html) - [Euclidean Distance on Wikipedia](https://en.wikipedia.org/wiki/Euclidean_distance)