Distance Calculator
A distance calculator finds the straight-line distance between coordinates.
This Distance Calculator covers four problems: two points, the three pairwise distances among three points, the shortest distance from a point to a straight line, and the shortest distance between two parallel lines. You can work in one, two, three, or four dimensions. Choose the type, enter the coordinates, and the distance appears with a diagram and the steps used to reach it.
Point-to-line and parallel-line calculations need a plane, so they are not available in one dimension. Distances between two or three points are available in every dimension.
How to Use the Distance Calculator
Set the calculation type first. The fields change to match it.
- Select 2 Points, 3 Points, Point and Straight Line, or 2 Parallel Lines.
- Choose 1D, 2D, 3D, or 4D. In 1D, only the two-point and three-point types are available.
- Select a coordinate unit: Unitless for plain numbers, or one physical length unit for every coordinate.
- Enter the coordinates that type asks for.
- 2 Points: Point 1 and Point 2. One dimension asks for X. Two dimensions add Y, three add Z, and four add W.
- 3 Points: Point 1, Point 2, and Point 3, with the same coordinates for the chosen dimension.
- Point and Straight Line: Point A and Point B define the line. Point P is the point you measure from. This type starts at 2D.
- 2 Parallel Lines: Point A and Point B define the first line. Point C lies on the second line, which copies the first line’s direction. This type also starts at 2D.
- Read the distance. Two points also show the coordinate differences. A point and a line, or parallel lines, show the closest point used to measure the gap, along with the diagram and the calculation steps.
Editing the distance changes one unlocked coordinate so the figure matches that value, keeping the current direction of the change when it can. Locked coordinates, an unreachable distance, or two equally valid positions leave the inputs unchanged and show a short note.
Types of Distance Calculations
Distance Between Two Points
Each point has one coordinate in 1D, two in 2D, three in 3D, and four in 4D. The result is the straight-line distance from Point 1 to Point 2. The separate axis changes are shown beside it.
Distance Between Three Points
Three points produce three distances, not one route:
- D12, from Point 1 to Point 2
- D13, from Point 1 to Point 3
- D23, from Point 2 to Point 3
In two dimensions the segments often form a triangle, but the points stay where you entered them, even when they lie on one line. In 3D and 4D each distance still uses every coordinate. In 1D the points stay at their real X values, and all three distances are still shown.
Distance From a Point to a Straight Line
Point A and Point B define a line that continues past both points. It is not the segment that stops at A and B. Point P is the point being measured.
The shortest distance is the perpendicular from P to the line. It meets the line at the closest point, the foot of the perpendicular, which may lie between A and B or beyond them. A distance of zero means P is on the line. Identical points A and B do not define a line. This calculation runs in 2D, 3D, and 4D, and not in 1D.
Distance Between Two Parallel Lines
The first line passes through A and B. The second passes through C and uses the same direction. You do not enter a second direction. The distance is the perpendicular from C to the first line.
This is not a tool for lines that point in different directions. If the lines lie on top of each other, the distance is zero and the result says they coincide. Parallel lines are available from 2D through 4D. Identical points A and B leave the direction undefined.
Understanding the Distance Formula
Each result is a Euclidean distance in the dimension you selected. One squared term is added for each axis.
Distance in One Dimension
On a number line there is only X.
d = |x₂ − x₁|
Order does not matter. From 3 to 8 the difference is 5. From 8 to 3 it is −5, and the distance is still 5. From −30 to 60 the distance is 90.
Distance in Two Dimensions
Both horizontal and vertical changes matter.
d = √[(x₂ − x₁)² + (y₂ − y₁)²]
ΔX is x₂ − x₁, and ΔY is y₂ − y₁. Positive means the second point is larger on that axis. Negative means it is smaller. Zero means the points share that coordinate. The slope calculator treats those same changes as a ratio. Here they become a length.
Point 1 = (3, 4) and Point 2 = (6, 8):
- ΔX = 6 − 3 = 3
- ΔY = 8 − 4 = 4
- d = √(3² + 4²) = √(9 + 16) = √25 = 5
The moves of 3 and 4 are the sides of a right triangle, and 5 is the hypotenuse. Adding 3 and 4 would follow the axes instead.
Distance in Three Dimensions
d = √[(x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²]
Point 1 = (3, 4, 5) and Point 2 = (6, 8, 10):
- ΔX = 3, ΔY = 4, and ΔZ = 5
- d = √(3² + 4² + 5²) = √50 ≈ 7.071068
The XY distance alone is 5, because it leaves out Z. If both Z values are equal, ΔZ is zero and the number matches the flat distance. The three-dimensional diagram still shows the Z axis, including when both values are 0.
Distance in Four Dimensions
d = √[(x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)² + (w₂ − w₁)²]
Point 1 = (1, 2, 3, 4) and Point 2 = (3, 4, 5, 6) change by 2 on every axis, so the distance is √(2² + 2² + 2² + 2²) = √16 = 4. All four changes are required. The diagram draws only the XY positions and says that Z and W are shown separately. That drawn segment has length √8, not the four-dimensional distance of 4.
Coordinate Units
Unitless is for coordinates with no physical length. The result is given in coordinate units, and those numbers are not treated as meters.
Every coordinate uses the one unit you select:
| Unit | Symbol |
|---|---|
| Millimeters | mm |
| Centimeters | cm |
| Meters | m |
| Kilometers | km |
| Inches | in |
| Feet | ft |
| Yards | yd |
| Miles | mi |
| Nautical miles | nmi |
Do not assign different units to different axes. With meters selected, the two-point example above is 5 m. Switching between physical units converts the coordinates already entered, so 1 m becomes 100 cm. Switching between Unitless and a physical unit does not convert the numbers. The same figures are read in the new unit.
Understanding the Results
Distance
Two points produce one straight-line distance. Three points produce the three pairwise distances. A point and a line, or two parallel lines, produce the perpendicular distance. Trailing zeros are dropped. A longer decimal is shown to six places, as with 7.071068 and 2.683282.
Coordinate Differences
For two points, the result lists the change on each axis in use:
- ΔX = x₂ − x₁
- ΔY = y₂ − y₁
- ΔZ = z₂ − z₁
- ΔW = w₂ − w₁
Positive means Point 2 is larger on that axis, negative means it is smaller, and zero means that axis adds nothing. One dimension has only ΔX. The other calculation types do not show this separate group. Their steps still include the arithmetic for the distance they calculate.
Distance Diagram
The diagram uses the coordinates you entered. For two points, Point 1 is the start and Point 2 is the end. The red segment is the measured distance. Gray dashed lines only show how a point meets the axes.
- 1D uses a number line, with separate measurement lines for three pairwise distances.
- 2D uses a horizontal X axis and a vertical Y axis.
- 3D uses one scale for X, Y, and Z. The red segment joins the points directly.
- 4D is an XY projection. Z and W are labeled separately, and the drawn segment is not the full distance.
A point and a line show the infinite line through A and B, Point P, the closest point, and the perpendicular. Only the two-dimensional figure marks that corner as a right angle. A right angle in 3D or 4D does not have to look like 90 degrees on the screen. Parallel lines share a direction, with the gap drawn between them.
Calculation Steps
The steps list the points, the coordinate changes, and the square-root expression, then the final distance. Three points get one set of steps for each pair. A line calculation also shows the line’s direction, the projection parameter, and the closest point.
The projection parameter places the closest point along the line from A toward B. Zero is at A and 1 is at B. A value between them lies on the segment. A value outside that range lies on the extension.
Examples of Distance Calculations
1. Two points in two dimensions
Point 1 = (3, 4) and Point 2 = (6, 8). Then ΔX = 3, ΔY = 4, and d = √(3² + 4²) = 5 coordinate units.
2. Two points in three dimensions
Point 1 = (3, 4, 5) and Point 2 = (6, 8, 10). Then d = √(3² + 4² + 5²) = √50 ≈ 7.071068 coordinate units. Using only X and Y would give 5.
3. Three pairwise distances
Point 1 = (0, 0), Point 2 = (3, 0), and Point 3 = (0, 4). The distances are 3, 4, and √(3² + 4²) = 5. They are the sides of a triangle, not a path of length 12. The area inside that triangle is a different measurement, which an area calculator can find.
4. Shortest distance from a point to a line
In meters, A = (0, 1), B = (4, 3), and P = (2, 5). The direction from A to B is (4, 2). The closest point on the infinite line is (3.2, 2.6), and the projection parameter is 0.8, so the foot lies between A and B.
d = √[(2 − 3.2)² + (5 − 2.6)²] = √7.2 ≈ 2.683282 m
The foot is kept when it falls outside the segment. For A = (0, 0), B = (2, 0), and P = (4, 3), the closest point is (4, 0), past B, and the distance is 3.
5. Shortest distance between parallel lines
A = (0, 0) and B = (4, 2) give the first line the direction (4, 2). C = (0, 3) places the second line on that same direction. The closest point on the first line is (1.2, 0.6).
d = √[(0 − 1.2)² + (3 − 0.6)²] = √7.2 ≈ 2.683282 coordinate units
Frequently Asked Questions
What is the Euclidean distance formula?
It is the straight-line distance between two points. In the plane it is √[(x₂ − x₁)² + (y₂ − y₁)²]. Each added dimension puts one more squared difference under the square root.
What is the difference between 2D and 3D distance?
Two dimensions use X and Y. Three dimensions also use Z. When the Z coordinates differ, the space distance is longer than the distance on the XY plane.
Can coordinates be negative?
Yes. A negative coordinate lies on the other side of the origin. Distance is calculated from the differences, so it is zero or positive.
What is the difference between distance to a line and distance to a line segment?
Distance to a line meets the infinite line through A and B, even past those points. Distance to the segment would stop at the nearer endpoint when the perpendicular falls outside that stretch. This calculator measures the infinite line.
How is the distance between parallel lines calculated?
Two points fix the first line. A third point fixes the second, which copies the first line’s direction. The distance is the perpendicular from that third point to the first line.
Can I calculate distance in four dimensions?
Yes. Enter X, Y, Z, and W. All four differences are used. The diagram shows only the XY projection and says that Z and W are shown separately.
What does Unitless mean in a distance calculator?
The coordinates are plain numbers, not a physical length. The result is reported in coordinate units. Choosing meters or another unit afterward does not convert those numbers. It reads them in the new unit.