Distance and Midpoint Calculator (2D/3D Euclidean Distance)
About this calculator The distance calculator takes the Cartesian coordinates of two points, ( x 1 , y 1 , z 1 ) (x_1, y_1, z_1) ( x 1 , y 1 , z 1 ) and ( x 2 , y 2 , z 2 ) (x_2, y_2, z_2) ( x 2 , y 2 , z 2 ) , and returns the straight-line (Euclidean) distance between them, d = Δ x 2 + Δ y 2 + Δ z 2 d = \sqrt{\Delta x^2 + \Delta y^2 + \Delta z^2} d = Δ x 2 + Δ y 2 + Δ z 2 , together with the x x x and y y y coordinates of the midpoint of the segment. Set both z z z values to 0 and it becomes the distance between two points in the plane.
It suits questions such as: how far apart are two points on a map or drawing; the spacing between two pixels on a screen; the displacement of a robot arm between two positions; the length of an edge between two vertices of a 3D model; how “similar” two samples are in data analysis. Anything that can be written as coordinates can have its distance measured with it.
What it does not do: it does not compute the distance along roads or a grid (that is the Manhattan distance, or route planning), it does not compute great-circle distance between two places on the Earth’s surface (latitude and longitude need spherical formulas), it does not output the z z z midpoint, and it does not convert units—all coordinates must use the same length unit.
How to use this calculator 01 Open the panel this page corresponds to “Math tools → Formulas → Distance calculator (2D/3D)” (/#/mathtools/formula?calculator=calculator.distance). On opening, only x₁ = 0 and y₁ = 0 are pre-filled; the other four coordinates are empty and treated as 0, so the initial distance shown is 0—fill in all six coordinates. 02 Enter the two points for plane problems set both z₁ and z₂ to 0; for 3D problems enter the actual heights. Coordinates may be negative or decimal. 03 Read the distance “Distance d”, marked “computed”, updates live, to at most 8 decimal places with trailing zeros removed. 04 Read the midpoint “Midpoint X” and “Midpoint Y” are the averages of the corresponding endpoint coordinates; for 3D problems take the z z z midpoint as ( z 1 + z 2 ) / 2 (z_1 + z_2)/2 ( z 1 + z 2 ) /2 yourself. 05 Check swap the two points and neither the distance nor the midpoint changes; enter identical coordinates for both points and the distance should be 0.
Worked examples All four examples were recomputed by the engine’s distance compute routine; the display convention is at most 8 decimal places with trailing zeros removed.
Example 1: origin to (3, 4, 12)
Inputs: ( 0 , 0 , 0 ) (0, 0, 0) ( 0 , 0 , 0 ) and ( 3 , 4 , 12 ) (3, 4, 12) ( 3 , 4 , 12 ) .
Δ x = 3 \Delta x = 3 Δ x = 3 , Δ y = 4 \Delta y = 4 Δ y = 4 , Δ z = 12 \Delta z = 12 Δ z = 12 .
Sum of squares 9 + 16 + 144 = 169 9 + 16 + 144 = 169 9 + 16 + 144 = 169 .
d = 169 = 13 d = \sqrt{169} = 13 d = 169 = 13 ; midpoint ( 1.5 , 2 , 6 ) (1.5, 2, 6) ( 1.5 , 2 , 6 ) .
Interface shows: distance 13 , midpoint X 1.5 , midpoint Y 2 . This example can be seen as the Pythagorean theorem applied twice: the base diagonal is 3 2 + 4 2 = 5 \sqrt{3^2 + 4^2} = 5 3 2 + 4 2 = 5 , which forms a new right triangle with the height 12, giving 5 2 + 12 2 = 13 \sqrt{5^2 + 12^2} = 13 5 2 + 1 2 2 = 13 .
Figure 1: the 3D distance is the space diagonal of a box, obtained by applying the Pythagorean theorem once more to the base diagonal
Example 2: (1, 2) and (4, 6) in the plane
Inputs: ( 1 , 2 , 0 ) (1, 2, 0) ( 1 , 2 , 0 ) and ( 4 , 6 , 0 ) (4, 6, 0) ( 4 , 6 , 0 ) .
Δ x = 3 \Delta x = 3 Δ x = 3 , Δ y = 4 \Delta y = 4 Δ y = 4 , Δ z = 0 \Delta z = 0 Δ z = 0 .
d = 9 + 16 = 5 d = \sqrt{9 + 16} = 5 d = 9 + 16 = 5 ; midpoint ( ( 1 + 4 ) / 2 , ( 2 + 6 ) / 2 ) = ( 2.5 , 4 ) \big((1+4)/2, (2+6)/2\big) = (2.5, 4) ( ( 1 + 4 ) /2 , ( 2 + 6 ) /2 ) = ( 2.5 , 4 ) .
Interface shows: distance 5 , midpoint X 2.5 , midpoint Y 4 . For comparison, walking along the grid (3 across, then 4 up) gives a Manhattan distance of 7; the straight-line distance 5 is never larger.
Example 3: 3D points with negative coordinates
Inputs: ( − 2 , 3 , 1 ) (-2, 3, 1) ( − 2 , 3 , 1 ) and ( 4 , − 1 , 5 ) (4, -1, 5) ( 4 , − 1 , 5 ) .
Δ x = 4 − ( − 2 ) = 6 \Delta x = 4 - (-2) = 6 Δ x = 4 − ( − 2 ) = 6 , Δ y = − 1 − 3 = − 4 \Delta y = -1 - 3 = -4 Δ y = − 1 − 3 = − 4 , Δ z = 5 − 1 = 4 \Delta z = 5 - 1 = 4 Δ z = 5 − 1 = 4 .
Sum of squares 36 + 16 + 16 = 68 36 + 16 + 16 = 68 36 + 16 + 16 = 68 .
d = 68 = 2 17 ≈ 8.2462 d = \sqrt{68} = 2\sqrt{17} \approx 8.2462 d = 68 = 2 17 ≈ 8.2462 ; midpoint ( 1 , 1 , 3 ) (1, 1, 3) ( 1 , 1 , 3 ) .
Interface shows: distance 8.24621125 , midpoint X 1 , midpoint Y 1 . The minus sign vanishes on squaring—distance cares only about the size of the coordinate differences.
Example 4: diagonals of the unit square and unit cube
Inputs ( 0 , 0 , 0 ) (0, 0, 0) ( 0 , 0 , 0 ) and ( 1 , 1 , 0 ) (1, 1, 0) ( 1 , 1 , 0 ) : distance 1.41421356 (2 \sqrt 2 2 ). Inputs ( 0 , 0 , 0 ) (0, 0, 0) ( 0 , 0 , 0 ) and ( 1 , 1 , 1 ) (1, 1, 1) ( 1 , 1 , 1 ) : distance 1.73205081 (3 \sqrt 3 3 ). The diagonal of the n n n -dimensional unit cube is n \sqrt n n —the higher the dimension, the longer the diagonal relative to the edge.
The inputs of Example 1 can be entered directly into the panel to reproduce it; change z₂ to 0 and the distance drops back to the planar 5.
Principles and derivation From the Pythagorean theorem to the distance formula
For two points P 1 ( x 1 , y 1 ) P_1(x_1, y_1) P 1 ( x 1 , y 1 ) and P 2 ( x 2 , y 2 ) P_2(x_2, y_2) P 2 ( x 2 , y 2 ) in the plane, draw a horizontal line through P 1 P_1 P 1 and a vertical line through P 2 P_2 P 2 ; they meet at Q ( x 2 , y 1 ) Q(x_2, y_1) Q ( x 2 , y 1 ) . P 1 Q P_1 Q P 1 Q has length ∣ Δ x ∣ |\Delta x| ∣Δ x ∣ , Q P 2 Q P_2 Q P 2 has length ∣ Δ y ∣ |\Delta y| ∣Δ y ∣ , and the two are perpendicular, so P 1 P 2 P_1 P_2 P 1 P 2 is the hypotenuse of a right triangle: d 2 = Δ x 2 + Δ y 2 d^2 = \Delta x^2 + \Delta y^2 d 2 = Δ x 2 + Δ y 2 . This is the Pythagorean theorem in different language.
In three dimensions apply it once more: within the horizontal plane z = z 1 z = z_1 z = z 1 the base diagonal is Δ x 2 + Δ y 2 \sqrt{\Delta x^2 + \Delta y^2} Δ x 2 + Δ y 2 ; it is perpendicular to the vertical Δ z \Delta z Δ z , so d 2 = ( Δ x 2 + Δ y 2 ) + Δ z 2 d^2 = (\Delta x^2 + \Delta y^2) + \Delta z^2 d 2 = ( Δ x 2 + Δ y 2 ) + Δ z 2 . Each additional mutually perpendicular dimension adds one more squared term under the root—which is why the Euclidean distance in n n n dimensions is ∑ i ( Δ x i ) 2 \sqrt{\sum_i (\Delta x_i)^2} ∑ i ( Δ x i ) 2 , and the “distance” between two 100-dimensional feature vectors in data science uses the very same formula.
Why the midpoint is the average
Travelling along the segment from P 1 P_1 P 1 to P 2 P_2 P 2 , each coordinate changes linearly from x 1 x_1 x 1 to x 2 x_2 x 2 ; halfway along, every coordinate is exactly midway between the two ends, i.e. ( x 1 + x 2 ) / 2 (x_1 + x_2)/2 ( x 1 + x 2 ) /2 . More generally, the point at fraction t t t along the segment is P 1 + t ( P 2 − P 1 ) P_1 + t\,(P_2 - P_1) P 1 + t ( P 2 − P 1 ) ; t = 1 / 2 t = 1/2 t = 1/2 gives the midpoint and t = 1 / 3 t = 1/3 t = 1/3 a point of trisection—the geometric form of proportion and linear interpolation.
What a “distance” must satisfy
In mathematics, any function satisfying four conditions is called a distance (a metric): non-negativity; zero when and only when the points coincide; symmetry (d ( P , Q ) = d ( Q , P ) d(P, Q) = d(Q, P) d ( P , Q ) = d ( Q , P ) ); and the triangle inequality (d ( P , R ) ≤ d ( P , Q ) + d ( Q , R ) d(P, R) \le d(P, Q) + d(Q, R) d ( P , R ) ≤ d ( P , Q ) + d ( Q , R ) —a detour is never shorter). Euclidean distance satisfies all four and is the precise statement of the intuition that a straight line is shortest. The triangle inequality explains why in Example 2 the Manhattan distance 7 exceeds the straight-line distance 5.
Beyond Euclidean distance
Manhattan distance ∣ Δ x ∣ + ∣ Δ y ∣ |\Delta x| + |\Delta y| ∣Δ x ∣ + ∣Δ y ∣ : the distance travelled when movement is restricted to a grid (chessboards, city blocks, some circuit routing).
Chebyshev distance max ( ∣ Δ x ∣ , ∣ Δ y ∣ ) \max(|\Delta x|, |\Delta y|) max ( ∣Δ x ∣ , ∣Δ y ∣ ) : the number of moves a king needs between two squares in chess.
Great-circle distance : the shortest path between two places along the Earth’s surface; latitude and longitude must first be converted, the formula is the haversine of spherical trigonometry, and this calculator does not do it. Over small areas (within a few tens of kilometres), latitude and longitude can be scaled to planar metric coordinates and Euclidean distance used as an approximation.
Like Euclidean distance, all of these satisfy the four properties of a metric, but they give different values; which one to use depends on “how you are allowed to move”.
Relationship to slope
Δ x \Delta x Δ x and Δ y \Delta y Δ y determine two quantities at once: the square root of the sum of their squares is the distance, and their ratio is the slope . In the same right triangle, distance reads the hypotenuse and slope reads the ratio of the two legs.
Assumptions
Cartesian coordinates : the three axes are mutually perpendicular with equal scales. Skewed or unequally scaled coordinates (such as latitude/longitude or logarithmic axes) cannot be substituted directly.
Euclidean space : “distance” means the length of the straight segment between the points, and space is flat.
One unit : all six coordinates use the same length unit; the distance is in that unit.
z = 0 means the plane : for 2D problems set both z₁ and z₂ to 0 (or to the same number).
All six coordinates must be filled in : the panel pre-fills only x₁ and y₁ and treats the rest as 0; make them all “input”.
Midpoint outputs x and y only : compute the z midpoint by hand as ( z 1 + z 2 ) / 2 (z_1 + z_2)/2 ( z 1 + z 2 ) /2 .
Scope and limitations
Can calculate the Euclidean distance and the x, y midpoint of any two points in 2D or 3D Cartesian coordinates; results to at most 8 decimal places.
Approximate only when coordinates come from measurement, the error in the distance is roughly the sum of the coordinate errors projected onto the connecting line; when small areas of the Earth’s surface are approximated by planar coordinates, the error grows with the extent.
Cannot calculate distance along a grid or road, great-circle distance on the Earth, distance from a point to a line or plane, or the shortest route through several points.
Does not output the z midpoint, a bearing or a direction vector; convert units; or judge whether the inputs are sensible. Numerics extremely large coordinates (such as 10 200 10^{200} 1 0 200 ) overflow to infinity when squared; everyday magnitudes are unaffected.
Common mistakes
Filling in only two coordinates : the panel pre-fills only x₁ and y₁ and treats the rest as 0, so the distance 0 shown at that point is meaningless. Fill in all six fields.
Forgetting to square and take the root : Δ x + Δ y \Delta x + \Delta y Δ x + Δ y is not a distance; 3 + 4 = 7 is the Manhattan distance, the Euclidean distance is 5.
Being put off by minus signs : a negative coordinate difference is fine; it becomes positive when squared. In Example 3, Δ y = − 4 \Delta y = -4 Δ y = − 4 contributes + 16 +16 + 16 .
Using latitude and longitude directly as coordinates : one degree of longitude is about 111 km at the equator but only about 56 km at 60° N; substituting directly distorts badly. Convert to planar metric coordinates first, or use the great-circle formula.
Mixing coordinate units : x in metres and y in centimetres gives a meaningless result. Use one unit.
Mistaking the midpoint for half the distance : the midpoint is a point (coordinates); half the distance is a length. They are not the same kind of quantity.
Expecting a z midpoint : the engine outputs only the x and y midpoint; compute z by hand.
Typical use cases Teaching: the Pythagorean theorem in 3D First use (0, 0, 0)–(3, 4, 0) to get 5, then change z₂ to 12 to get 13, so students see the two steps: base diagonal first, then space diagonal.
Drawings, screens and CAD The straight-line distance between two dimension points or pixels; the midpoint as an axis of symmetry or a label position. A downward-pointing y axis on screens does not affect the distance.
Machinery and robotics The magnitude of an end-effector’s displacement between two poses, the centre distance between two holes, the spacing between two points in a 3D scan point cloud.
Data analysis The Euclidean distance between two samples in feature space underlies k-nearest-neighbour, clustering and similar algorithms; this calculator’s 3D formula is its low-dimensional version.
FAQ Why does the distance show 0 when I open the panel? Only x₁ and y₁ are pre-filled; the other coordinates are empty and treated as 0, so both points sit at the origin. Fill in all six coordinates and the correct result appears.
What do I enter for z in a 2D problem? Enter 0 for both z values (or the same number); Δ z = 0 \Delta z = 0 Δ z = 0 does not affect the result.
Can it compute the distance between latitude/longitude pairs? Not directly. Latitude and longitude are angular coordinates on a sphere; convert them to planar metric coordinates first (small areas) or use the great-circle distance formula (large areas).
Where is the midpoint Z? The engine does not output the z midpoint. Compute ( z 1 + z 2 ) / 2 (z_1 + z_2)/2 ( z 1 + z 2 ) /2 by hand; in Example 1 the z midpoint is 6.
What is the difference between distance and displacement? This calculator gives the straight-line length between two points, a scalar. Displacement also has a direction: the direction vector is ( Δ x , Δ y , Δ z ) (\Delta x, \Delta y, \Delta z) ( Δ x , Δ y , Δ z ) , and its length is the distance given here.
Why isn’t the result an integer? For most coordinate combinations the distance is irrational (e.g. 2 \sqrt 2 2 , 68 \sqrt{68} 68 ); only Pythagorean triples such as 3-4-5 and 5-12-13 give integers. The interface keeps at most 8 decimal places.
References and further reading
The distance definition in the CalcX engine source src/data/formulas.ts (d = Δ x 2 + Δ y 2 + Δ z 2 d = \sqrt{\Delta x^2 + \Delta y^2 + \Delta z^2} d = Δ x 2 + Δ y 2 + Δ z 2 , midpoint X / Y as the average of the endpoint coordinates); every figure on this page was recomputed by that engine.
Wikipedia, Euclidean distance (访问日期:2026-09-08)—2D, 3D and n n n -dimensional formulas, metric properties.
Wikipedia, Midpoint (访问日期:2026-09-08)—the midpoint formula and its generalisations.
Wikipedia, Taxicab geometry (访问日期:2026-09-08)—Manhattan distance compared with Euclidean distance.
Stewart, J. Calculus: Early Transcendentals , 8th ed. Cengage, 2016. §12.1 “Three-Dimensional Coordinate Systems”—derivation of the 3D distance formula and the midpoint.
Privacy All inputs and calculations run inside your browser and are never uploaded to a server. The text on this page is static content; it neither contains nor records any user input.
Sources & review
Reviewed by CalcX 编辑组
Updated 2026-09-09
Open Distance and Midpoint Calculator (2D/3D Euclidean Distance) in CalcX