Enter the coordinates of point 1 and point 2 to find the distance between them. The slope and the equation of the line through the two points are shown too.
Table of Contents
-
What you can do on this page
-
What is this calculation used for?
-
How to Use
-
Formulas and figures
-
Symbols and terms
-
Good to know before you start
-
How to calculate it in Excel
-
How to calculate it in Google Sheets
-
How to calculate it in Python
-
How to write it in LaTeX and other math languages (copy and paste)
-
How to have ChatGPT do the calculation
-
DataChef Features
-
Related Features
-
NumberChef Calculators List
What you can do on this page
- Enter the coordinates of two points, and you get the distance \(d\) between them on the spot
- Along with the distance, it also finds the change in x \(\Delta x\), the change in y \(\Delta y\), the slope \(m\) and the equation of the line through the two points, \(y = mx + b\)
- The result is also shown on a graph, so you can see that the distance is the length of the line segment joining the two points
- A plain-language explanation of the formulas and copy-and-paste formulas for Excel, Google Sheets and Python are all on this page
What is this calculation used for?
In a 2D game, the positions of your character, enemies and items are kept as coordinates, and the game counts a "hit" when the distance becomes less than a set amount. For example, if your character is at (1, 1) and an enemy is at (4, 5), the distance is \(\sqrt{3^2 + 4^2} = 5\). Repeating this calculation is how distance-based collision detection works.
The distance formula is one of the first practical formulas you write when you start learning game development.
Surveyors record property corners and construction reference points as coordinates, for example in the State Plane Coordinate System used across the United States. Once you know the coordinates of two points, the horizontal distance between them can be found with the distance formula on this page.
This calculation supports the building of roads, buildings and other infrastructure. (To find a distance from latitude and longitude, taking the curve of the Earth into account, a different formula is used.)
In data analysis, a pair of numbers such as height and weight is treated as a point on the coordinate plane, and the closer two points are, the more similar the data are considered to be. This distance (the Euclidean distance) is used to group similar customers (clustering) and to make predictions from nearby data (the k-nearest neighbors method).
The formula on this page is the basic way of measuring distance that appears in every AI and machine learning textbook.
In technical drawings and CAD, positions such as the centers of holes in a part are given as coordinates. The diagonal distance between the centers of two holes, which is often not written on the drawing, can be found from the differences in coordinates with the distance formula.
For example, two holes 1.5 in apart horizontally and 2 in apart vertically have centers \(\sqrt{1.5^2 + 2^2} = \sqrt{6.25} = 2.5\) in apart. It is an everyday calculation in machining and inspection.
Formulas and figures
Symbols and terms
Symbols
| \(d\) | dee | The distance between the two points, from the first letter of "distance". |
| \((x_1, y_1)\), \((x_2, y_2)\) | x sub one, y sub one | The coordinates of the two points. \(x\) is the horizontal position and \(y\) is the vertical position. The small number at the lower right (the subscript) tells the first point from the second. |
| \(\Delta x\), \(\Delta y\) | delta x, delta y | The change (the difference of the coordinates). \(\Delta\) (delta) is a Greek letter that stands for "change" or "difference": \(\Delta x = x_2 - x_1\) and \(\Delta y = y_2 - y_1\). |
| \(\sqrt{\phantom{a}}\) | square root (radical sign) | The sign for the square root (the number that gives this number when squared). \(\sqrt{25} = 5\) (because 5² = 25). In the distance formula, you take the square root only once, at the end. |
| \(m\) | em | The slope of the line through the two points. It tells how much the line goes up or down for each 1 step to the right. If it is positive, the line rises to the right; if negative, it falls to the right. |
| \(b\) | bee | The y-intercept: the height where the line crosses the y-axis (the value of \(y\) when \(x = 0\)). |
Terms
| coordinates | A pair of numbers (horizontal position, vertical position) that gives the position of a point. The point (4, 5) is 4 to the right of the origin and 5 up. |
| coordinate plane | A plane where positions are given by a horizontal x-axis and a vertical y-axis. The distance on this page is the straight-line length between two points on the coordinate plane. |
| line segment | A straight line that joins two points, with those points as its ends. The distance between two points is the length of this line segment. |
| Pythagorean theorem | The theorem that in a right triangle, the sum of the squares of the two legs equals the square of the hypotenuse (\(a^2 + b^2 = c^2\)). The distance formula is this theorem applied to coordinates. It is taught in Grade 8. |
| hypotenuse | The longest side of a right triangle, opposite the right angle. In the distance formula, the line segment joining the two points is the hypotenuse. |
| Euclidean distance | The formal name for the straight-line distance between two points that this page calculates. In data analysis and AI, this name is often used for the basic way to measure how close points are. |
| slope | A number that shows how steep a line is: how much y increases when x increases by 1 ("rise over run"). It is the same as the rate of change of a linear function. |
| vertical line | A line perpendicular to the x-axis (going straight up and down). The line through two points with the same x-coordinate is vertical. The change in x is 0, so its slope is undefined. Its equation has the form \(x = c\), where \(c\) is a constant. |
Good to know before you start
Here is what helps you use the calculation on this page with real understanding, not just by pressing the button.
If you get stuck, going back over these topics is the fastest way forward.
| The coordinate plane (Grade 6) |
|
| Operations with positive and negative numbers (Grade 7) |
|
| Square roots (Grade 8) |
|
| The Pythagorean theorem (Grade 8) |
|
| Linear functions (Grade 8) |
|
How to calculate it in Excel
| Point 1 x-coordinate x₁ | 1 |
| Point 1 y-coordinate y₁ | 1 |
| Point 2 x-coordinate x₂ | 4 |
| Point 2 y-coordinate y₂ | 5 |
| Distance between the points d | =SQRT((B3-B1)^2+(B4-B2)^2) |
| Point 1 x-coordinate x₁ | 1 |
| Point 1 y-coordinate y₁ | 1 |
| Point 2 x-coordinate x₂ | 4 |
| Point 2 y-coordinate y₂ | 5 |
| Change in x Δx | =B3-B1 |
| Change in y Δy | =B4-B2 |
| Sum of squares Δx²+Δy² | =B5^2+B6^2 |
| Distance between the points d | =SQRT(B7) |
| Point 1 x-coordinate x₁ | 1 |
| Point 1 y-coordinate y₁ | 5 |
| Point 2 x-coordinate x₂ | 3 |
| Point 2 y-coordinate y₂ | 2 |
| Slope m | =(B4-B2)/(B3-B1) |
| y-intercept b | =B2-B5*B1 |
"SQRT(…)" is the square root, and "^2" is squared.
The first table gives the distance 5. The second table finds the same distance 5 from Δx = 3, Δy = 4 and the sum of squares 25, so you can also see the values along the way.
The third table gives the slope −1.5 and the y-intercept 6.5 (the line y = −1.5x + 6.5). If the two points have the same x-coordinate, you would be dividing by 0 and an error (#DIV/0!) appears; this tells you that the slope is undefined (a vertical line).
How to calculate it in Google Sheets
| Point 1 x-coordinate x₁ | 1 |
| Point 1 y-coordinate y₁ | 1 |
| Point 2 x-coordinate x₂ | 4 |
| Point 2 y-coordinate y₂ | 5 |
| Distance between the points d | =SQRT((B3-B1)^2+(B4-B2)^2) |
| Point 1 x-coordinate x₁ | 1 |
| Point 1 y-coordinate y₁ | 1 |
| Point 2 x-coordinate x₂ | 4 |
| Point 2 y-coordinate y₂ | 5 |
| Change in x Δx | =B3-B1 |
| Change in y Δy | =B4-B2 |
| Sum of squares Δx²+Δy² | =B5^2+B6^2 |
| Distance between the points d | =SQRT(B7) |
| Point 1 x-coordinate x₁ | 1 |
| Point 1 y-coordinate y₁ | 5 |
| Point 2 x-coordinate x₂ | 3 |
| Point 2 y-coordinate y₂ | 2 |
| Slope m | =(B4-B2)/(B3-B1) |
| y-intercept b | =B2-B5*B1 |
How to calculate it in Python
import math
x1, y1 = 1.0, 1.0 # coordinates of point 1
x2, y2 = 4.0, 5.0 # coordinates of point 2
delta_x = x2 - x1 # change in x
delta_y = y2 - y1 # change in y
distance = math.hypot(delta_x, delta_y) # distance between the points (same as √(Δx²+Δy²))
print(f"Distance between the points d: {distance}")
# Bonus: slope and equation of the line through the two points (undefined when Δx is 0, a vertical line)
if delta_x != 0:
slope = delta_y / delta_x # slope m
y_intercept = y1 - slope * x1 # y-intercept b
sign = "+" if y_intercept >= 0 else "-" # split off the sign so a negative intercept is not shown as "+ -0.3"
print(f"Slope m: {slope}")
print(f"y-intercept b: {y_intercept}")
print(f"Equation of the line: y = {slope}x {sign} {abs(y_intercept)}")
else:
print(f"Vertical line (x = {x1}), so the slope is undefined")
How to write it in LaTeX and other math languages (copy and paste)
d = √((x₂ − x₁)² + (y₂ − y₁)²)
d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>d</mi>
<mo>=</mo>
<msqrt>
<mrow>
<msup>
<mrow><mo>(</mo><msub><mi>x</mi><mn>2</mn></msub><mo>−</mo><msub><mi>x</mi><mn>1</mn></msub><mo>)</mo></mrow>
<mn>2</mn>
</msup>
<mo>+</mo>
<msup>
<mrow><mo>(</mo><msub><mi>y</mi><mn>2</mn></msub><mo>−</mo><msub><mi>y</mi><mn>1</mn></msub><mo>)</mo></mrow>
<mn>2</mn>
</msup>
</mrow>
</msqrt>
</mrow>
</math>
d = sqrt((x_2 - x_1)^2 + (y_2 - y_1)^2)
Sqrt[(x2 - x1)^2 + (y2 - y1)^2]
d := sqrt((x2 - x1)^2 + (y2 - y1)^2);
d = sqrt((x2 - x1)^2 + (y2 - y1)^2);
d = √((x_2 - x_1)^2 + (y_2 - y_1)^2)
Δx² + Δy² = d²
\Delta x^2 + \Delta y^2 = d^2
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<msup><mrow><mi mathvariant="normal">Δ</mi><mi>x</mi></mrow><mn>2</mn></msup>
<mo>+</mo>
<msup><mrow><mi mathvariant="normal">Δ</mi><mi>y</mi></mrow><mn>2</mn></msup>
<mo>=</mo>
<msup><mi>d</mi><mn>2</mn></msup>
</mrow>
</math>
(Delta x)^2 + (Delta y)^2 = d^2
dx^2 + dy^2 == d^2
dx^2 + dy^2 = d^2;
dx^2 + dy^2 == d^2
Δx^2 + Δy^2 = d^2
m = (y₂ − y₁) ÷ (x₂ − x₁), y = mx + b (b = y₁ − m·x₁)
m = \frac{y_2 - y_1}{x_2 - x_1}, \quad y = mx + b, \quad b = y_1 - m x_1
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>m</mi>
<mo>=</mo>
<mfrac>
<mrow><msub><mi>y</mi><mn>2</mn></msub><mo>−</mo><msub><mi>y</mi><mn>1</mn></msub></mrow>
<mrow><msub><mi>x</mi><mn>2</mn></msub><mo>−</mo><msub><mi>x</mi><mn>1</mn></msub></mrow>
</mfrac>
<mo>,</mo>
<mi>y</mi>
<mo>=</mo>
<mi>m</mi><mi>x</mi>
<mo>+</mo>
<mi>b</mi>
<mo>,</mo>
<mi>b</mi>
<mo>=</mo>
<msub><mi>y</mi><mn>1</mn></msub>
<mo>−</mo>
<mi>m</mi><msub><mi>x</mi><mn>1</mn></msub>
</mrow>
</math>
m = (y_2 - y_1)/(x_2 - x_1), y = m x + b, b = y_1 - m x_1
m = (y2 - y1)/(x2 - x1); b = y1 - m*x1; y = m*x + b
m := (y2 - y1)/(x2 - x1); b := y1 - m*x1; y := m*x + b;
m = (y2 - y1)/(x2 - x1); b = y1 - m*x1; y = m*x + b;
m = (y_2 - y_1)/(x_2 - x_1), y = mx + b, b = y_1 - mx_1
How to have ChatGPT do the calculation
You are a math calculation assistant. Do the following calculation by actually running Python code, and base your answer only on the numbers from the execution result (do not answer by mental math or guessing). For the two points (1, 1) and (4, 5) on the coordinate plane, find each of the following: 1. The distance d between the two points (use the distance formula d = √((x2−x1)² + (y2−y1)²)) 2. The change in x, Δx, and the change in y, Δy 3. The slope m of the line through these two points, and the equation of the line y = mx + b (also show the value of the y-intercept b) Show the formulas you used and the numbers from the execution result.
How to Use
-
1Enter your numbersType the numbers you want to calculate with into the input fields
-
2CalculatePress the "Calculate" button
-
3Check the resultThe result appears on the spot. The same page also explains the idea behind the calculation and the formula
DataChef Features
No technical knowledge required.
Intuitive and user-friendly operation.
Can be used without registering personal information.
Automatic file deletion by clicking "download".
and rapid file conversion.
No attribution required.
No need to contact us for commercial use permission.
