GAMES101 Study Notes 1
The content below was generated entirely by machine translation. Please verify its accuracy. If anything is unclear, consult the Chinese source version.
Because of various matters at school, along with reviewing for and taking exams, it has already been more than four months since I last updated the blog, and even longer since I last wrote a computer graphics post.
Summer vacation recently began, and I finally studied the entirety of GAMES101 after previously watching only the ray-tracing section. It was still a very pleasant surprise: after some time had passed, I gained new understandings of many concepts that I had not understood very clearly before, especially the mathematical ones. Because of the course’s time constraints, some material was not explained in much detail, so I am recording some of my own understanding here.
Three-Dimensional Rotation Matrices
I already wrote about this in the earlier RT: The Next Week article, but the previous explanation was rather… strange and verbose, and it did not explain the subject from the perspective of coordinate-system transformations. I will therefore write it again here (of course, I still have not studied linear algebra systematically, so the following content may still be rather dubious).
The three-dimensional rotation matrices around the three axes can respectively be written in the following forms:
It is not difficult to notice that, in the matrix for rotation around the y-axis, the positions of and seem to be reversed, which is very strange. In the original video, the rotation matrix is derived by selecting several special points. I feel that a coordinate-system transformation makes it easier to understand here (although Professor Yan thinks this approach is more complicated).
First consider rotation around the z-axis. This case is relatively simple and is basically the same as a two-dimensional rotation matrix:

Note that although I did not draw the z-axis here, the right-hand rule tells us that the z-axis points outward through the screen.
We can express the new x-axis () and the new y-axis () separately as vectors. Note that both vectors are unit vectors:
Observe that the angle between and the original y-axis is , so we can “reverse” the vector form of . One more point requires attention: the x-component of is negative:
In fact, in any coordinate system, every coordinate is obtained by multiplying unit vectors by certain lengths. You can imagine this as moving a point a certain distance in a certain direction. For example, in a Cartesian plane, the coordinate can be understood as moving a point 1 unit in the x direction and 2 units in the y direction.
Therefore, in the rotated coordinate system, the new coordinate of a point is . This is equivalent to moving x units in the direction, y units in the direction, and z units in the original z direction. Although that direction was not transformed, we still denote it by here.
The new coordinate is therefore:
Looking at the rotation-matrix formula given earlier, we can see that indeed satisfies the expression above:
There is a rather interesting point here, marked with the different colors: the three columns of the rotation matrix correspond respectively to , , and , which are the directions of the three axes in the new coordinate system.
From the perspective of coordinate-system transformations, this makes it very easy to understand why the rotation matrix is written this way. We can directly put the directions of the three transformed axes into the three columns of the matrix, thereby obtaining the rotation matrix.
We can use the same method to analyze rotation around the y-axis—the matrix that appeared to be “reversed.”

