How to calculate euclidean distance
Euclidean distance is a fundamental concept in geometry that measures the straight-line distance between two points in a Euclidean space, such as a 2D plane or 3D space. It plays an essential role in various fields including data analysis, machine learning, and geographic information systems (GIS). In this article, we will dive into the concept of Euclidean distance by illustrating its calculation in different dimensions.
Step 1: Understanding the formula
The Euclidean distance between two points (x1, y1) and (x2, y2) in a two-dimensional space can be calculated using the following formula:
distance = √((x2 – x1)² + (y2 – y1)²)
For three-dimensional spaces, the formula becomes:
distance = √((x2 – x1)² + (y2 – y1)² + (z2 – z1)²)
Step 2: Working with 2D coordinates
To calculate the Euclidean distance between two points in a 2D plane, follow these steps:
a) Identify the coordinates of the two points. For example, Point A(3, 4) and Point B(6, 8).
b) Subtract the corresponding x-coordinates and y-coordinates.
x-difference = x2 – x1 = 6 – 3 = 3
y-difference = y2 – y1 = 8 – 4 = 4
c) Square each difference.
(x-difference)² = 3² = 9
(y-difference)² = 4² = 16
d) Add the squared differences.
sum_of_squares = 9 + 16 = 25
e) Find the square root of the sum of squared differences.
distance = √25 = 5
So, the Euclidean distance between Point A and Point B is 5.
Step 3: Working with 3D coordinates
Calculating the Euclidean distance in a 3D space involves a similar process as in the 2D case:
a) Identify the coordinates of the two points. For example, Point A(2, -1, 4) and Point B(5, 2, 9).
b) Subtract the corresponding x, y, and z coordinates.
x-difference = x2 – x1 = 5 – 2 = 3
y-difference = y2 – y1 = 2 – (-1) = 3
z-difference = z2 – z1 = 9 – 4 = 5
c) Square each difference.
(x-difference)² = 3² = 9
(y-difference)² = 3² = 9
(z-difference)² = 5² = 25
d) Add the squared differences.
sum_of_squares = 9 + 9 + 25 = 43
e) Find the square root of the sum of squared differences.
distance = √43 ≈6.71
Therefore, the Euclidean distance between Point A and Point B in a three-dimensional space is approximately equal to 6.71.
Conclusion:
Calculating Euclidean distance is both straightforward and applicable to many fields like data science and geography. By understanding the formula and following these steps for two or three-dimensional spaces, anyone can accurately compute the distance between any two points in a Euclidean space.