Skip to content
Other

2D Distance Calculator: Distance Between Two Points

Enter the x and y coordinates of two points to calculate the straight-line (Euclidean) distance between them. You get the exact distance in simplified radical form and as a decimal, the midpoint, the slope as a reduced fraction, the equation of the line through both points, the angle the segment makes with the x-axis, and the horizontal and vertical components. The step-by-step panel walks through every calculation with your actual numbers.

Your details

Horizontal (x) coordinate of the first point.
Vertical (y) coordinate of the first point.
Horizontal (x) coordinate of the second point.
Vertical (y) coordinate of the second point.
Distance
5

Straight-line (Euclidean) distance between the two points

Exact distance5
Horizontal component (dx)3
Vertical component (dy)4
Midpoint x1.5
Midpoint y2
Slope (rise / run)1.333333
Slope as fraction4/3
Line equationy = 4/3x
Angle with x-axis53.1301deg
Line descriptionSlope = 4/3, line rises to the right
Horizontal (dx)3
Vertical (dy)4
Distance (d)5

Distance: 5.000000 (exact: 5)

  • The straight-line distance from (0, 0) to (3, 4) is 5.000000 (exact: 5).
  • The midpoint lies at (1.5000, 2.0000).
  • Point 1 is in the origin; Point 2 is in Quadrant I.
  • Line equation: y = 4/3x.

Next stepUse the slope and the y-intercept from the line equation above to graph or extend the line in either direction.

Formula

d=(x2−x1)2+(y2−y1)2d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}

Worked example

For points (0, 0) and (3, 4): dx = 3, dy = 4, so d = sqrt(3^2 + 4^2) = sqrt(9 + 16) = sqrt(25) = 5. The midpoint is (1.5, 2), slope = 4/3, y-intercept = 0, line equation y = (4/3)x, angle = atan2(4, 3) = 53.13 degrees.

What is the 2D distance formula?

The 2D distance formula calculates the straight-line (Euclidean) distance between two points in a flat, two-dimensional Cartesian coordinate system. Given Point 1 at (x1, y1) and Point 2 at (x2, y2), the formula is d = sqrt((x2 - x1)^2 + (y2 - y1)^2). This is a direct application of the Pythagorean theorem: the horizontal separation (dx = x2 - x1) and vertical separation (dy = y2 - y1) form the two legs of a right triangle, and the straight-line distance is the length of the hypotenuse. The formula always produces a non-negative result and gives the shortest possible path between two points in a plane.

Simplified radical form and exact answers

When your coordinates are integers, the calculator also shows the distance in simplified radical form. For example, if dx = 3 and dy = 4, the sum of squares is 25, which is a perfect square, so the exact distance is 5. For dx = 2 and dy = 4, the sum of squares is 20 = 4 * 5, so the exact form is 2*sqrt(5). This matters in geometry proofs and algebra courses where an approximate decimal answer is not accepted. The simplification works by factoring out the largest perfect square that divides the radicand.

Slope, line equation, and midpoint

Beyond distance, this calculator derives the full picture of the line segment. The slope m = (y2 - y1) / (x2 - x1) tells you the steepness of the line. When dx and dy are both integers the slope is shown as a reduced fraction (e.g. 4/3 rather than 1.333...), which is the exact form. From the slope and one point, the y-intercept b = y1 - m * x1 is found, giving the slope-intercept equation y = mx + b. The midpoint at ((x1 + x2) / 2, (y1 + y2) / 2) is the point exactly halfway along the segment. Together these quantities fully characterise the line and segment connecting the two input points.

The Pythagorean theorem connection

Visualise a right triangle with one vertex at each input point and the right angle at (x2, y1). The horizontal leg has length |dx| and the vertical leg has length |dy|. The Pythagorean theorem says the hypotenuse length equals sqrt(dx^2 + dy^2), which is exactly the distance formula. Squaring removes the sign from dx and dy, so the distance is the same whether Point 2 is to the left or right, above or below Point 1. The horizontal and vertical bars in the visual show the signed components, while the third bar shows the total distance.

Common uses for the 2D distance formula

The 2D distance formula appears across mathematics, science, and engineering. In coordinate geometry it measures segment lengths, checks whether a point lies on a circle (all points equidistant from the centre), and underpins proofs. In physics it converts two-component displacements into scalar magnitudes. In computer graphics it drives collision detection, pathfinding, and rendering. In data science the formula is the foundation of Euclidean distance metrics used in k-nearest-neighbours, k-means clustering, and similarity search. Whenever two quantities in different dimensions are combined into one distance, this formula is the starting point.

Special cases and what they mean

ConfigurationDistanceSlopeAngleLine equation
Same point (x1=x2, y1=y2)0N/AN/AN/A
Horizontal line (y1=y2)|x2 - x1|00 deg or 180 degy = c
Vertical line (x1=x2)|y2 - y1|Undefined90 deg or -90 degx = c
45-degree diagonalsqrt(2) * side145 degy = x + b
3-4-5 right triangle5 (dx=3, dy=4)4/353.13 degy = (4/3)x
Unit step right100 degy = c
1-1 diagonalsqrt(2)1 or -145 or -45 degy = x + b

Interpreting results for common coordinate configurations.

Frequently asked questions

What is the distance formula for two points in 2D?

The formula is d = sqrt((x2 - x1)^2 + (y2 - y1)^2). Subtract the x-coordinates, square the result, do the same for the y-coordinates, add both squares together, and take the square root. This gives the straight-line Euclidean distance, which is always non-negative.

How do I get the exact distance as a radical rather than a decimal?

When both dx = x2 - x1 and dy = y2 - y1 are integers, the sum dx^2 + dy^2 is also an integer. Factor out the largest perfect square from that integer: for example sqrt(50) = sqrt(25 * 2) = 5*sqrt(2). If the sum is itself a perfect square the radical collapses to a whole number. This calculator shows the simplified radical form automatically whenever the coordinates are integers.

What does the line equation output mean?

The line equation is written in slope-intercept form, y = mx + b, where m is the slope and b is the y-intercept. It describes the full infinite line that passes through both input points, not just the segment between them. For a vertical line (where dx = 0 and slope is undefined) the equation takes the form x = c instead, because no y = mx + b form exists.

Why is slope undefined for a vertical line?

Slope is dy divided by dx. When the two points have the same x-coordinate (x1 = x2), dx = 0, and division by zero is undefined. A vertical line rises straight up without any horizontal movement, so no finite number can represent its slope. The line is described as x = c (a constant) rather than with a slope-intercept form.

Can I use this formula for negative coordinates?

Yes. The formula works for any real coordinates, positive, negative, or zero. Squaring dx and dy removes their signs before adding, so (-3, -4) to (0, 0) gives the same distance of 5 as (3, 4) to (0, 0).

How is the angle calculated and what does it mean?

The angle uses the two-argument arctangent, atan2(dy, dx), which returns the angle in radians measured counterclockwise from the positive x-axis, then converted to degrees. The result ranges from -180 to 180. Point 2 directly above Point 1 gives 90 degrees; directly to the right gives 0 degrees; directly below gives -90 degrees.

What is the difference between distance and displacement?

Distance is a scalar: the magnitude of the straight-line path between two points, always positive. Displacement is a vector: it includes both the magnitude and the direction from start to end. This calculator gives the scalar distance as the primary result and also shows the signed components dx and dy, which together form the displacement vector.

Sources

Written by Grace Mbeki, MSc Data Scientist & Educator · Nairobi, Kenya

Turning everyday numbers into clear, actionable answers for the decisions that matter most.

Search 3,500+ calculators

Loading search…