第 04·附注 集:三维空间的线性变换
Three-dimensional linear transformations
一句话直觉:三维线性变换是二维直觉的零摩擦延伸:3×3 矩阵的 9 个数字,不过是在记录三个标准基向量 i-hat、j-hat 与 k-hat 在三维空间中的新坐标。
本篇作为第 03、04 讲的重要附注,把“矩阵即空间变换”的思维图景无缝拓展至三维空间。我们引入沿 $z$ 轴的第三个标准基向量 $\hat{k}$,用 $3\times 3$ 矩阵编码三维线性变换,以“绕 $y$ 轴旋转 $90^\circ$”为例手写旋转矩阵,并解释为何计算机图形学与机器人学极其依赖 $3\times 3$ 矩阵乘法来拆解复杂三维姿态。
三维空间的三个标准基向量
$$\hat{\imath} = \begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix},\quad \hat{\jmath} = \begin{bmatrix} 0 \\ 1 \\ 0 \end{bmatrix},\quad \hat{k} = \begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix}$$
绕 y 轴旋转 90° 的 3×3 矩阵
$$R_y(90^\circ) = \begin{bmatrix} 0 & 0 & 1 \\ 0 & 1 & 0 \\ -1 & 0 & 0 \end{bmatrix}$$
3×3 矩阵向量乘法(视频具体数值例)
$$\begin{bmatrix} 0 & 1 & 2 \\ 3 & 4 & 5 \\ 6 & 7 & 8 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} = x \begin{bmatrix} 0 \\ 3 \\ 6 \end{bmatrix} + y \begin{bmatrix} 1 \\ 4 \\ 7 \end{bmatrix} + z \begin{bmatrix} 2 \\ 5 \\ 8 \end{bmatrix}$$
3×3 矩阵乘法(变换复合)
$$\begin{bmatrix} 0 & -2 & 2 \\ 5 & 1 & 5 \\ 1 & 4 & -1 \end{bmatrix} \begin{bmatrix} 0 & 1 & 2 \\ 3 & 4 & 5 \\ 6 & 7 & 8 \end{bmatrix} \quad (\text{先右后左复合})$$
跳出平面世界:三维线性变换与三大基向量
⏱ 00:13 – 02:16
整套系列课程大多在二维平面内讨论,不仅因为二维图像更容易在屏幕上呈现、也更容易建立直观认识,更因为一旦掌握了二维核心思想,它们就能完美、无缝地推广到三维乃至任意高维空间。现在让我们短暂探出“平面世界(Flatland)”,看看三维向量到三维向量的线性变换是什么模样。
三维线性变换依然可以想象成揉捏三维网格:保持所有网格线平行且等距分布,并让原点固定不动;空间中每一个运动的点,依然只是以它为终点的三维输入/输出向量的代理。而决定整个三维线性变换的,正是三个标准基向量各自的新去向:
📐 三维标准基向量与 3×3 矩阵的 9 数字编码
$$\hat{\imath} = \begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix}\;(\text{x 轴}),\quad \hat{\jmath} = \begin{bmatrix} 0 \\ 1 \\ 0 \end{bmatrix}\;(\text{y 轴}),\quad \hat{k} = \begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix}\;(\text{z 轴}) \implies A = \begin{bmatrix} \vert & \vert & \vert \\ L(\hat{\imath}) & L(\hat{\jmath}) & L(\hat{k}) \\ \vert & \vert & \vert \end{bmatrix}$$
将变换后的 $\hat{\imath},\,\hat{\jmath},\,\hat{k}$ 三组三维坐标分别写成一个 $3\times 3$ 矩阵的 3 列,仅用 9 个数字(如屏幕上示例矩阵 $\begin{bmatrix}1&1&1\\0&1&0\\-1&0&1\end{bmatrix}$)就能完全刻画三维线性变换
💡 三维可视化窍门:丢掉密密麻麻的三维网格,只盯三根基箭头
完整三维网格在透视图中会显得非常凌乱遮挡视线。因此,在背景中仅保留一份静止的原始三维坐标轴,然后专心追踪绿色 $\hat{\imath}$、红色 $\hat{\jmath}$ 与新加入的蓝色 $\hat{k}$ 这三根基向量落在哪里,是最清晰的观察方式。
01:08
三维网格形变:保持空间网格线平行、等距分布且原点固定画面重点:彩色三维立方体网格随线性变换挤压变形
01:44
三维标准基向量:x 轴绿色 $\hat{\imath}$、y 轴红色 $\hat{\jmath}$ 与新增的 z 轴蓝色 $\hat{k}$画面重点:三维坐标系中突出显示绿红蓝三根正交单位向量
02:02
简化观测:隐藏繁杂网格,仅留背景坐标轴并读取 $\hat{\imath}\to(1,0,-1)$ 等落点坐标画面重点:仅保留背景坐标轴与三根变换后基箭头及 i-hat 坐标
02:14
9 数字完整编码:三组基向量落点坐标并列组成 $3\times 3$ 矩阵(示例 $\begin{bmatrix}1&1&1\\0&1&0\\-1&0&1\end{bmatrix}$)画面重点:右上角给出 3×3 矩阵编码全貌
[00:13] ↗
嘿 大家好! 今天我带来了一个相对较短的视频作为章节之间的补充说明
Hey folks, I've got a relatively quick video for you today, just sort of a footnote between chapters.
[00:19] ↗
前两期视频中,我谈论了关于线性变换与矩阵的话题 但是我只说明了一类将二维向量变换为其他二维向量的特殊变换
In the last two videos I talked about linear transformations and matrices, but I only showed the specific case of transformations that take two-dimensional vectors to other two-dimensional vectors.
[00:29] ↗
总体而言,整个系列里我们主要在二维空间中进行讨论 主要是因为这样更容易在屏幕上展现,也更容易理解
In general throughout the series we'll work mainly in two dimensions, mostly because it's easier to actually see on the screen and wrap your mind around.
[00:36] ↗
但是更重要的一点在于,一旦你掌握了二维空间里的核心概念 这些概念就能完美推广至高维空间
But more importantly than that, once you get all the core ideas in two dimensions, they carry over pretty seamlessly to higher dimensions.
[00:44] ↗
然而,我们还是应该不时探出头看看平面外的世界 了解这些概念在二维空间外意味着什么
Nevertheless, it's good to peek our heads outside of flatland now and then to, you know, see what it means to apply these ideas in more than just those two dimensions.
[00:52] ↗
比如说,考虑这样一个线性变换 它以三维向量为输入,并以三维向量为输出
For example, consider a linear transformation with three-dimensional vectors as inputs and three-dimensional vectors as outputs.
[01:00] ↗
我们可以想象它在移动三维空间中的所有点(这里用网格代表) 保持网格线平行且等距分布,并保持原点不动
We can visualize this by smooshing around all the points in three-dimensional space, as represented by a grid, in such a way that keeps the grid lines parallel and evenly spaced, and which fixes the origin in place.
[01:13] ↗
和二维情形一样,我们看到的三维空间的每一个点 实际上只是用来代表以它本身为终点的一个向量 而我们所做的变换只是将输入向量移动至对应的输出向量
And just as with two dimensions, every point of space that we see moving around is really just a proxy for a vector who has its tip at that point, and what we're really doing is thinking about input vectors moving over to their corresponding outputs.
[01:28] ↗
还是和二维情形相同 三维线性变换由基向量的去向完全决定
And just as with two dimensions, one of these transformations is completely described by where the basis vectors go.
[01:34] ↗
不过现在我们有三个通常使用的标准基向量
But now, there are three standard basis vectors that we typically use.
[01:38] ↗
x方向的单位向量“i帽” y方向的单位向量“j帽” 外加一个新来的,z方向的单位向量“k帽”
The unit vector in the x direction, i-hat, the unit vector in the y direction, j-hat, and a new guy, the unit vector in the z direction, called k-hat.
[01:47] ↗
实际上我认为,只考虑跟踪这些基向量的话会更容易观察这些线性变换 因为使用三维网格会显得很凌乱
In fact, I think it's easier to think about these transformations by only following those basis vectors, since the full 3D grid representing all points can get kind of messy.
[01:57] ↗
在背景中留下原始坐标轴的副本 我们就能观察到三个基向量变换后的位置
By leaving a copy of the original axes in the background, we can think about the coordinates of where each of these three basis vectors lands.
[02:06] ↗
将变换后三个基向量的坐标记录在一个3×3的矩阵中
Record the coordinates of these three vectors as the columns of a 3x3 matrix.
[02:11] ↗
仅仅使用九个数字,这个矩阵就完全描述了一个线性变换
This gives a matrix that completely describes the transformation using only nine numbers.
具体实例:绕 $y$ 轴旋转 $90^\circ$ 与 $3\times 3$ 矩阵向量乘法
⏱ 02:17 – 03:25
来看一个直观的三维范例:将整个三维空间绕 $y$ 轴旋转 $90^\circ$。逐一追踪三个基向量的运动轨迹,就能立刻写出它的变换矩阵:
📐 绕 y 轴旋转 90° 的矩阵构造
$$\hat{\imath} \mapsto \begin{bmatrix} 0 \\ 0 \\ -1 \end{bmatrix},\quad \hat{\jmath} \mapsto \begin{bmatrix} 0 \\ 1 \\ 0 \end{bmatrix},\quad \hat{k} \mapsto \begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix} \implies R_y(90^\circ) = \begin{bmatrix} 0 & 0 & 1 \\ 0 & 1 & 0 \\ -1 & 0 & 0 \end{bmatrix}$$
绿色 $\hat{\imath}$ 转到 $z$ 轴负向 $(0,0,-1)$;红色 $\hat{\jmath}$ 位于旋转轴本身上保持 $(0,1,0)$ 不动;蓝色 $\hat{k}$ 转到 $x$ 轴正向 $(1,0,0)$
至于任意输入向量 $(x, y, z)$ 在变换后的落点,推导方式与二维完全一致:每个坐标代表对相应基向量的缩放系数,而“先缩放再相加”的线性组合结构在变换前后均严格保持。因此只需把坐标 $x, y, z$ 分别乘上矩阵的三列再相加即可。
📐 3×3 矩阵向量乘法(视频演示示例)
$$\begin{bmatrix} 0 & 1 & 2 \\ 3 & 4 & 5 \\ 6 & 7 & 8 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} = x \begin{bmatrix} 0 \\ 3 \\ 6 \end{bmatrix} + y \begin{bmatrix} 1 \\ 4 \\ 7 \end{bmatrix} + z \begin{bmatrix} 2 \\ 5 \\ 8 \end{bmatrix}$$
输入向量的三个分量 $(x, y, z)$ 依次作为矩阵第 1、2、3 列的权重系数,求和得出输出向量
⚠️ 易错提醒:确认三维坐标轴正方向与右手系符号
手推绕坐标轴旋转的矩阵时,最容易把正负号写反(例如搞混 $\hat{\imath}$ 转到 $(0,0,-1)$ 还是 $(0,0,1)$)。务必先看清图中 $x, y, z$ 三个坐标轴的正方向,并用右手螺旋法则确认旋转朝向,再依次读取三根基箭头落点。
02:29
绕 $y$ 轴旋转 $90^\circ$:绿色 $\hat{\imath}$ 被旋至 $z$ 轴负半轴 $(0, 0, -1)$画面重点:i-hat 指向 (0, 0, -1) 并显示列向量标注
02:37
红色 $\hat{\jmath}$ 停在旋转轴 $(0, 1, 0)$ 上不动,蓝色 $\hat{k}$ 转至 $x$ 轴正向 $(1, 0, 0)$画面重点:k-hat 落点 (1, 0, 0) 及旋转后的三轴状态
02:45
组装出绕 $y$ 轴 $90^\circ$ 旋转矩阵:三组坐标作为三列构成 $\begin{bmatrix}0&0&1\\0&1&0\\-1&0&0\end{bmatrix}$画面重点:右上角展示完整的 3×3 旋转矩阵
03:24
3×3 矩阵向量乘法本质:以输入分量 $(x,y,z)$ 缩放矩阵的三列并求和画面重点:[0,1,2;3,4,5;6,7,8] 乘 [x;y;z] 的彩色列线性组合等式
[02:17] ↗
举个简单的例子,考虑沿着y轴旋转90度的变换
As a simple example, consider the transformation that rotates space 90 degrees around the y-axis.
[02:25] ↗
这个变换将i帽移动到z轴上的(0, 0, -1)
So that would mean that it takes i-hat to the coordinates 0,0, negative 1 on the z-axis.
[02:31] ↗
它不移动j帽,所以j帽仍旧在(0, 1, 0)
It doesn't move j-hat, so it stays at the coordinates 0,1,0.
[02:35] ↗
而k帽被移动至x轴上的(1, 0, 0)
And then k-hat moves over to the x-axis at 1,0,0.
[02:41] ↗
这三组坐标就成为了描述这一旋转变换的矩阵的三列
Those three sets of coordinates become the columns of a matrix that describes that rotation transformation.
[02:50] ↗
要想知道(x, y, z)所代表的向量在变换后的去向 推理过程与二维下几乎相同
To see where a vector with coordinates x,y,z lands, the reasoning is almost identical to what it was for two dimensions.
[02:57] ↗
它的每个坐标都可以看作对相应基向量的缩放 从而使缩放结果的和为你选择的向量
Each of those coordinates can be thought of as instructions for how to scale each basis vector so that they add together to get your vector.
[03:06] ↗
和二维类似,重要的部分在于 这一“缩放再相加”的过程在变换前后均适用
And the important part, just like the 2D case, is that this scaling and adding process works both before and after the transformation.
[03:16] ↗
所以要找到向量变换后的位置 你将它的坐标与矩阵的对应列相乘 再将结果相加即可
So to see where your vector lands, you multiply those coordinates by the corresponding columns of the matrix, and then you add together the three results.
三维矩阵乘法:图形学与机器人的旋转分解之道
⏱ 03:30 – 04:34
两个 $3\times 3$ 矩阵相乘同样遵循二维规则:看见两个 $3\times 3$ 矩阵并排相乘时,脑海里应当想象先施加右侧矩阵所代表的变换,再施加左侧矩阵所代表的变换。
📐 三维变换复合示例(从右向左作用)
$$\underbrace{\begin{bmatrix} 0 & -2 & 2 \\ 5 & 1 & 5 \\ 1 & 4 & -1 \end{bmatrix}}_{\text{后施加的变换}} \underbrace{\begin{bmatrix} 0 & 1 & 2 \\ 3 & 4 & 5 \\ 6 & 7 & 8 \end{bmatrix}}_{\text{先施加的变换}} = \begin{bmatrix} A\vec{c}_1 & A\vec{c}_2 & A\vec{c}_3 \end{bmatrix}$$
乘积矩阵的第 $j$ 列,就是把先作用矩阵(右侧)的第 $j$ 列,左乘后作用矩阵(左侧)的结果
💡 为什么三维矩阵乘法统治了计算机图形学与机器人学?
三维空间中绕任意倾斜轴的复杂旋转非常难以直接凭空描述或写死在公式里;但如果将它拆解成若干个简单、独立的基础旋转的复合(比如先绕 $x$ 轴转、再绕 $y$ 轴转、最后绕 $z$ 轴转),每一步的旋转矩阵都极好写出,最后只需把它们按顺序做三维矩阵乘法合成一个矩阵即可!这是游戏引擎、3D 渲染与机械臂运动学的核心基石。
- 自我检验练习:模仿第 04 讲推导 $2\times 2$ 乘法的方法,试着仅靠“追踪 $\hat{\imath},\,\hat{\jmath},\,\hat{k}$ 两次落点”自己推一遍 $3\times 3$ 矩阵乘法的数值法则。
- 第 1 列:左侧 $3\times 3$ 矩阵 $\times$ 右侧第 1 列;第 2、3 列同理,自然得到第 $(i,j)$ 元素为左第 $i$ 行与右第 $j$ 列点积。
🔗 知识串联:下一讲正式开启 Stage 3:用“行列式”定量刻画线性变换把面积或体积放大了多少倍!
前往「第 05 集 · 行列式」→
03:46
两个 $3\times 3$ 矩阵相乘:白框标出右侧矩阵为“First transformation(先施加变换)”画面重点:两个 3×3 矩阵相乘,白框标出右侧 First transformation
03:58
图形学与机器人学核心应用:把复杂的三维空间旋转拆解为简单标准旋转的复合画面重点:三维空间网格绕不同轴旋转复合过程
04:22
课后自测思考:结合“连续两次三维空间变换”自行推导 $3\times 3$ 乘法的数值规则画面重点:三维复合变换动画收尾画面
[03:30] ↗
两个矩阵相乘也是类似的
Multiplying two matrices is also similar.
[03:32] ↗
当你看到两个3×3矩阵相乘时 你应该想象首先应用右侧矩阵代表的变换 然后应用左侧矩阵代表的变换
Whenever you see two 3x3 matrices getting multiplied together, you should imagine first applying the transformation encoded by the right one, then applying the transformation encoded by the left one.
[03:44] ↗
实际上,三维矩阵相乘在部分领域有着非常重要的应用 比如计算机图形学与机器人学 虽然三维空间中的旋转很难直接表述 但是如果将它分解为简单分立的旋转的复合,这一过程就很容易理解了
It turns out that 3D matrix multiplication is actually pretty important for fields like computer graphics and robotics, since things like rotations and three dimensions can be pretty hard to describe, but they're easier to wrap your mind around if you can break them down as the composition of separate, easier-to-think-about rotations.
[04:04] ↗
三维下通过数值计算矩阵乘法再次与二维情形类似
Performing this matrix multiplication numerically is, once again, pretty similar to the two-dimensional case.
[04:10] ↗
这里有一个好方法来检测你对上期视频的理解程度 那就是根据“两个线性变换依次作用”这一想法 自己尝试推理上面这个矩阵乘法应该是什么样的
In fact, a good way to test your understanding of the last video would be to try to reason through what specifically this matrix multiplication should look like, thinking closely about how it relates to the idea of applying two successive transformations in space.
[04:32] ↗
下期视频中,我会开始讲解行列式
In the next video, I'll start getting into the determinant.
📝 几何直觉自测(点击题目展开解答)
Q1. 一个三维线性变换至少需要多少个数字才能完全确定?这些数字各自代表什么几何含义?▼
需要 $9$ 个数字,排成一个 $3\times 3$ 矩阵。它的三列依次代表三个标准基向量 $\hat{\imath}=\begin{bmatrix}1\\0\\0\end{bmatrix}$、$\hat{\jmath}=\begin{bmatrix}0\\1\\0\end{bmatrix}$、$\hat{k}=\begin{bmatrix}0\\0\\1\end{bmatrix}$ 在线性变换后的三维目标坐标。
Q2. 为什么绕 $y$ 轴旋转 $90^\circ$(将 $z$ 轴正向转到 $x$ 轴正向)的矩阵是 $\begin{bmatrix}0&0&1\\0&1&0\\-1&0&0\end{bmatrix}$?请按列解释。▼
第一列记录 $\hat{\imath}$ 旋转 $90^\circ$ 落到 $z$ 轴负向 $(0,0,-1)$;第二列记录 $\hat{\jmath}$ 位于旋转轴本身上保持 $(0,1,0)$ 不变;第三列记录 $\hat{k}$ 旋转 $90^\circ$ 落到 $x$ 轴正向 $(1,0,0)$。
Q3. 在计算机图形学和机器人学中,为什么常用多个 $3\times 3$ 矩阵相乘来表示三维旋转?▼
因为三维空间中直接描述绕任意轴的复杂旋转非常困难,而分别绕 $x, y, z$ 坐标轴旋转的矩阵很容易写出;将复杂姿态分解为几个简单旋转依次复合(从右向左相乘),就能用一个合成的 $3\times 3$ 矩阵高效表示整个运动。