Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

1.5: Length and distance

In Chapter 1.4, we learned how to add and scale vectors. Now, let’s look more closely at their geometry. How do we find the length of a vector? And how can we use vectors to find the distance between two points?


Length of a vector

Review: The Pythagorean theorem

Throughout Chapter 1.5, we will refer to the familiar Pythagorean theorem. Recall, this says that if cc is the length of the hypotenuse (the longest side) of a right triangle, and aa and bb are the side lengths of its two legs, then

a2+b2=c2.a^2 + b^2 = c^2.

For example, a right triangle with legs of lengths 5 and 12 has a hypotenuse of length 52+122=169=13\sqrt{5^2+12^2}=\sqrt{169}=13.

Image produced in Jupyter

Example in ℝ²

Now for our main point: finding the length of a vector. Let’s start with the vector

v⃗=[34].\vec v = \begin{bmatrix} {\color{#3d81f6} 3} \\ {\color{orange} 4} \end{bmatrix}.

To draw v⃗\vec v from the origin, we move 3{\color{#3d81f6} 3} units to the right and 4{\color{orange} 4} units up. The resulting arrow is the hypotenuse of a right triangle. The Pythagorean theorem tells us its length is

32+42=25=5.\sqrt{{\color{#3d81f6} 3}^2 + {\color{orange} 4}^2} = \sqrt{25} = 5.
Image produced in Jupyter

We use norm and magnitude as other words for length, and write the norm of v⃗\vec v as ∥v⃗∥\lVert \vec v \rVert. Here, ∥v⃗∥=5\lVert \vec v \rVert = 5.

Example in ℝ³

What if we add a third component? Consider

v⃗=[34−2].\vec v = \begin{bmatrix} {\color{gray} 3} \\ {\color{gray} 4} \\ {\color{orange} -2} \end{bmatrix}.
Loading...

Drag the figure above to see the two right triangles mentioned below from different viewpoints.

We can find its length by applying the Pythagorean theorem twice. First, move 3{\color{gray} 3} units in the xx direction and 4{\color{gray} 4} units in the yy direction. The blue diagonal in the xyxy-plane has length

32+42=5.\sqrt{{\color{gray} 3}^2 + {\color{gray} 4}^2} = {\color{#3d81f6} 5}.

The third component is −2{\color{orange} -2}, so we move 2{\color{orange} 2} units downward. This vertical segment is perpendicular to the xyxy-plane, so we get another right triangle. Its legs have lengths 5{\color{#3d81f6} 5} and 2{\color{orange} 2}, and its hypotenuse is our original vector. Therefore,

∥v⃗∥=52+22=29.\lVert \vec v \rVert = \sqrt{{\color{#3d81f6} 5}^2 + {\color{orange} 2}^2} = \sqrt{29}.

Notice that this is the same as taking the square root of the sum of the squares of all three components:

∥v⃗∥=32+42+(−2)2.\lVert \vec v \rVert = \sqrt{{\color{gray} 3}^2 + {\color{gray} 4}^2 + {\color{orange} (-2)}^2}.

Formal definition

The same pattern gives us a definition for any number of components.

As another example,

∥[−120−2]∥=(−1)2+22+02+(−2)2=9=3.\left\lVert \begin{bmatrix} -1 \\ 2 \\ 0 \\ -2 \end{bmatrix} \right\rVert = \sqrt{(-1)^2 + 2^2 + 0^2 + (-2)^2} = \sqrt{9} = 3.

This vector has four components, but its length is 3. Those are different quantities! This is a vector in R4\mathbb{R}^4, which means we can’t visualize it, but we still measure its length by this definition.


Scaling

What happens to a vector’s length when we scale it? If v⃗{\color{#3d81f6} \vec v} has length 5, then 2v⃗2{\color{#3d81f6} \vec v} has length 10. So does −2v⃗-2{\color{#3d81f6} \vec v}: the minus sign reverses the direction, but the arrow is still twice as long.

Why the absolute value in the last property? The length formula squares each component, so a factor of c{\color{orange} c} contributes c2{\color{orange} c}^2 under the square root. Taking the square root gives c2=∣c∣\sqrt{{\color{orange} c}^2}=|{\color{orange} c}|. The sign affects the direction, but the length stays nonnegative.

For now, to find the length of a linear combination such as 2u⃗−v⃗2{\color{orange} \vec u} - {\color{#3d81f6} \vec v}, compute the vector first, then take its norm.


The triangle inequality

Notice something in the earlier activity. In Activity 1, we found that ∥u⃗+v⃗∥=6\lVert\vec u+\vec v\rVert=6, while ∥u⃗∥+∥v⃗∥=10+210\lVert\vec u\rVert+\lVert\vec v\rVert=10+2\sqrt{10}. The length of the sum is less than the sum of the lengths! This is an example of the triangle inequality.

Let’s describe this another way. Imagine traveling from point AA to point BB, then from point BB to point CC. Let u⃗{\color{orange} \vec u} and v⃗{\color{#3d81f6} \vec v} represent those two displacements, respectively. The direct displacement from AA to CC is the sum of the two vectors: u⃗+v⃗{\color{orange} \vec u} + {\color{#3d81f6} \vec v}.

Image produced in Jupyter

Key idea: The straight path cannot be longer than the path through BB. We can state this formally.

The two sides can be equal. For example, if we travel 3{\color{orange} 3} meters east and then another 4{\color{#3d81f6} 4} meters east, our total displacement has length 7 meters. But if we change direction along the way, the direct route is shorter.

The picture explains the inequality in two dimensions. It also holds in Rn\mathbb{R}^n, for any number of components. We’ll use this fact without proving the general case here.


Distance between points

To find the distance between two points, we find the length of the vector that connects them!

Example in ℝ²

Consider the points B=(−2,4){\color{orange} B}={\color{orange} (-2,4)} and A=(5,−1){\color{#3d81f6} A}={\color{#3d81f6} (5,-1)}. The vector d⃗{\color{black} \vec d} from B{\color{orange} B} to A{\color{#3d81f6} A} describes the displacement from one point to the other.

Image produced in Jupyter

To find d⃗{\color{black} \vec d}, subtract the starting coordinates from the ending coordinates:

d⃗=[5−(−2)−1−4]=[7−5].{\color{black} \vec d}=\begin{bmatrix}{\color{#3d81f6} 5}-{\color{orange} (-2)}\\{\color{#3d81f6} -1}-{\color{orange} 4}\end{bmatrix} ={\color{black} \begin{bmatrix}7\\-5\end{bmatrix}}.

The distance between the points is the length of this vector:

∥d⃗∥=72+(−5)2=74 units≈8.60 units.\lVert {\color{black} \vec d}\rVert=\sqrt{{\color{black} 7}^2+{\color{black} (-5)}^2}={\color{black} \sqrt{74}}\text{ units}\approx{\color{black} 8.60}\text{ units}.

A path between these points may take a detour and be longer. The length of d⃗\color{black} \vec d gives the straight-line distance between the endpoints.

We sometimes use points and vectors interchangeably in coordinate calculations, but they play different roles: a point specifies a fixed position, while a vector describes a displacement. For example, B{\color{orange} B} is a particular location in the plane, while d⃗{\color{black} \vec d} describes moving 7{\color{black} 7} units to the right and 5{\color{black} 5} units down, regardless of where we start.

The same method works with any number of coordinates: subtract corresponding coordinates, then take the norm. Reversing the direction gives the opposite displacement, −d⃗-{\color{black} \vec d}, but the same distance, since ∥−d⃗∥=∥d⃗∥\lVert-{\color{black} \vec d}\rVert=\lVert{\color{black} \vec d}\rVert.

Example in ℝ³

Consider the points P=(2,−3,0)P=(2,-3,0) and Q=(−2,3,7)Q=(-2,3,7).

The displacement from PP to QQ is

[−2−23−(−3)7−0]=[−467].\begin{bmatrix}-2-2\\3-(-3)\\7-0\end{bmatrix} =\begin{bmatrix}-4\\6\\7\end{bmatrix}.

The distance between the points is therefore

(−4)2+62+72=101 units≈10.05 units.\sqrt{(-4)^2+6^2+7^2}=\sqrt{101}\text{ units}\approx 10.05\text{ units}.

The first coordinate decreases by 4 units. The negative sign tells us which way to move; it does not make the distance negative. Its contribution to the squared length is (−4)2=16(-4)^2=16.


Unit vectors

In Chapter 1.4, we noticed that the vectors

[12],[24],[100200]\begin{bmatrix}1\\2\end{bmatrix},\qquad \begin{bmatrix}2\\4\end{bmatrix},\qquad \begin{bmatrix}100\\200\end{bmatrix}

all point in the same direction, even though their lengths are different. We didn’t yet have a precise way to describe their shared direction.

One way to describe a vector’s direction is to use a vector of length 1 that points in that direction. We call a vector of length 1 a unit vector.

Let’s start with v⃗=[12]{\color{#3d81f6} \vec v}=\begin{bmatrix}1\\2\end{bmatrix}. Its length is 12+22=5\sqrt{1^2+2^2}=\sqrt{5}. To give it length 1 while keeping its direction, we can scale it by 1/51/\sqrt{5}:

15[12]=[1525].\frac{1}{\sqrt{5}}\begin{bmatrix}1\\2\end{bmatrix} =\begin{bmatrix}\frac{1}{\sqrt{5}}\\[4pt]\frac{2}{\sqrt{5}}\end{bmatrix}.

The resulting vector has length 15⋅5=1\frac{1}{\sqrt{5}}\cdot\sqrt{5}=1, and the positive scale factor preserves its direction. This is the unit vector that describes the direction of v⃗{\color{#3d81f6} \vec v}!

The other two vectors have lengths 252\sqrt{5} and 1005100\sqrt{5}. Dividing each by its own length gives exactly the same unit vector. This makes their shared direction precise: two nonzero vectors point in the same direction exactly when they give the same unit vector after dividing by their lengths.

In general, to find a unit vector in the direction of any nonzero vector v⃗{\color{#3d81f6} \vec v}, divide it by its length:

v⃗∥v⃗∥=1∥v⃗∥v⃗.\frac{{\color{#3d81f6} \vec v}}{\lVert {\color{#3d81f6} \vec v} \rVert} =\frac{1}{\lVert {\color{#3d81f6} \vec v} \rVert}{\color{#3d81f6} \vec v}.

Dividing a vector by its length means multiplying every component by the same scalar, 1/∥v⃗∥1/\lVert{\color{#3d81f6} \vec v}\rVert. We call this process normalizing a vector. The scaling property tells us that the result has length 1:

∥v⃗∥v⃗∥∥=1∥v⃗∥∥v⃗∥=1.\left\lVert\frac{{\color{#3d81f6} \vec v}}{\lVert{\color{#3d81f6} \vec v}\rVert}\right\rVert =\frac{1}{\lVert{\color{#3d81f6} \vec v}\rVert}\lVert{\color{#3d81f6} \vec v}\rVert=1.

Since ∥v⃗∥>0\lVert{\color{#3d81f6} \vec v}\rVert>0, the scale factor is positive, so the direction stays the same. We cannot normalize 0⃗\vec 0, since doing so would require dividing by 0.

In Chapter 1.6, we’ll use vector lengths to help measure angles between vectors.