# Reza Nourai's Game Development Ramblings

Random discussions about game development. Particularly math, physics, collision detection/response, and performance.
Search Blogs

# Math Primer Series: Vectors III: Affine Spaces, Linear and Affine Combinations

### Math Primer Series: Vectors III: Affine Spaces, Linear and Affine Combinations

Rate This

In this chapter of our primer, we’ll examine affine spaces, and see what affine and linear combinations are. Furthermore, we can use these concepts to define some other related concepts, such as affine and linear dependency.

### Affine Space

An affine space can be thought of as any space containing points and vectors together, which follow the rules we established in the previous posts: any point plus a vector gives a point, and the difference of two points is a vector. The key is that affine spaces give us a way to correlate points to vectors, and vectors to points. Because an affine space is a single space that defines both points and vectors, we’re able to do things like add a vector to a point. However, we must follow the rules we discussed before. When defining the operations before, we actually assumed an affine space without explicitly calling it out.

What other properties do affine spaces have? Why do we care about them? Well, besides letting us define the basics of vector and point operations, they provide two other concepts which we’ll draw from. These are linear and affine combinations.

Linear Combinations

Using only vector addition and scalar multiplication, we can define a very powerful concept for vectors. Let’s examine Figure 1. On the left half, we see 2 vectors of varying lengths, but the same direction. On the right half, we see 2 vectors of varying lengths and different directions.

The important observation here is that for the pair of vectors on the left, u can be represented in terms of v and vice versa. For instance, if we know that u is twice as long as v, we can write u = 2v. This is what’s called a linear combination. If any vector can be represented in terms of adding scaled forms of other vectors, it is a linear combination of those vectors. The set of vectors are referred to as linearly dependent. This can be put into equation form:

Now, let’s examine the pair of vectors on the right. Here, we see that there’s no way we can express the vector u in terms of v. When a vector cannot be constructed as a linear combination of another vector (or set of vectors), they are called linearly independent.

Affine Combinations

What if we were to try and do the same thing with Points? We can certainly try and write the equation:

This is what we call an Affine combination, but how can that be? We know we can’t add points together. Well, it turns out if we impose the restriction that the sum of the coefficients equals 1, we can actually make this into a linear combination added to a point. Let’s follow through the math to see how this works:

Note that the differences of points we’re using on P1 – P(n-1) are really vectors, so this has become a linear combination (no restriction on coefficients) added to an origin point (P0). While this is useful to think about mathematically, I think looking at it visually helps to drive the concept home. See Figure 2.

Here, we have 3 points: A, B, and C. We wish to find a way to express the point D in terms of the other points (which would be the equivalent of expressing a vector in terms of other vectors). If we can define a vector from A to B (call it u), and another from A to C (call it v), then we can express the vector from A to D as a linear combination using the definition from above. In this case, it would become xu + yv. However, we are interested in finding the point D, not the vector from A to D. If we replace the vector with (D – A), and then add A to both sides of the equation we get our point D and we have an equation to express it in terms of the other points (the affine combination we were looking for). Let’s take a look at the equations:

We can generalize this equation to n points with the following form of the equation:

It is important to note that while the form above is convenient for thinking of the point in terms of an origin point and linear components, the proper form for an affine combination is the first one that we discussed:

For the curious, the coefficients in the affine combination equation are also called barycentric coordinates. If the vectors formed from the points are linearly independent, then the points P0 – Pn-1 are called affinely independent. We refer to an n-order set of affinely independent points as a simplex (See Figure 3).

Well, that’s it for this installment! We’ve discussed affine spaces, linear and affine combinations, and how we can use them to define linear and affine dependence. These concepts are a bit less obvious than the previous chapters, so please let me know if there was anything confusing in here I can help clear up or explain further.