Euclidean Distance Calculator (2024)

It may sound fancy, but the Euclidean distance is nothing more than the distance the way we think of it every day: discover more on how to calculate it with our Euclidean distance calculator!

Here you will learn:

  • What is the Euclidean distance?
  • Formulas:
    • The distance between two points and the distance between three points;
    • The distance between a point and a line;
    • The distance between two lines.
  • Other uses of the Euclidean distance.

What is the Euclidean distance?

The Euclidean distance is a metric defined over the Euclidean space (the physical space that surrounds us, plus or minus some dimensions). In a few words, the Euclidean distance measures the shortest path between two points in a smooth n-dimensional space.

We can define the Euclidean distance only in flat spaces: on curved surfaces, strange things happen, and straight lines are not necessarily the shortest!

How do I calculate the Euclidean distance?

The Euclidean distance is defined through the Cartesian coordinates of the points under analysis. We can think of it as the translation vector between two points. In our Euclidean distance calculator, we teach you how to calculate:

  • The Euclidean distance between two or three points in spaces form one to four dimensions;
  • The Euclidean distance between a point and a line in a 2D space; and
  • The Euclidean distance between two parallel lines in a 2D space.

Euclidean distance between two points

To find the Euclidean distance between two points. you need to know the coordinates of these points.

Take a generic point ppp. We can write its coordinates as:

p=(p1,p2,p3,...)p = (p_1,p_2,p_3,...)p=(p1,p2,p3,...)

The number of components depends on the dimensionality of the space.

To calculate the distance between the point ppp and the point qqq, we apply a generalized form of the Pythagorean theorem:

 ⁣d(p,q) ⁣= ⁣(q1 ⁣ ⁣p1)2 ⁣+ ⁣(q2 ⁣ ⁣p2)2 ⁣+ ⁣=i=1n(qipi)2\small\begin{align*}\!d(p,q)\!&=\!\sqrt{(q_1\!-\!p_1)^2\!+\!(q_2\!-\!p_2)^2\!+\!\dots}\\\\&=\sqrt{\sum_{i=1}^n(q_i-p_i)^2}\end{align*}d(p,q)=(q1p1)2+(q2p2)2+=i=1n(qipi)2

Where nnn is the dimensionality of the space.

As you can see, it's pretty easy!

Euclidean distance of three points

If we add a point, we will find three possible distances; three points, after all, always define a triangle (possibly degenerated).

Taking the triple of points ppp, qqq, and rrr, we can find the following two points distances:

d(p,q)=i=1n(qipi)2d(q,r)=i=1n(qiri)2d(p,r)=i=1n(piri)2\begin{align*}d(p,q)&=\sqrt{\sum_{i=1}^n(q_i-p_i)^2}\\\\d(q,r)&=\sqrt{\sum_{i=1}^n(q_i-r_i)^2}\\\\d(p,r)&=\sqrt{\sum_{i=1}^n(p_i-r_i)^2}\end{align*}d(p,q)d(q,r)d(p,r)=i=1n(qipi)2=i=1n(qiri)2=i=1n(piri)2

This concept can obviously expand to increasingly larger n-tuples.

Euclidean distance between a point and a line

To find the distance from a point to a line (in two dimensions), we need to consider the fact that a line is nothing but a collection of points satisfying an equation. The distance between a point and a line is then the minimum distance between the point and the line.

The segment connecting the point to the point on the line satisfying the condition above is perpendicular to the line itself. To find the distance, we use this formula:

d=ap1+bq1+ca2+b2d=\frac{\left\lvert a\cdot p_1 +b\cdot q_1 + c\right\rvert}{\sqrt{a^2+b^2}}d=a2+b2ap1+bq1+c

Where aaa, bbb, and ccc are the coefficient of the equation of the line in the form: ax+by+c=0a\cdot x + b\cdot y + c = 0ax+by+c=0. If we are considering the more commonly found expression y=mx+cy = m\cdot x + cy=mx+c, we would use this formula (equivalent in every way):

d=mp1+q1+cm2+1d=\frac{\left\lvert m\cdot p_1 + q_1 + c\right\rvert}{\sqrt{m^2+1}}d=m2+1mp1+q1+c

Euclidean distance between two parallel lines

To calculate the distance between two parallel lines we use the following equation:

