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

**and vice versa. For instance, if we know that**

*v***is twice as long as**

*u***, we can write**

*v***= 2**

*u***. This is what’s called a**

*v**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

**. When a vector cannot be constructed as a linear combination of another vector (or set of vectors), they are called**

*v**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

**), 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 x**

*v***+ y**

*u***. 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:**

*v*

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 P_{0} – P_{n-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.

Can you explain further why the coefficients must add up to 1? The wikipedia page for affine combinations says the same thing, but again without much further explanation. I can accept this as a definition, but I'm having trouble making it stick in my brain, because nothing jumps to mind as to why this definition is significant.

Generally I'm having trouble separating affine combination from the general concept of linear combinations of vectors. If you restrict the coefficients of u and v such that they add up to one, doesn't that effectively mean that D must be colinear with the line-segment C<->B? D could be anywhere along that line if you used coefficients like 2 and -1, generalized to N and -(N-1). Yet your point D doesn't quite seem to fit that line – although who knows, your drawing might have an issue.

That's a great question, Brian. I actually missed a very important piece when describing affine combinations, thanks for pointing it out. I'll update the post in a bit when I get a chance to properly type it up, but the gist of it is this: The equation as I have it doesn't have the restriction that each coefficient equals one (though I incorrectly stated that it does). However, the canonical form of an affine combination is P = aoPo + a1P1 + a2P2 + … anPn. In that form, it *does* have this restriction of equaling 1. This can be shown by substituting ao = 1 – a1 – a2 … – an back into the equation and solving, which will lead you to exactly the equation I have above (P = Po + a1(P1-Po) …). Another way to think of it would be to try and factor our final equation back into the canonical form. Mathematically, it will end up with the restriction of all coefficients equaling 1. In the non-canonical form (the one I derive visually) you can think of the implicit a0 parameter automatically enforcing the restriction, so a1-an are free to be whatever you want.

Also, you're correct that when the remaining coefficients equal exactly 1 (implying a0 = 0), you get the outline of the corresponding simplex (triangle in this case). That's exactly how we arrive at these simplices, which we'll examine in further detail in later posts. I'm going to detour over to matrices first, but we'll eventually discuss simplices & barycentric coordinates in detail when we talk about certain collision detection algorithms.

Again, I'll type this up and edit the post. Thanks for pointing it out.

I think a discussion of barycentric coordinates will be really helpful, so I'll post about that next before continuing with matrices. It will serve 2 purposes I think are valuable now. Firstly, it should help in understanding affine combinations more clearly. Secondly, it will give us a chance to apply what we've covered to an actual game programming problem, specifically collision detection.

Hello Reza,

at the beginning of chapter "affine combinations" you write "Well, it turns out if we impose the restriction that the coefficients equal 1".

I think you forgot the word "sum" which would lead to "Well, it turns out if we impose the restriction that the sum of the coefficients equal 1".

Sorry for hairsplitting but that makes a difference (despite the correct equation).

Thanks for your math lessons.

Thanks for catching that Deniz. It does completely change the meaning, and I've fixed it. Glad your enjoying the posts!

1. The star(*) in the figures threw me off track for a while, may be u can change to dot(.) when u're free

2. I was hoping u can add a section like before – why and where it is used in game programming (significance)

3. I miss the "notify follow up comments via email" thingy in this blog?

Thanks for all the gr8 work đź™‚

An affine combination of vectors(points) is a special kind of linear combination. In general, it is not a linear combination of the points(vectors) where sum of scalars must be equal to one.