IMAGE, AUDIO AND COORDINATE WORKSHEETS

Checking a three-dimensional distance with no height change

When two points share the same third coordinate, the straight-line distance in space equals the distance in the plane. A difference in that coordinate adds one more squared term.

One formula for any number of dimensions

The 3D distance calculator returns the square root of the sum of three squared differences: (x2 - x1)², (y2 - y1)² and (z2 - z1)². It is the Pythagorean theorem applied once in the plane and once more with the third axis. If the z coordinates are equal, the third difference is zero, its square is zero, and the formula collapses to the familiar two-dimensional distance. This is a useful property because it lets you check a spatial result against a plane result you already trust. When the two disagree for points at the same height, an input has been mistyped or the coordinates were not in the same system.

The planar control: a 3-4-5 segment

Start with the points (0, 0, 7) and (3, 4, 7). The differences are 3, 4 and 0, so the squared terms add to 9 + 16 + 0 = 25, and the distance is 5. The value 7 is irrelevant to the answer, since both points sit at the same height and the third difference cancels it. Changing 7 to 0, to 100 or to -20 leaves the distance at 5. The control confirms two things at once: the spatial tool agrees with the plane, and a shift of both points along the third axis does not change the distance between them.

Adding a perpendicular difference

Now keep the first two coordinates and change the second point to (3, 4, 12) with the first point at (0, 0, 0). The differences are 3, 4 and 12, the squares add to 9 + 16 + 144 = 169, and the distance is 13. The planar segment of length 5 is the base of a right triangle, the third difference of 12 is its height, and the space distance is the hypotenuse. The numbers 5, 12 and 13 form a Pythagorean triple, so the result is a whole number that is easy to verify by hand. A related set is 8, 15 and 17, and the triple 7, 24 and 25, either of which can serve as the planar base or the vertical leg in a test. In general the space distance is the square root of the planar distance squared plus the vertical difference squared.

Other whole-number cases

Several other sets of differences give whole-number distances and make good tests. Differences of 2, 3 and 6 give 4 + 9 + 36 = 49, a distance of 7. Differences of 1, 2 and 2 give 1 + 4 + 4 = 9, a distance of 3. These are handy for checking a spreadsheet or a script, since a wrong formula rarely lands on a whole number by accident. A unit cube gives a different kind of check: the diagonal from (0, 0, 0) to (1, 1, 1) is the square root of 3, about 1.73205, which is not whole but is a well-known value to compare against.

A room-sized example with negative coordinates

Real coordinates are rarely tidy. Suppose a warehouse measures 20 meters by 15 meters by 8 meters and you want the longest straight line inside it, corner to opposite corner. The differences are 20, 15 and 8, so the squares total 400 + 225 + 64 = 689 and the distance is about 26.249 meters. Negative values work the same way. From (1, -1, 2) to (-3, 2, 14), the differences are -4, 3 and 12, whose squares sum to 16 + 9 + 144 = 169, so the distance is 13. Squaring removes the sign, which is why the order of the points does not matter. Swapping the two points gives the same differences with opposite signs, and the squares are identical.

Choosing which axis is the third

The labels x, y and z are arbitrary as far as the formula is concerned, so any axis can play the role of the third coordinate. In surveying or building plans, z is often height. In graphics software, y is frequently the upward axis and z points into or out of the screen. Because the three differences enter symmetrically, swapping the axis names does not change the distance. What does matter is that all three axes use the same unit. A table with x and y in meters and z in centimeters gives a wrong distance without any warning. If the third difference is 1,200 centimeters but is entered as 1,200 next to meter-based x and y, it dominates the sum and returns a distance near 1,200 instead of 13.

Straight-line distance is not travel distance

The result is the length of the straight segment between two points. A cable laid along walls, a path around furniture, a flight route that follows the curve of the earth and a road with bends all have longer lengths. The straight distance gives a lower bound for such routes, which is useful for checking that a measured or planned length is not impossibly short. If a planned cable run between the two warehouse corners is quoted at 24 meters, the 26.249 meter straight-line figure shows the quote cannot be right. The planar part alone is 25 meters, since the square root of 400 + 225 is 25, so even a run along the floor would need more than that, and adding the 8 meter rise brings the straight-line total to 26.249. Knowing that lower bound is often enough to catch an obviously mistaken measurement before material is ordered.

Geographic coordinates need conversion

Latitude, longitude and altitude are not Cartesian coordinates. Treating degrees as if they were equal-length units gives a wrong answer, because a degree of longitude spans a shorter ground distance at higher latitudes. For small areas, you can convert to a local system in meters first, using a projection or a local tangent plane, and then apply the formula. For long distances, geodesic methods that account for the shape of the earth are the right tool. The calculator described here assumes perpendicular axes with a common length unit and nothing else.

What the calculation does not cover

The tool computes one distance from six supplied numbers. It does not check that the points are inside a given structure, account for obstacles or measurement uncertainty, or convert units. If your positions come from instruments, their errors carry through: an error of 0.01 in a coordinate changes the distance by at most that amount when the point is displaced along the segment. Record the unit and coordinate system with every result.

Reproduce the checks

Matching third coordinates

Open the 3D Distance Calculator and enter:

First x coordinate
0
First y coordinate
0
First z coordinate
7
Second x coordinate
3
Second y coordinate
4
Second z coordinate
7

Expected output:

distance

5

The third-coordinate difference is zero.

Added perpendicular difference

Open the 3D Distance Calculator and enter:

First x coordinate
0
First y coordinate
0
First z coordinate
0
Second x coordinate
3
Second y coordinate
4
Second z coordinate
12

Expected output:

distance

13

The three differences form a five-twelve-thirteen control.

References and implementation scope

The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.

Sources

Related tasks