d=c2c1a2+b2d=\frac{\lvert c_2-c_1 \rvert}{\sqrt{a^2+b^2}}d=a2+b2c2c1

The lines have equations:

  • a1x+b1y1+c1a_1\cdot x+b_1\cdot y_1 + c_1a1x+b1y1+c1; and
  • a2x+b2y1+c2a_2\cdot x+b_2\cdot y_1 + c_2a2x+b2y1+c2.

However, there is a strong constraint over the choices of coefficients. Since two non-parallel lines would cross at a certain point in the plane, giving a trivial distance d=0d=0d=0, we define the Euclidean distance only in the case of parallel lines. This gives us quite some helpful rules:

  • a1=a2=aa_1=a_2=aa1=a2=a;
  • b1=b2=bb_1=b_2=bb1=b2=b;
  • However, c1c2c_1\neq c_2c1=c2.

Using the slope-intercept form of the equation of a line, the formula for the distance becomes:

d=c2c1m2+1d=\frac{\lvert c_2-c_1 \rvert}{\sqrt{m^2+1}}d=m2+1c2c1

A different point of view: Euclidean distance as a distance between points in a set

The Euclidean distance is becoming an important concept in machine learning (the less sci-fi version of AI), where the distance between points in arbitrary spaces of features is measured with metrics. The most commonly used ones are:

  • The Minkowski distance;
  • The Manhattan distance; and
  • The Euclidean distance.

Each of them is appropriate for certain data: the Manhattan distance for integer values and the Euclidean distance for real-valued data. The Minkowski distance is a generalization of both.

It is interesting to notice how a physical, and concrete, concept (the distance between two points) is translated into a distance in a space of features: the difference is from calculating the distance between your house and the one of a friend to a generalized distance between two colors, two car models...

How do I use the Euclidean distance calculator?

First, choose the objects you are calculating the distance: for points, you can also choose the dimensionality of the space.

Then, insert the coordinates of the points or the parameters of the lines. We will show both the distance and the steps to calculate it. There is nothing more to it!

Euclidean distance and beyond

The Euclidean distance is a particular — yet common — way to measure the distance. We made more calculator specific to certain topics and problems:

  • The 2D distance calculator;
  • Length of a line segment calculator;
  • Coordinate distance; and
  • Distance between two points'

FAQ

What is the distance between two parallel lines with equations y = 2x + 3 and y = 2x - 4?