Although this looks very similar to the preceding figure, notice that the labels in the diagram have changed. Again, the right-hand rule tells us that the y-axis now points outward through the screen.
With the preceding observation, we now need only find , , and in the current situation to write down the rotation matrix around the y-axis.
First, for the new z-axis, namely , we can draw an analogy with in the z-axis rotation. Its vector form is:
The reason the y-component is zero is obvious: we are considering rotation around the y-axis, so y certainly does not change.
Next, by analogy with in the z-axis rotation, we obtain the vector form of :
Because is unchanged from before, it can simply be written as:
Combining these vectors that represent the new x, y, and z directions gives:
Barycentric Coordinates
As explained in the GAMES101 course, barycentric coordinates—especially those for triangles—are extremely useful in computer graphics. They make it convenient to interpolate information at a triangle’s vertices across the triangle’s surface.
When I first listened to the lecture, I still had many questions. For example, why must the three coefficients sum to 1 and all be nonnegative for a point to lie inside the triangle?
After thinking about it for some time, I felt that understanding the concept according to the literal meaning of its name was intuitive: understand it from the perspective of a center of mass.
Physical Perspective
Suppose there is a triangle whose three vertices have masses , respectively, while every region other than the vertices has mass 0. According to the definition of a center of mass, the triangle’s center of mass is:
Separating these three terms gives:
This form is extraordinarily similar to the barycentric-coordinate expression : every term is a coefficient multiplied by a vertex coordinate.
Looking at a term of the form , we find that the coefficients used to calculate the center of mass satisfy the barycentric-coordinate requirements exactly: , and no term is negative.
Thinking in terms of the physical center of mass, what exactly are we converting when we transform ordinary coordinates into barycentric coordinates?
Map the coefficients in the center-of-mass formula to those in barycentric coordinates, namely . We can then see that these coefficients are actually the proportions of the triangle’s total mass assigned to each vertex.
In other words, during the conversion—suppose we convert point from Cartesian coordinates to barycentric coordinates—we are really solving this problem: how should weight be distributed among the triangle’s three vertices so that the triangle’s center of mass lies at point ?
The converted coordinate is precisely the proportion of weight assigned to each of the triangle’s three vertices.
This makes it easy to understand why the three numbers must sum to 1 and be nonnegative for a point to lie inside the triangle. First, from a physical perspective, if mass is nonnegative, the center of mass must lie inside the object. Second, to satisfy the definition of a center of mass, , , and must sum to 1. Since they represent the proportions of the total mass at the three vertices, the three numbers necessarily sum to 1, corresponding to the total mass.
Of course, barycentric coordinates are a generalization of the physical definition, so a purely algebraic explanation may be more convincing.
Algebraic Perspective

We know that a triangle’s barycentric coordinates use a linear combination of its three vertices to represent a coordinate: . We can now try to explain algebraically why the three coefficients must sum to 1 and be nonnegative for the point to lie inside the triangle.
First, we can express point in another form that will help with the later derivation:
Note that and have no relation to the three barycentric-coordinate coefficients here. This expression means that, starting from point A, we move units along the direction AB and then units along the direction AC to reach point .
First, one thing is certain if the point is to remain inside the triangle: and are nonnegative. Starting at A, moving any distance only in the direction or would immediately leave the triangle.
Rearranging the preceding expression slightly gives:
This expression can be understood as follows: we move every point, including point , by . At this point, A must lie at the origin.
The expression then becomes intuitive. First, the vector takes us from the origin to point ; then takes us from point back to A, which is the origin.
Because these two parts point in opposite directions and have the same magnitude—one travels from A to , and the other from to A—the sum of the two vectors must be 0.
Expanding and rearranging the expression gives:
This form is exactly the same as the barycentric-coordinate expression, so we can determine that , , and .
Adding these quantities gives . Indeed, the three barycentric-coordinate coefficients necessarily sum to 1.
We already established that and are nonnegative, but if , would that not make negative?
Consider the following figure. is a perpendicular from to ( is not the midpoint of ; using a non-equilateral triangle might have made this clearer, but I was lazy):

Return to the original definition, . Here, and are respectively the distances traveled in the and directions.
The length of the projection of onto is therefore .
The figure shows that if is 1—that is, if has its full length—the projection’s length must equal . Likewise, if is 0, the projected length in the direction must also be 0.
Because projection, or equivalently the dot product, is a linear operation, if is 0.5, the projection’s length must be half of .
We can therefore say that the length of the projection of onto is .
Similarly, the length of the projection of in the direction follows the same rule.
For point to remain inside the triangle, the length of the projection of the vector onto must be no greater than the length of itself. Otherwise, point would cross side and leave the triangle.
The projected length of onto is , while the projected length of onto is . Naturally, the projected length of the sum of the two vectors onto is .
As stated above, for point to stay inside the triangle, the projection of onto must be no longer than itself. That is, , so .
Because and , we can show that must also be nonnegative.
At this point, we have explained why a point inside a triangle must satisfy , with every coefficient nonnegative. Of course, converting a Cartesian coordinate into barycentric coordinates still requires some relatively complicated calculations. For this part, I think the first method described in this blog post is relatively easy to understand and quite ingenious; interested readers can take a look.





![[Stanford CS144] Lab 4 Record](/img/CS144/tcp%E7%8A%B6%E6%80%81%E6%B5%81%E8%BD%AC%E5%9B%BE.jpg)