WebGL Lesson 12: Linear Combinations of VectorsCopy the code

Last time, we talked about the definition of vectors, and two operations on vectors:

  • add
  • The number by

From these two operations, we extend a new operation: linear combination of vectors.

A = (-0.5, 0.5) B = (0.5, 0.5) A = (-0.5, 0.5) B = (0.5, 0.5) A = (-0.5, 0.5) B = (0.5, 0.5) B = (0.5, 0.5)

We add these two vectors, and we get A new vector C: C = A + B, as shown in the figure below:

So what does point C mean? Let’s look at the three coordinates in the diagram:

😯, we see nothing useful at all for point C. But vector addition has to mean something, and we have to figure it out.


Let’s assume that A and B are two locations, with A representing the location of home and B representing the location of company.

Then Xiao Ming has to go from A to B. Let’s say Xiao Ming has already reached point D. The diagram below:

Then Xiao Ming went to point E again. The diagram below:

Well, obviously, we need an equation for the coordinates of D or E, or to put it in A more general way: we need an equation for the coordinates of F at any point between A and B. The most natural way to think about it is that it has to do with both A and B.

Without going round in circles, the following formula is given:

F = A * (1-t) + B * t; // 0 <= t <= 1

Let’s analyze the above formula:

  • The first partA * (1-t)Which is essentiallyAThis vector and a number1-ttheThe number byOperation.
  • The second partB * tWhich is essentiallyBThis vector and a numberttheThe number byOperation.
  • Then, use the two partsaddOperation, merged into the finalVector F.

To put it in plain English, it’s A times A number, plus B times A number. Let’s not analyze why F has to be between A and B. Let’s define a linear combination first:

  • Linear combination of vectors: A pile ofIf I put the vectors together,eachI’m going to multiply the vector times some number, and then I’m going to multiplyAll of the vectorsAdd it up, and it’s called thisA pile of vectorA linear combination of theta.
1. Each vector is not multiplied by the same number, it is completely independent. 2. You can't have all zeros, because if they're all zeros, you're going to end up with the zero vector, which is not interesting. 3. A linear combination of a bunch of vectors, and the result is still a vector. 4. All multipliers are collectively called coefficients.Copy the code
Look at theThe coefficient offorA linear combinationEffect of results

Now list the F formula again:

F = A * (1-t) + B * t; // 0 <= t <= 1

In this example, the coefficients are 1-t and then t, and the range of t is limited to [0,1]. Let’s set t = 0 and see what the result looks like:



And we found out that it happened to beAPoint itself.

Let’s set t = 1 again and see what happens:



justBPoints.

So we can make A wild guess that if we slowly change t from zero to one, then F will be moving slowly from A to B. Naturally, F is going to be on the line segment between A and B.

This is an interesting result. In general, let’s call this F formula linear interpolation formula. “A” and “B” have A toe in the middle.

The interpolation formula itself is a special linear combination, the particularity lies in the selection of coefficients and the fixed range. But don't think that you have to put the coefficients in a certain range because you have a linear combination. That's wrong. You can take whatever coefficient you want, remember ~Copy the code

It says that not all linear combinations mean anything. Only certain linear combinations are of practical use, such as interpolation formulas.

Let’s look at the addition of two vectors, so we start with A plus B is equal to C, and when we get C, we leave C there, without analyzing what this does, right.

Let’s rewrite this as follows: C is equal to 1 times A plus 1 times B. So if you think about linear combinations, if you add vectors, it’s just a linear combination, how do you do it? You take 1. So in that sense, we’re at the end of the line, so what point C itself means is beyond the scope of this lecture, and we’ll talk about it later in the lecture.

Finally, here’s a question to think about: Describe the linear combination of the following:

G = x * A + y * B; // x ∈ [0, 1], y ∈ [0, 1]

Note that x and y are unrelated and can vary independently, but both are within the range [0, 1].Copy the code



At the end of the text, questions are answeredCopy the code
I can see the effect of the last formula, as shown below:
  • A:

The coordinates of G should be inside this painted area, right? Quack quack.