The distance is 3.13. To calculate it,

  1. We identify the parameters of the lines:

    • m=2 (the value is the same for both lines since they are parallel); and

    • c₁ = 3, and c₂ = -4.

  2. We apply the equation for the distance between two parallel lines:

    d = | c₁ - c₂ |/(√[m² + 1])
    d = | 3 + 4 |/(√[2² + 1] = 3.13

How do I calculate the distance between a point and a line?

To calculate the distance between a point and a line, follow these steps:

  1. Define the coordinates and parameters of the objects.

  2. Calculate the distance using the formula:

    d = | m × p₁ + q₁ + c |/(√[m² + 1])

  3. And that's it! To compute the distance, we had to calculate the area of a triangle in coordinates space and then calculate its height.

Is the distance formula still valid in a 4-dimensional space?

Yes: the concept of distance exists in any Euclidean space with an arbitrary number of dimensions. It may be hard to visualize a 4-dimensional space, though. Imagine a car that moved from a point A to a point B in a certain time t. If you take time as your fourth dimension, you can see that, if you freeze the movement, the car is not moving: we need the fourth dimension to define the distance!

What is the distance between the point p = (1,2) and the point q = (2,3)?

d = 1.414. To calculate the distance between these two points on a plane, we simply apply the formula:

√[(p₂ - p₁)² + (q₂ - q₁)²]

In this case:

√[(2 - 1²) + (3 - 2²] = √2 = 1.414

Notice how the distance between these two particular points corresponds both to the hypotenuse of a right triangle and the diagonal of a square.

Euclidean Distance Calculator (2024)

FAQs

How do you calculate Euclidean distance? ›

Euclidean distance in two dimensions is given by D = ( x 2 − x 1 ) 2 + ( y 2 − y 1 ) 2 , where D is the distance, and ( x 1 , y 1 ) and ( x 2 , y 2 ) are the Cartesian coordinates of the two points.

How to find the Euclidean distance of 3 points? ›

In three-dimensional space, the distance between the points (a, b, c) and (d, e, f) is Square root of√(a − d)2 + (b − e)2 + (c − f)2. This formula can be extended to other coordinate systems, such as polar coordinates and spherical coordinates.

Why do we calculate Euclidean distance? ›

While in mathematics, the Euclidean space is measuring the space or line between two points. As a tool, the Euclidean distance provides individual cell's relationship either to certain source or to a set of sources presented via straight-line distance.

What is the formula for the Euclidean distance matrix? ›

d(p,q)=d(q,p)=√(q1−p1)2+(q2−p2)2+⋯+(qn−pn)2=√n∑i=1(qi−pi)2.

What is Euclidean in simple terms? ›

Euclidean geometry, the study of plane and solid figures on the basis of axioms and theorems employed by the Greek mathematician Euclid (c. 300 bce). Three theorems of congruent triangles.

What is the formula for Euclidean distance in 3 dimensions? ›

Similarly, to calculate the distance between two objects (or points) in space, the knowledge and formula of three dimensions – the distance between two points is required. PQ = d = √ [(x2 – x1)2 + (y2 – y1)2 + (z2 – z1)2].

When to use Euclidean distance? ›

The Euclidean Distance tool is used frequently as a stand-alone tool for applications, such as finding the nearest hospital for an emergency helicopter flight. Alternatively, this tool can be used when creating a suitability map, when data representing the distance from a certain object is needed.

What is the Euclidean distance pattern? ›

Euclidean distance is the most basic distance in metric learning. Generally, the Euclidean distance between two example vectors (x and y) is defined as: (77) D x , y = x - y ⊤ x - y = ∥ x - y ∥ 2 .

Why not use Euclidean distance? ›

One of the key limitations of Euclidean distance is that it is not scale-invariant, which means that distances computed might be skewed depending on the units of the features.

How to calculate Euclidean norm? ›

The Euclidean norm Norm[v, 2] or simply Norm[v] = ||v|| function on a coordinate space ℝn is the square root of the sum of the squares of the coordinates of v.

Why is Euclidean distance better than cosine? ›

For tasks prioritizing directional similarity over magnitude, such as text analysis or recommendation systems, Cosine Similarity proves beneficial. Euclidean Distance is suitable for scenarios where the actual geometric distance between points is essential, like clustering or regression analysis.

How do you manually calculate Euclidean distance? ›

The Euclidean distance formula is used to find the distance between two points on a plane. This formula says the distance between two points (x1 1 , y1 1 ) and (x2 2 , y2 2 ) is d = √[(x2 – x1)2 + (y2 – y1)2].

What is the range of the Euclidean distance? ›

What is the range of Euclidean distance? In theory, maximum Euclidean distance is unbounded ( ), but in practice its range depends on the distribution of input values. If the input values are bounded between zero and one, the theoretical maximum is equal to the square root of the number of variables ( ) being compared.

What is the formula for the distance between two points? ›

Distance between two points is the length of the line segment that connects the two points in a plane. The formula to find the distance between the two points is usually given by d=√((x2 – x1)² + (y2 – y1)²). This formula is used to find the distance between any two points on a coordinate plane or x-y plane.

What is the formula for Euclidean distance in R? ›

How to compute the Euclidean distance between two arrays in R? Euclidean distance is the shortest possible distance between two points. Formula to calculate this distance is : Euclidean distance = √Σ(xi-yi)^2 where, x and y are the input values.

References

Top Articles
Latest Posts
Article information

Author: Saturnina Altenwerth DVM

Last Updated:

Views: 5637

Rating: 4.3 / 5 (44 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Saturnina Altenwerth DVM

Birthday: 1992-08-21

Address: Apt. 237 662 Haag Mills, East Verenaport, MO 57071-5493

Phone: +331850833384

Job: District Real-Estate Architect

Hobby: Skateboarding, Taxidermy, Air sports, Painting, Knife making, Letterboxing, Inline skating

Introduction: My name is Saturnina Altenwerth DVM, I am a witty, perfect, combative, beautiful, determined, fancy, determined person who loves writing and wants to share my knowledge and understanding with you.