Vectors
TL;DR - What should you know?
- Vectors have direction and length, but no position
- How do you add/subtract vectors?
- How do you scale a vector by some factor ?
- How do you compute the length of a vector?
- How do you compute the dot product of two vectors (2 ways)?
- The dot product is commutative
- The dot product is bilinear:
- What orientations of two vectors with respect to each other result in what dot product values (positive, negative, zero)?
- What is the range of the dot product for two unit vectors (length )?
- What is the cross product and how to calculate it?
- What is the length of the result of the cross product?
- The cross product is anti-commutative
- The cross product is bilinear:
- The cross product with a multiple of itself is the zero vector.
A vector consists of just two properties: A direction and a length.
Usually, they are represented by an arrow. Note the "represented", as vectors do not have a position and any arrow you draw is just as good as another one with the same direction and length somewhere else.
In the following, vectors are written as small bold letters, for example the vector .
You can add two vectors and by drawing and then starting from 's tip. The result is the connection from the start of to the tip of . You can also draw first to arrive at the same conclusion. So vector addition is commutative: .
Subtraction is basically the same as subtraction. For , you do an addition but with inverted. So means flip around a vector.
You can scale a vector by some factor , by drawing it times longer.
Now, you don't usually calculate anything by drawing arrows. Instead, you will pin down a coordinate system and associate a vector with the coordinates that represent it in that system.
We will write the components of the vector as subscripts, either as numbers denoting their index or as their name, whichever is more convenient. For example, the three components of a 3D vector are or .
Vectors will be written as column vectors, that is they are written in a column:
Addition and subtraction is straightforward: Add or subtract the corresponding coordinates of each vector representation. Scaling is computed, by multiplying each coordinate with the scaling factor.
The length of a 2D vector, denoted by vertical lines left and right can be computed by the Pythagorean theorem: The vector is the hypotenuse of a triangle with sides and .
For vectors in higher dimensions, you can just apply Pythagoras multiple times and get the general formula:
A vector with length is called a unit vector or a normalized vector.
You will also often see the expression (sometimes written as ), which is just the squared length. It looks like this:
As it doesn't involve a square root, it is easier to compute and work with mathematically. So if you only care about whether (or ) then you can just replace the length with the squared length and save some computations.
The following shows the square lengths and highlights the relation to the Pythagorean theorem.
Now one thing that is missing is multiplication and division for vectors. The reason for that is that there is no definition that satisfies all properties of what we want multiplication or division to do.
There are two operations, that at least have the name product: The dot product and the cross product.
Both and especially the dot product are incredibly important operations.
Let's start with the dot product. If you want to know more about it, you can also have a look at this page.
The dot product is defined in two ways:
is the (smallest) angles between the two vectors.
You can try for yourself to show that these are equivalent by drawing two vectors in 2D and fiddling around with geometry, it is a bit tedious but gets you to there.
You can think about the first version as something you use to calculate the value of the dot product and the second one to do some reasoning about angles (this is a simplification, so exceptions obviously apply).
From the definitions you can immediately see (by just plugging in) two important properties:
To understand the main interpretation, just assume for a moment, that , so we have two unit vectors. Then we have .
From the trigonometry section, we already know the geometric interpretation of , which we can use here. Choose either or as the -axis and the other one as the triangle hypotenuse. Then the dot product is just tip of that hypotenuse dropped orthogonally onto the -axis vector! Which one you choose doesn't matter, since you can switch the order in the dot product.
Now let's say that only vector is a unit vector. Then . This corresponds to scaling the hypotenuse (the radius of the circle)! The number tells you, how much of points into the direction of .
This is also called a projection and is the nice meaning of the dot product.
From this interpretation and the cosine formula we also get two important kinds of values of the dot product:
Especially the second property is important, as it means, that two perpendicular vectors have a dot product of .
The cross product is the second kind of product and contrary to the dot product, it results in a vector.
The vector results in a vector that is perpendicular to both and . Importantly, it obeys the right-hand rule. If you align your right index finger with and your middle finger with , then points in the direction of your thumb.
The usual coordinate system works pretty nicely with it. Just take the sequence and start at any point. Cross that base vector with the next and you get the following one (you start from the beginning after ): , and .
You compute it as:
Similar to the dot product, since there are only subtractions and multiplications, you can factor out scalar values and distribute the product:
Another important property is:
This is similar to the dot product! It corresponds to the area of the parallelogram spanned by the two vectors.
The cross product is anti-commutative, that means
We can use that to compute the value of any vector with a multiple of itself:
That last part comes from exchanging the order in the cross product, which in this case just looks the same but still adds the . The only way, a vector (or number) is equal to itself negated is, when it is zero. That means:
One last word about vectors and points. Vectors don't have a position, but points are just that position. We can "convert" a point to a vector by specifying its position vector. This vector points from the origin to the point.
That is why mostly it won't really matter if we are talking about points or vectors. There are some differences though, which will come up for example when considering translations.
With that, we covered the most important parts for now of vectors.