Skip to content

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.

024681002468105.39
From 1 across, 2 up to 3 across, 7 up in a straight line. The segment is the long side of a triangle 2 across and 5 up, about 5.39 long.

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.

024681002468107
The same two points along the grid. The walk goes 2 across, then 5 up, so 7 steps.

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.

acrossupalong the gridin a straight line
2575.39
8152317
7243125
0666
4044
Five pairs of points, by how far across and how far up, with both distances. In the last two rows one side is 0, and the two distances match.

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.

02468100246810
shapeacross, updistance
triangle6, 62.83
square4, 13
circle1, 95.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.

A triangle, a square and a circle, and a new point at 4 across, 4 up. In a straight line the triangle is nearest, 2.83 away. Along the grid the square is, 3 away, and the triangle is 4. Each part of the plane is shaded by the group a new point there would join.

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 nn, 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.

question 1Two points stand 8n8n across and 15n15n up from each other, for any whole number nn from 1, so 8 and 15 when n is 1. How far apart are they in a straight line?
  1. the move: Pythagoras' rule

    the line:
    S=(8n)2+(15n)2S = (8n)^2 + (15n)^2

    why it is allowed: SS is the square of the straight line, the long side of a right-angled triangle with short sides 8n8n and 15n15n. Pythagoras' rule, from school geometry, says that square is the two short sides' squares added.

  2. the move: work out each square

    the line:
    S=64n2+225n2S = 64n^2 + 225n^2

    why it is allowed: 8n8n times 8n8n is 64n264n^2, and 15n15n times 15n15n is 225n2225n^2.

  3. the move: add them

    the line:
    S=289n2S = 289n^2

    why it is allowed: 64 and 225 make 289.

  4. the move: take the root last

    the line:
    the straight line is theroot of 289n2: 17n\begin{gathered} \text{the straight line is the} \\ \text{root of } 289n^2\text{: } 17n \end{gathered}

    why it is allowed: 17n17n times 17n17n is 289n2289n^2. Minus 17n17n times minus 17n17n is too, but a distance is never below 0, so the line is 17n17n.

try it with a small nn: at n=1n = 1, line 1 gives S=289S = 289, which you can work out by hand

question 2The same two points, 8n8n across and 15n15n up. How far apart are they along the grid?
  1. the move: across, then up

    the line:
    G=8n+15nG = 8n + 15n

    why it is allowed: GG is the walk along the grid, the across added to the up.

  2. the move: add them

    the line:
    G=23nG = 23n

    why it is allowed: 8 and 15 make 23, so the walk is 23n23n, against 17n17n in a straight line.

try it with a small nn: at n=1n = 1, line 1 gives G=23G = 23, which you can work out by hand

question 3When the across and the up are both nn, for any whole number nn from 1, how many times as long as the straight line is the walk?
  1. the move: the walk

    the line:
    n+n=2nn + n = 2n
    024681002468104.24
    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.

  2. the move: the two squares, one over the other

    the line:
    Q=(2n)2n2+n2Q = \frac{(2n)^2}{n^2 + n^2}

    why it is allowed: QQ 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 2n2n by line 1, and the line's square is n2n^2 and n2n^2 added, by Pythagoras' rule as in question 1.

  3. the move: work out the square

    the line:
    Q=4n2n2+n2Q = \frac{4n^2}{n^2 + n^2}

    why it is allowed: 2n2n times 2n2n is 4n24n^2.

  4. the move: add the squares

    the line:
    Q=4n22n2Q = \frac{4n^2}{2n^2}

    why it is allowed: n2n^2 and n2n^2 make 2n22n^2.

  5. the move: cancel n2n^2

    the line:
    Q=42Q = \frac{4}{2}

    why it is allowed: n2n^2 is above and below, and it is not 0, since nn is at least 1.

  6. the move: divide

    the line:
    Q=2Q = 2

    why it is allowed: 4 over 2 is 2.

  7. the move: take the root last

    the line:
    the walk is 2 timesthe line, about 1.41\begin{gathered} \text{the walk is } \sqrt{2} \text{ times} \\ \text{the line, about 1.41} \end{gathered}

    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 QQ, the number whose square is 2.

try it with a small nn: at n=1n = 1, line 2 gives Q=2Q = 2, 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?

  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.
  2. 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.
  3. In a straight line the triangle is nearer, 2.83 against 3. Along the grid the square is nearer, 3 against 4.
pointacrossup or downalong the gridin a straight line
triangle at 6, 62242.83
square at 4, 10333
The two points against the new point at 4, 4. The nearest is the triangle in a straight line and the square along the grid.

the trap

check yourself

  1. 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.

  2. And in a straight line?

    the answer

    25 and 49 make 74, so the root of 74, about 8.6.

  3. 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.