distance, in a straight line and along the grid
learning from examples
what it is
How far apart two points are. You can measure in a straight line, or along the grid, across and then up. Which way you measure can change which point is nearest.
A point on the plane is two numbers: how far across, then how far up. Take the points 1 across, 2 up and 3 across, 7 up. From the first to the second is 2 across and 5 up.
Along the grid, you walk the across and then the up: 2 and 5 make 7 steps. A car in a city of square blocks drives this way. Books call it Manhattan distance.
In a straight line, the across and the up are the two short sides of a right-angled triangle, and the distance is its long side. Square each short side and add the squares: 4 and 25 make 29. That sum is the long side's square, so the long side is the number whose square is 29, its square root, about 5.39. Books call it Euclidean distance.
The straight line is never longer than the walk. Take 2 and 5. The walk squared is 7 times 7, which is (2 + 5) times (2 + 5): 2 times 2, 5 times 5, and 2 times 5 twice. That is 4 + 25 + 20, so 49. The line squared is only 4 + 25, so 29. Any across and up work the same way, by multiplying out the brackets as in school algebra. The walk's square is the line's square plus twice the across times the up. Neither the across nor the up is below 0, so that extra is never below 0, and it is 0 only when one of them is 0. Then the two distances match, as in the table's last two rows. Neither length is below 0 either, so the bigger square belongs to the longer length: 7 against about 5.39.
| across | up | along the grid | in a straight line |
|---|---|---|---|
| 2 | 5 | 7 | 5.39 |
| 8 | 15 | 23 | 17 |
| 7 | 24 | 31 | 25 |
| 0 | 6 | 6 | 6 |
| 4 | 0 | 4 | 4 |
Each point belongs to a group, drawn as its shape. A new point has no group yet, and it joins the group of its nearest point. Below, move the new point and switch between the two ways of measuring. The table lists every point's distance, nearest first.
| shape | across, up | distance |
|---|---|---|
| triangle | 6, 6 | 2.83 |
| square | 4, 1 | 3 |
| circle | 1, 9 | 5.83 |
The new point stands at 4, 4. Its nearest point is 2.83 away in a straight line. So it becomes a triangle.
With scripts on, you can move the new point with two sliders or by pressing on the plane, and switch between the two ways of measuring. The picture, the table and this line change with it.
where the formulas come from
Each question is worked out one numbered line at a time. A line shows the move it makes, the line itself, and why the move is allowed. A line either follows from the lines above it, or brings in something the question needs, such as how the method works, a small fact about , or a result from another page, with its own reason. Press 'hide the lines, then guess each one' to cover the lines and uncover them one by one, guessing each before you see it.
the move: Pythagoras' rule
the line:why it is allowed: is the square of the straight line, the long side of a right-angled triangle with short sides and . Pythagoras' rule, from school geometry, says that square is the two short sides' squares added.
the move: work out each square
the line:why it is allowed: times is , and times is .
guess it, thenthe move: add them
the line:why it is allowed: 64 and 225 make 289.
guess it, thenthe move: take the root last
the line:why it is allowed: times is . Minus times minus is too, but a distance is never below 0, so the line is .
guess it, then
try it with a small : at , line 1 gives , which you can work out by hand
the move: across, then up
the line:why it is allowed: is the walk along the grid, the across added to the up.
the move: add them
the line:why it is allowed: 8 and 15 make 23, so the walk is , against in a straight line.
guess it, then
try it with a small : at , line 1 gives , which you can work out by hand
the move: the walk
the line:3 across and 3 up in a straight line, about 4.24 long. Along the grid the walk is 6, about 1.41 times as long. why it is allowed: Along the grid the walk is the across and the up added.
the move: the two squares, one over the other
the line:why it is allowed: is the walk's square over the straight line's square. The line itself is a root, so compare squares first and take the root last. For 3 and 3, the walk's square is 36, the line's is 18, and 36 over 18 is 2. The walk is by line 1, and the line's square is and added, by Pythagoras' rule as in question 1.
guess it, thenthe move: work out the square
the line:why it is allowed: times is .
guess it, thenthe move: add the squares
the line:why it is allowed: and make .
guess it, thenthe move: cancel
the line:why it is allowed: is above and below, and it is not 0, since is at least 1.
guess it, thenthe move: divide
the line:why it is allowed: 4 over 2 is 2.
guess it, thenthe move: take the root last
the line:why it is allowed: The walk's square over the line's square is the walk over the line, squared. For 3 and 3, 6 over 4.24 is about 1.41, and 1.41 squared is about 2. Both lengths are above 0, so the walk over the line is the root of , the number whose square is 2.
guess it, then
try it with a small : at , line 2 gives , which you can work out by hand
a worked example
Which of two points is nearest to the new point at 4 across, 4 up, a triangle at 6, 6 or a square at 4, 1?
- The triangle is 2 across and 2 up away. Along the grid that is 4. In a straight line, across and up are both 2, and 2 squared is 4, so the squares are 4 and 4, which make 8. Its root is about 2.83.
- The square is 0 across and 3 down. Along the grid that is 3, and in a straight line it is 3 too, since one side is 0.
- In a straight line the triangle is nearer, 2.83 against 3. Along the grid the square is nearer, 3 against 4.
| point | across | up or down | along the grid | in a straight line |
|---|---|---|---|---|
| triangle at 6, 6 | 2 | 2 | 4 | 2.83 |
| square at 4, 1 | 0 | 3 | 3 | 3 |
the trap
check yourself
How far apart are 2 across, 3 up and 7 across, 10 up along the grid?
the answer
They are 5 across and 7 up apart, so 12.
And in a straight line?
the answer
25 and 49 make 74, so the root of 74, about 8.6.
From 0, 0, which is nearer in a straight line, 3, 3 or 0, 5? And along the grid?
the answer
In a straight line 3, 3 is about 4.24 away and 0, 5 is 5, so 3, 3. Along the grid 3, 3 is 6 and 0, 5 is 5, so 0, 5.