Linear Algebra 线性代数
This appendix serves as a cheat sheet for linear algebra. The subject is presented as a set of tools, their properties, and what you can use them for. If you’re interested in the theory behind all this, you can pick up any introductory linear algebra textbook.
本附录作为线性代数的小抄。这个主题是作为一组工具、它们的属性以及你可以使用它们的原因来介绍的。如果你对这一切背后的理论感兴趣,你可以拿起任何一本线性代数的入门教科书。
The focus here is exclusively on 2D and 3D algebra, as that’s what’s required in this book.
这里的重点是专门讨论二维和三维代数,因为这就是本书的要求。
Points
A point represents a position within a coordinate system.
一个点代表坐标系中的一个位置。
We represent a point as a sequence of numbers between parentheses—for example, . We refer to points using capital letters, such as or .
我们将一个点表示为括号之间的数字序列--例如,(4,3) ( 4 , 3 )。我们用大写字母来指代点,如P𝑃或Q𝑄。
Each of the numbers in the point’s sequence is called a coordinate. The number of coordinates is the point’s dimension. A point with two coordinates is called two-dimensional, or 2D.
在点的序列中的每一个数字都被称为一个坐标。坐标的数量就是该点的维度。一个有两个坐标的点被称为二维,或二维。
The order of the numbers is important; is not the same as . By convention, the coordinates are called and in 2D, and , , and in 3D; so the point has an coordinate of and a coordinate of . Figure A-1 shows , a 2D point with coordinates .
数字的顺序很重要;(4,3) ( 4 , 3 ) 与(3,4) ( 3 , 4 ) 不一样。按照惯例,坐标在二维中称为x𝑥和y𝑦,在三维中称为x𝑥、y𝑦和z𝑧;所以点(4,3) ( 4 , 3 )的x𝑥坐标为4 4,y𝑦坐标为3 3。图A-1显示了P𝑃,一个坐标为(4,3) ( 4 , 3 )的2D点。
We can also refer to specific coordinates of a point using a subscript, like or . So the point can also be written as when convenient.
我们也可以用下标来指代一个点的具体坐标,如P x 𝑃 𝑥或Q y 𝑄 𝑦。所以点P𝑃在方便时也可以写成( P x , P y , P z ) ( 𝑃 𝑥 , 𝑃 𝑦 , 𝑃 𝑧 ) 。
Vectors
A vector represents the difference between two points. Intuitively, imagine a vector as an arrow that connects a point to another point; alternatively, think of it as the instructions to get from one point to another.
矢量代表两点之间的差异。直观地说,可以把矢量想象成连接一个点和另一个点的箭头;或者把它想象成从一个点到另一个点的指令。
Representing Vectors 表示矢量
We represent a vector as a set of numbers between parentheses, and refer to them using a capital letter. This is the same representation we use for points, so we add a small arrow on top to remember they’re vectors and not points. For example, is a vector, which we might decide to call . Figure A-2 shows two equal vectors, and .
我们将向量表示为括号内的一组数字,并使用大写字母来指代它们。这与我们对点使用的表示方法相同,所以我们在上面加一个小箭头,以记住它们是向量而不是点。例如,(2,1) ( 2 , 1 )是一个向量,我们可以决定把它叫做A ⃗ 𝐴 →。图A-2显示了两个相等的向量,A ⃗ 𝐴 → 和B ⃗ 𝐵 →。
Despite sharing their representation with points, vectors don’t represent or have a position; they are, after all, the difference between two positions. When you have a diagram like Figure A-2, you have to draw vectors somewhere; but the vectors and are equal, because they represent the same displacement.
尽管与点的表示方法相同,但向量并不代表或拥有位置;它们毕竟是两个位置之间的差异。当你有一个像图A-2这样的图时,你必须在某个地方画出向量;但向量A⃗ 𝐴 →和B⃗ 𝐵 →是相等的,因为它们代表相同的位移。
In addition, the point and the vector are unrelated. Sure, the vector goes from to , but it’s equally true that it goes from, say, to .
此外,点(2,1) ( 2 , 1 )和向量(2,1) ( 2 , 1 )是不相关的。当然,矢量(2,1) ( 2 , 1 )从(0,0) ( 0 , 0 )到(2,1) ( 2 , 1 ),但它同样是真的,比如说从(5,5) ( 5 , 5 )到(7,6) ( 7 , 6 )。
Vectors are characterized by their direction (the angle in which they point) and their magnitude (how long they are).
矢量的特点是它们的方向(它们所指向的角度)和它们的大小(它们有多长)。
The direction can be further decomposed into orientation (the slope of the line they’re on) and sense (which of the possible two ways along that line they point). For example, a vector pointing right and a vector pointing left both have the same horizontal orientation, but they have the opposite sense. However, we don’t make this distinction anywhere in this book.
方向可以进一步分解为方向(它们所在直线的斜率)和意义(它们沿该直线可能指向的两个方向中的哪个)。例如,指向右边的向量和指向左边的向量都有相同的水平方向,但它们的意义相反。然而,我们在本书的任何地方都没有做这种区分。
Vector Magnitude 矢量幅度
You can compute the magnitude of a vector from its coordinates. The magnitude is also called the length or norm of the vector. It’s denoted by putting the vector between vertical pipes, as in , and it’s computed as follows:
你可以根据一个矢量的坐标来计算它的大小。幅值也被称为矢量的长度或规范。它的表示方法是把矢量放在垂直的管子之间,如 | V ⃗ | | 𝑉 → |,它的计算方法如下。
A vector with a magnitude equal to is called a unit vector.
一个幅度等于1.0 1.0的向量被称为单位向量。
Point and Vector Operations
点和矢量操作
Now that we’ve defined points and vectors, let’s explore what we can do with them.
现在我们已经定义了点和向量,让我们来探讨一下我们能用它们做什么。
Subtracting Points 减去点数
A vector is the difference between two points. In other words, you can subtract two points and get a vector:
矢量是两点之间的差异。换句话说,你可以减去两个点,得到一个矢量。
In this case, you can think of as “going” from to , as in Figure A-3.
在这种情况下,你可以把V⃗𝑉→看作是从Q𝑄到P𝑃的 "走向",如图A-3所示。
Algebraically, you subtract each of the coordinates separately:
在代数上,你要分别减去每个坐标。
Adding a Point and a Vector
添加一个点和一个矢量
We can rewrite the equation above coordinate by coordinate:
我们可以逐个坐标重写上面的方程。
These are just numbers, so all the usual rules apply. This means you can do this:
这些只是数字,所以所有通常的规则都适用。这意味着你可以这样做。
And grouping the coordinates again,
并再次对坐标进行分组。
In other words, you can add a vector to a point and get a new point. This makes intuitive and geometric sense; given a starting position (a point) and a displacement (a vector), you end up in a new position (another point). Figure A-4 presents an example.
换句话说,你可以在一个点上添加一个矢量,得到一个新的点。这具有直观的几何意义;给定一个起始位置(一个点)和一个位移(一个矢量),你最终会在一个新的位置(另一个点)。图A-4是一个例子。
Adding Vectors 添加载体
You can add two vectors. Geometrically, imagine putting one vector “after” another, as in Figure A-5.
你可以将两个向量相加。在几何学上,想象一下把一个向量放在另一个向量的 "后面",如图A-5所示。
As you can see, vector addition is commutative—that is, the order of the operands doesn’t matter. In the diagram, we can see that .
正如你所看到的,向量加法是交换性的,也就是说,操作数的顺序并不重要。在图中,我们可以看到V⃗+W⃗=W⃗+V⃗ 𝑉→+𝑊→=𝑊→+𝑉→。
Algebraically, you add the coordinates individually:
在代数上,你要单独添加坐标。
Multiplying a Vector by a Number
向量与数字相乘
You can multiply a vector by a number. This is called the scalar product. This makes the vector shorter or longer, as you can see in Figure A-6.
你可以将一个向量与一个数字相乘。这被称为标量乘积。这可以使向量变短或变长,正如你在图A-6中看到的那样。
If the number is negative, the vector will point the other way; this means it changes its sense and therefore its direction. But multiplying a vector by a number never changes its orientation—that is, it will remain along the same line.
如果数字是负的,矢量将指向另一个方向;这意味着它改变了它的意义,从而改变了它的方向。但是,将一个矢量乘以一个数字永远不会改变它的方向,也就是说,它将保持在同一直线上。
Algebraically, you multiply the coordinates individually:
在代数上,你把坐标单独相乘。
You can also divide a vector by a number. Just like with numbers, dividing by is equivalent to multiplying by . As usual, division by zero doesn’t work.
你也可以用一个数字除以一个向量。就像数字一样,除以k𝑘相当于乘以1 k 1𝑘。像往常一样,除以零不起作用。
One of the applications of vector multiplication and division is to normalize a vector—that is, to turn it into a unit vector. This changes the magnitude of the vector to , but doesn’t change its other properties. To do this, we just need to divide the vector by its length:
矢量乘法和除法的应用之一是将一个矢量归一化,即把它变成一个单位矢量。这将改变向量的大小为1.0 1.0,但不改变其其他属性。要做到这一点,我们只需要将向量除以其长度。
Multiplying Vectors 向量的乘法
You can multiply a vector by another vector. Interestingly, there are many ways in which you can define an operation like this. We’re going to focus on two kinds of multiplication that are useful to us: the dot product and the cross product.
你可以用一个向量乘以另一个向量。有趣的是,你可以用很多方法来定义这样的操作。我们将专注于两种对我们有用的乘法:点积和交叉积。
Dot Product 点状产品
The dot product between two vectors (also called the inner product) gives you a number. It’s expressed using the dot operator, as in . It’s also written between angle braces, as in .
两个向量之间的点积(也叫内积)给你一个数字。它用点运算符表示,如 V ⃗ ⋅ W ⃗ 𝑉 → ⋅ 𝑊 →。也可以写在角括号之间,如⟨ V ⃗ , W ⃗ ⟩ ⟨ 𝑉 → , 𝑊 → ⟩ 。
Algebraically, you multiply the coordinates individually and add them:
在代数上,你将坐标单独相乘并相加。
Geometrically, the dot product of and is related to their lengths and to the angle between them. The exact formula neatly ties together linear algebra and trigonometry:
在几何学上,V⃗ 𝑉 →和W⃗ 𝑊 →的点积与它们的长度和它们之间的角度α𝛼有关。准确的公式巧妙地将线性代数和三角学联系起来。
Either of these formulas help us see that the dot product is commutative (that is, = ) and that it’s distributive with respect to a scalar product (that is, ).
这些公式中的任何一个都可以帮助我们看到点积是可交换的(也就是说,⟨ V ⃗ , W ⃗ ⟩ 𝑉 → , 𝑊 → ⟩ = ⟨ W ⃗ , V ⃗ ⟩ 𝑊 → 。𝑉 → ⟩),并且它对标量积是可分配的(即k⋅⟨ V ⃗ , W ⃗ ⟩=⟨k⋅ V ⃗ , W ⃗ ⟩ 𝑘 ⋅ ⟨ 𝑉 → , 𝑊 → ⟩ = ⟨ 𝑘 ⋅ 𝑉 → , ⟩)。
An interesting consequence of the second formula is that if and are perpendicular, then cos and therefore is also zero. If and are unit vectors, then is always between and , with meaning they’re equal and meaning they’re opposite.
第二个公式的一个有趣的结果是,如果V ⃗ 𝑉 → 和W ⃗ 𝑊 → 是垂直的,那么cos(α)=0 ( 𝛼 ) = 0,因此⟨ V ⃗ , W ⃗ ⟩ 𝑉 → , 𝑊 → ⟩ 也为零。如果V ⃗ 𝑉 → 和W ⃗ 𝑊 → 是单位向量,那么⟨ V ⃗ , W ⃗ ⟩ 𝑉 → , 𝑊 → ⟩ 总是在-1.0 - 1.0和1.0 1.0之间,1.0 1.0表示它们相等,-1.0 - 1.0表示它们相反。
The second formula also suggests the dot product can be used to calculate the angle between two vectors:
第二个公式也表明点积可以用来计算两个向量之间的角度。
Note that the dot product of a vector with itself, , reduces to the square of its length:
请注意,一个向量与自身的点积,⟨ V ⃗ , V ⃗ ⟩ 𝑉 → , 𝑉 → ⟩,还原为其长度的平方。
This suggests another way to compute the length of a vector, as the square root of its dot product with itself:
这表明了另一种计算矢量长度的方法,即计算其与自身点积的平方根。
Cross Product 交叉产品
The cross product between two vectors gives you another vector. It’s expressed using the cross operator, as in .
两个向量之间的交叉积可以得到另一个向量。它用交叉运算符表示,如V⃗ × W⃗ 𝑉 → × 𝑊 →。
The cross product of two vectors is a vector perpendicular to both of them. In this book we only use the cross product on 3D vectors, shown in Figure A-7.
两个向量的交叉积是一个与它们都垂直的向量。在这本书中,我们只对三维向量使用交叉积,如图A-7所示。
The computation is a bit more involved than the dot product. If , then
其计算方法比点积要复杂一些。如果R⃗ = V⃗ × W⃗ 𝑅 → = 𝑉 → × 𝑊 →, 那么
The cross product is not commutative. Specifically, .
交叉积不是换算的。具体来说,V ⃗ × W ⃗ =-( W ⃗ × V ⃗ ) 𝑉 → × 𝑊 → = - ( 𝑊 → × 𝑉 → ) 。
We use the cross product to compute the normal vector of a surface—that is, a unit vector perpendicular to the surface. To do this, we take two vectors on the surface, calculate their cross product, and normalize the result.
我们用交叉积来计算曲面的法向量,也就是垂直于曲面的单位向量。为此,我们在曲面上取两个向量,计算它们的交积,然后将结果归一。
Matrices 矩阵
A matrix is a rectangular array of numbers. For the purposes of this book, matrices represent transformations that can be applied to points or vectors, and we refer to them with a capital letter, such as . This is the same way we refer to points, but it will be clear by the context whether we’re talking about a matrix or a point.
矩阵是一个长方形的数字阵列。在本书中,矩阵表示可以应用于点或向量的变换,我们用大写字母来指代它们,如M𝑀。这与我们指称点的方式相同,但通过上下文可以清楚地看到我们是在谈论矩阵还是点。
A matrix is characterized by its size in terms of columns and rows. For example, this is a matrix:
矩阵的特点是以列和行为单位的大小。例如,这是一个4×3的4×3矩阵。
Matrix Operations 矩阵操作
Let’s see what we can do with matrices and vectors.
让我们看看我们能用矩阵和向量做什么。
Adding Matrices 添加矩阵
You can add two matrices, as long as they have the same size. The addition is done element by element:
你可以添加两个矩阵,只要它们有相同的大小。加法是逐个元素进行的。
Multiplying a Matrix by a Number
矩阵乘以一个数字
You can multiply a matrix by a number. You just multiply every element of the matrix by the number:
你可以用一个数字乘以一个矩阵。你只需将矩阵的每个元素都乘以数字。
Multiplying Matrices 矩阵相乘
You can multiply two matrices together, as long as their sizes are compatible: the number of columns in the first matrix must be the same as the number of rows in the second matrix. For example, you can multiply a matrix by a matrix, but not the other way around! Unlike numbers, the order of the multiplication matters, even if you’re multiplying together two square matrices that could be multiplied in either order.
你可以将两个矩阵相乘,只要它们的大小一致:第一个矩阵的列数必须与第二个矩阵的行数相同。例如,你可以用一个2×3的2×3矩阵乘以一个3×4的3×4矩阵,但不能反过来!与数字不同的是,乘法的顺序很重要,即使你将两个正方形矩阵相乘,也可以按任何顺序相乘。
The result of multiplying two matrices together is another matrix, with the same number of rows as the left-hand side matrix, and the same number of columns as the right-hand side matrix. Continuing with our example above, the result of multiplying a matrix by a matrix is a matrix.
两个矩阵相乘的结果是另一个矩阵,其行数与左手边的矩阵相同,列数与右手边的矩阵相同。继续我们上面的例子,一个2×3的2×3矩阵与一个3×4的3×4矩阵相乘的结果是一个2×4的2×4矩阵。
Let’s see how to multiply two matrices, A and B:
让我们看看如何将两个矩阵A和B相乘。
To make things more clear, let’s group the values in A and B into vectors: let’s write A as a column of row (horizontal) vectors and B as a row of column (vertical) vectors. For example, the first row of A is the vector and the second column of B is the vector :
为了使事情更清楚,让我们把A和B中的值分成向量:我们把A写成一列行(水平)向量,把B写成一列列(垂直)向量。例如,A的第一行是向量(a,b,c)( 𝑎 , 𝑏 , 𝑐 ),B的第二列是向量(h,l,p)( ℎ , 𝑙 , 𝑝 )。
Let’s give names to these vectors:
让我们给这些向量命名。
We know that A is , and B is , so we know the result will be a matrix:
我们知道A是2×3 2×3,B是3×4 3×4,所以我们知道结果将是一个2×4 2×4矩阵。
Now we can use a simple formulation for the elements of the resulting matrix: the value of the element in row and column of the result—that is, —is the dot product of the corresponding row vector in and column vector in , that is, and :
现在我们可以用一个简单的公式来表示结果矩阵中的元素:结果中行r𝑟和列c𝑐的元素的值--即c rc 𝑐 𝑟 𝑐--是A A中相应行向量和B B中列向量的点积,即A r → 𝐴 𝑟 → 和B c → 𝐵𝑐→。
For example , which expands to .
例如c 01 =⟨ A 0 → , B 1 → ⟩ 𝑐 01 = ⟨ 𝐴 0 → , 𝐵 1 → ⟩,扩展为a⋅h+b⋅l+c⋅p 𝑎 ⋅ ℎ + 𝑏 ⋅𝑙 + 𝑐 ⋅ 𝑝。
Multiplying a Matrix and a Vector
矩阵和向量的相乘
You can think of an n-dimensional vector as either an vertical matrix or as a horizontal matrix, and multiply the same way you would multiply any two compatible matrices. For example, here’s how to multiply a matrix and a 3D vector:
你可以把一个n维向量看成是一个n×1𝑛×1的垂直矩阵,或者是一个1×n 1×𝑛的水平矩阵,然后用与任何两个兼容的矩阵相乘的方法进行乘法。例如,下面是一个2×3的2×3矩阵和一个三维向量的相乘方法。
由于矩阵和向量(或向量和矩阵)相乘的结果也是一个向量,而且在我们的例子中,矩阵代表变换,我们可以说,矩阵变换了向量。