CALENDAR AND GEOMETRY BOUNDARY CHECKS

Comparing a straight segment with an axis-aligned path

The distance between two points is the straight segment, found with the Pythagorean formula. A path that travels one horizontal leg and then one vertical leg adds the two differences and is longer.

Two lengths from the same coordinates

Given two points, the horizontal difference is dx = x2 minus x1 and the vertical difference is dy = y2 minus y1. The straight-line distance is sqrt(dx² + dy²), which the distance calculator evaluates with a hypotenuse function. An axis-aligned path, which moves along the x direction and then along the y direction, has length |dx| + |dy|. Both start and end at the same points, so both are valid answers to different questions. One asks for the shortest connection, the other for the length of a particular route that is restricted to horizontal and vertical movement, like walking along a grid of streets or a wire routed along a circuit board.

The three-four-five control

From (0, 0) to (3, 4) the differences are 3 and 4. The squares are 9 and 16, their sum is 25 and the square root is 5, so the straight segment has length 5. The two-leg path goes 3 units horizontally and 4 vertically, for a total of 7. The extra 2 is the cost of insisting on right-angle moves, paid once for every unit traveled along the second axis. The ratio, 7 / 5 = 1.4, is a handy number to remember. The 3-4-5 triple is the smallest set of whole numbers that satisfy the Pythagorean relation, which makes it a convenient control: the distance is an integer, so a typing slip shows up at once.

A longer example with a 6-8-10 triangle

Take (1, 2) to (7, 10). The differences are 6 and 8, so the distance is sqrt(36 + 64) = 10, and the axis-aligned path is 6 + 8 = 14. The detour adds 4, and the ratio is again 1.4 because the triangle is the 3-4-5 shape doubled in size. Scaling both differences by the same factor scales both lengths by that factor, so the ratio depends on the direction of the segment and not on its length. A different direction gives a different ratio, which is worth testing by moving to a segment that is not a Pythagorean triple. For (0, 0) to (2, 1), the differences are 2 and 1, the distance is sqrt(5), about 2.236, and the path is 3, a ratio of about 1.34.

How large the gap can get

The two lengths agree whenever one of the differences is zero. From (5, 5) to (5, 12) the distance is 7 and the path is 7 as well, because the segment is already vertical. The gap is widest for a diagonal at 45 degrees, where dx equals dy. From (0, 0) to (1, 1) the straight segment is sqrt(2), about 1.414, and the two-leg path is 2, so the path is about 41 percent longer. That is the most the two-leg path can exceed the straight segment: its length is never more than sqrt(2) times the distance. The 3-4-5 case, at 1.4, sits just under that limit.

Which one a task needs

Use the straight-line distance for a cable pulled across open space, the length of a diagonal brace, the separation between two points on a plan or any case where movement is unconstrained. Use the sum of the legs for movement along grid lines, such as city blocks in a regular street grid, aisles in a warehouse, or a pen plotter moving one axis at a time. This second measure is often called taxicab or Manhattan distance. Neither of the two is better. Reading a task description for words like route, aisle or grid tells you which applies, and choosing the wrong one is a common source of an answer that is too short or too long.

Coordinates must live on a flat plane

The formulas assume a flat Cartesian plane with the same unit on both axes. Plan coordinates in meters or feet satisfy this. Latitude and longitude in degrees do not, because a degree of longitude spans a shorter ground distance as latitude increases, so applying the Pythagorean formula to raw degrees gives a misleading number. If one axis is in feet and the other in meters, convert one first. A drawing with different scales on the two axes, such as a stretched chart, also distorts the result, so measure on the true-scale plan instead of the chart.

Using the basic calculator for the legs

The distance tool handles the Euclidean case in one step. For the two-leg path, adding the absolute differences is simple arithmetic, which is why the worked cases use the basic calculator with 3 plus 4. If coordinates run in different directions, take the absolute value of each difference before adding, since a negative dx would otherwise cancel part of dy. For example, from (4, 9) to (1, 5) the differences are minus 3 and minus 4, the distance is 5, and the path length is 3 + 4 = 7, the same as the control but traveled in the opposite direction.

Distances with a negative or fractional difference

The squares in the Euclidean formula remove any sign, so the order of the points does not matter: from (3, 4) to (0, 0) is also 5. The axis-aligned path needs the absolute values, as the previous section showed. Fractional coordinates work the same way. From (0.5, 1.5) to (3.5, 5.5) the differences are 3 and 4, so the distance is 5 and the path is 7, the control case shifted across the plane. Translating both points by the same amount never changes either length, which is why a plan can be moved to a new origin without affecting the measurements. Rotating the plan does change the axis-aligned length, though, while the straight distance stays fixed. A 3-4-5 segment rotated until it is vertical has a path length of 5, the same as its straight distance, and at intermediate angles the path length lies between 5 and about 7.07, the largest value at 45 degrees.

Limits of both numbers

The distance tool returns the length of a straight segment between two points and nothing else. It does not model street networks, obstacles, one-way restrictions or travel time. The two-leg length is a supplied ideal path with exactly one turn, not a navigation recommendation, and a real route may bend more than once and cost more. Both figures are geometric lengths in whatever unit the coordinates use. For planning an actual trip or cable run, measure on the real layout and allow for slack, bends and clearances.

Reproduce the checks

Straight segment

Open the Distance Calculator and enter:

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

Expected output:

distance

5

The Euclidean formula uses both squared differences.

Axis-aligned path

Open the Basic calculator and enter:

First number
3
Operation
add
Second number
4

Expected output:

Result

7

The path adds the two leg lengths.

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