齐次变换与 SE(3)Homogeneous Transforms & SE(3)
旋转加平移不是线性变换,没法直接写成一个矩阵乘法。给坐标多添一个 1,升高一维,"旋转加平移"就变成了一个 4×4 矩阵,位姿的连乘、求逆都变成了普通的矩阵运算。这样的矩阵构成的集合就是 SE(3),它是李群的第一个主角。 Rotation plus translation is not a linear map, so it cannot be a single matrix product. Append a 1 to the coordinates, go up one dimension, and "rotate then translate" becomes one 4×4 matrix; chaining and inverting poses turn into ordinary matrix algebra. The set of such matrices is SE(3), the first leading actor among Lie groups.
1为什么机器人需要它Why robots need this
机械臂有六七个关节,每个关节处的坐标系相对前一个都是"转一下再平移一段"。末端在底座里的位姿,是这一长串"旋转 + 平移"的连乘。用 5.1 节的写法 \((R, \mathbf t)\),每乘一次要算 \(R_1R_2\) 和 \(R_1\mathbf t_2 + \mathbf t_1\) 两个式子,求逆还要记 \(-R\T\mathbf t\)。关节多了,推导和代码都很容易写错。
齐次坐标的好处是:把"旋转 + 平移"装进同一个矩阵,连乘就是矩阵乘法,求逆有固定的分块公式。相机投影 \(P = K\,[R\,|\,\mathbf t]\)、机械臂的正运动学、SLAM 里的位姿图,都靠这一个小技巧。更重要的是,这样得到的矩阵集合 SE(3) 本身是一个群,下一节会看到,它也是一个弯曲的光滑流形,这正是李群理论登场的地方。
A robot arm has six or seven joints, and each joint frame sits relative to the previous one by "turn, then slide". The end effector's pose in the base frame is a long chain of such "rotation + translation" steps. With the \((R, \mathbf t)\) notation of Lesson 5.1, every product needs two formulas, \(R_1R_2\) and \(R_1\mathbf t_2 + \mathbf t_1\), and inversion adds \(-R\T\mathbf t\). With many joints, both derivations and code are easy to get wrong.
The beauty of homogeneous coordinates is that they put "rotation + translation" in one matrix: chaining is matrix multiplication and inversion has a fixed block formula. Camera projection \(P = K\,[R\,|\,\mathbf t]\), forward kinematics and SLAM pose graphs all rely on this one trick. More importantly, the set SE(3) of such matrices is itself a group, and, as the next lesson shows, a curved smooth manifold: exactly where Lie-group theory enters.
2直觉:升一维,把平移变成"剪切"Intuition: go up one dimension and translation becomes a shear
线性变换必须把原点留在原点(1.3 节),所以平移不是线性的。但看一个小把戏:把平面上的点 \((x, y)\) 放到三维空间的高度 \(w = 1\) 的那张平面上,变成 \((x, y, 1)\)。现在对三维空间做一个剪切:每个点沿 \(xy\) 方向平移的距离,和它的高度 \(w\) 成正比,\((x, y, w) \mapsto (x + t_x w,\ y + t_y w,\ w)\)。高度为 1 的那张平面上,每个点恰好平移了 \((t_x, t_y)\);这个剪切是三维里的线性变换,因此可以写成矩阵乘法。
还有一个意外的好处:高度 \(w = 0\) 的点,剪切对它们没有任何影响。所以 \(w=0\) 的"点"可以用来表示方向向量,它们只会被旋转,不会被平移。下面的实验里,拖动 \(t_x, t_y, \theta\):琥珀色的点(\(w=1\))会被平移,紫色的箭头(\(w=0\))不会。
A linear map must keep the origin fixed (Lesson 1.3), so translation is not linear. Now watch a small trick: put the plane point \((x, y)\) at the plane of height \(w = 1\) in 3D, as \((x, y, 1)\). Then shear 3D space: every point slides in the \(xy\) direction by an amount proportional to its height \(w\), \((x, y, w) \mapsto (x + t_x w,\ y + t_y w,\ w)\). On the plane \(w = 1\) every point moves by exactly \((t_x, t_y)\); and this shear is a linear map in 3D, hence a matrix product.
There is a pleasant side effect: points with height \(w = 0\) are untouched by the shear. So "points" with \(w=0\) can represent direction vectors: they get rotated but never translated. In the lab below, drag \(t_x, t_y, \theta\): the amber point (\(w=1\)) is translated while the purple arrow (\(w=0\)) is not.
- 令 \(\theta = 0\),把 \((t_x, t_y)\) 拉到长度超过 2。琥珀色的 F 平移了,蓝色箭头歪向哪里?紫色箭头动了吗?With \(\theta = 0\), pull \((t_x, t_y)\) to a length above 2. The amber F slid; where does the blue arrow lean? Did the purple arrow move?
- 令 \(t = 0\),把 \(\theta\) 转到 90° 左右。整个"平面世界"绕蓝色的 \(w\) 轴转动,紫色箭头也跟着转。With \(t = 0\), turn \(\theta\) to about 90°. The whole flatland rotates about the blue \(w\) axis, and the purple arrow turns with it.
矩阵的最后一列是平移,因为 \(\hat w\)(即"原点")被送到了 \((\mathbf t, 1)\)。矩阵的左上角是旋转,右下角的 1 保证平面 \(w=1\) 被送回 \(w=1\)。对点 \((\mathbf p, 1)\) 做乘法,得到 \((R\mathbf p + \mathbf t,\ 1)\),恰好就是"先转后移"。
The last column of the matrix is the translation, because \(\hat w\) (the "origin") is sent to \((\mathbf t, 1)\). The upper-left block is the rotation, and the 1 in the lower-right corner keeps the plane \(w=1\) mapped onto \(w=1\). Multiplying the point \((\mathbf p, 1)\) yields \((R\mathbf p + \mathbf t,\ 1)\): exactly "rotate then translate".
3动手玩:SE(2) 与求逆Play: SE(2) and the inverse
平面里的刚体运动构成 SE(2),位姿是 \((x, y, \theta)\),3×3 齐次矩阵是
Rigid motions of the plane form SE(2); a pose is \((x, y, \theta)\) and its 3×3 homogeneous matrix is
\(T\) 把机器人系的读数变成世界系的读数,\(T^{-1}\) 反过来。直观上,\(T^{-1}\) 就是"站在机器人身上看世界":机器人变成原点,朝向变成 \(+x\),世界系被放到了 \(T^{-1}\) 所描述的位置。左边是世界视角,右边是机器人视角。拖动任何一边的点,另一边同步更新。
\(T\) turns robot-frame readings into world-frame readings, and \(T^{-1}\) does the opposite. Intuitively, \(T^{-1}\) is "seeing the world from the robot's seat": the robot becomes the origin, its heading becomes \(+x\), and the world frame is placed where \(T^{-1}\) says. The left panel is the world view and the right one the robot view. Drag the point in either panel and the other follows.
- 把机器人放到 \((3, 1)\)、朝向 \(90°\)。预测 \(T^{-1}\) 的平移列,再核对读数。(答案:\((-1, 3)\),而不是 \((-3,-1)\)。)Put the robot at \((3, 1)\) facing \(90°\). Predict \(T^{-1}\)'s translation column, then check. (Answer: \((-1, 3)\), not \((-3,-1)\).)
- 在右图里把点拖到机器人正前方 2 米,也就是 \(\mathbf p^B = (2, 0)\)。再看左图:它在世界里的哪里?In the right panel drag the point to 2 m straight ahead of the robot, i.e. \(\mathbf p^B = (2, 0)\). Then look at the left panel: where is it in the world?
三维:SE(3) 编辑器In 3D: the SE(3) editor
三维位姿是 \(T = \begin{bmatrix} R & \mathbf t \\ \mathbf 0\T & 1\end{bmatrix} \in \R^{4\times4}\),其中 \(R\) 的三列依次是机体 \(x, y, z\) 轴在世界里的方向(红、绿、蓝),\(\mathbf t\) 是机体原点的位置(琥珀)。用六个滑块摆一个位姿(\(R = R_z(\text{yaw})R_y(\text{pitch})R_x(\text{roll})\),5.2 节),观察 4×4 矩阵每一块怎样对应到图上。
A 3D pose is \(T = \begin{bmatrix} R & \mathbf t \\ \mathbf 0\T & 1\end{bmatrix} \in \R^{4\times4}\), where the three columns of \(R\) are the body's \(x, y, z\) axes in the world (red, green, blue) and \(\mathbf t\) is the position of the body origin (amber). Set a pose with the six sliders (\(R = R_z(\text{yaw})R_y(\text{pitch})R_x(\text{roll})\), Lesson 5.2) and see how each block of the 4×4 matrix lands in the picture.
- 让机体的 \(x\) 轴(红)指向正上方,即 \(R\) 的第一列变成 \((0,0,1)\)。需要什么 pitch?(顺便想想:这是哪一种欧拉角奇异?)Make the body's \(x\) axis (red) point straight up, i.e. the first column of \(R\) becomes \((0,0,1)\). Which pitch does it take? (And which Euler singularity is this?)
- 用平移滑块把机体原点放到紫色点 \(\mathbf q\) 上(距离小于 0.12)。此时 \(T^{-1}\mathbf q\) 是什么?为什么?Use the translation sliders to put the body origin on the purple point \(\mathbf q\) (within 0.12). What is \(T^{-1}\mathbf q\) now, and why?
连乘:平面三连杆Chaining: a planar 3-link arm
每个关节处的坐标系相对前一个是"先沿前一段连杆走 \(L\),再转 \(q\)":\(T_{i-1,i} = \mathrm{Trans}(L_{i-1})\,\mathrm{Rot}(q_i)\)。末端相对底座的位姿就是把它们依次乘起来:\(T_{0E} = T_{01}\,T_{12}\,T_{23}\,T_{3E}\)。拖动三个关节(圆圈)。
Each joint frame sits relative to the previous one by "walk \(L\) along the previous link, then turn by \(q\)": \(T_{i-1,i} = \mathrm{Trans}(L_{i-1})\,\mathrm{Rot}(q_i)\). The end effector's pose in the base frame is the product of all of them, \(T_{0E} = T_{01}\,T_{12}\,T_{23}\,T_{3E}\). Drag the three joints (the circles).
- 让末端落到绿色目标点上(距离小于 0.08)。读一读 \(T_{0E}\) 的最后一列。Bring the tip onto the green target (within 0.08). Read the last column of \(T_{0E}\).
- 把三个关节全拉直(\(q_1=q_2=q_3=0\))。这时每个 \(T_{i-1,i}\) 是什么样子?Straighten all three joints (\(q_1=q_2=q_3=0\)). What does each \(T_{i-1,i}\) look like?
4再看数学The math
提示:把鼠标悬停在公式中带底色的符号上,FIG 3、FIG 4 或 FIG 5 中对应的元素会被高亮。Tip: hover the highlighted symbols in the formulas; the matching element in FIG 3, FIG 4 or FIG 5 lights up.
齐次坐标:点和方向Homogeneous coordinates: points and directions
给 \(\mathbf p \in \R^3\) 添一个分量 1,得到齐次坐标 \(\tilde{\mathbf p} = (\mathbf p, 1) \in \R^4\)。方向(自由向量)则用 \((\mathbf d, 0)\)。位姿 \(T\) 作用在它们上:
Append a 1 to \(\mathbf p \in \R^3\) to get the homogeneous coordinates \(\tilde{\mathbf p} = (\mathbf p, 1) \in \R^4\). Directions (free vectors) use \((\mathbf d, 0)\). A pose \(T\) acts on them by
点 − 点 = 方向(\(w\) 分量 \(1 - 1 = 0\)),点 + 方向 = 点(\(1 + 0 = 1\)),点 + 点没有意义(\(w = 2\))。这和直觉一致:两个位置相减得到位移,两个位置相加没有物理意义。
Point − point = direction (the \(w\) component is \(1 - 1 = 0\)), point + direction = point (\(1 + 0 = 1\)), and point + point makes no sense (\(w = 2\)). That matches intuition: subtracting positions gives a displacement, adding positions has no physical meaning.
SE(3) 的定义The definition of SE(3)
"S"是 special(\(\det R = +1\),没有镜像),"E"是 Euclidean(保持距离)。它有 \(3 + 3 = 6\) 个自由度(SE(2) 有 \(1 + 2 = 3\) 个)。注意 \(T\) 本身不是正交矩阵:\(T\T T \ne I\),所以 \(T^{-1} \ne T\T\)。
"S" is special (\(\det R = +1\), no reflections) and "E" is Euclidean (distances are preserved). It has \(3 + 3 = 6\) degrees of freedom (SE(2) has \(1 + 2 = 3\)). Note that \(T\) itself is not orthogonal: \(T\T T \ne I\), so \(T^{-1} \ne T\T\).
连乘与求逆Composition and inverse
分块矩阵相乘,正好重现了 5.1 节的两个公式:
Block multiplication reproduces the two formulas of Lesson 5.1:
验证逆:\(\begin{bmatrix} R & \mathbf t \\ \mathbf 0\T & 1 \end{bmatrix}\begin{bmatrix} R\T & -R\T\mathbf t \\ \mathbf 0\T & 1 \end{bmatrix} = \begin{bmatrix} RR\T & -RR\T\mathbf t + \mathbf t \\ \mathbf 0\T & 1 \end{bmatrix} = I\)。求逆不需要解线性方程组,只要一次转置和一次矩阵乘向量。而且 \(\det T = \det R = 1\),\(T^{-1}\) 一定存在。
Check the inverse: \(\begin{bmatrix} R & \mathbf t \\ \mathbf 0\T & 1 \end{bmatrix}\begin{bmatrix} R\T & -R\T\mathbf t \\ \mathbf 0\T & 1 \end{bmatrix} = \begin{bmatrix} RR\T & -RR\T\mathbf t + \mathbf t \\ \mathbf 0\T & 1 \end{bmatrix} = I\). Inversion needs no linear solve, only a transpose and one matrix-vector product, and since \(\det T = \det R = 1\) the inverse always exists.
它是一个群It is a group
上面的公式说明 SE(3) 满足群的四条要求:封闭(两个 \(T\) 相乘还是 \(T\))、结合律(矩阵乘法天然满足)、有单位元 \(I\)、每个元素有逆。但它不可交换:\(T_1T_2 \ne T_2T_1\)(5.1 节的左乘右乘之别,以及 FIG 4 里"先转后移"和"先移后转"的区别)。群的定义是下一节(5.4)的主题。
The formulas show that SE(3) satisfies the four requirements of a group: closure (the product of two \(T\)'s is a \(T\)), associativity (free from matrix multiplication), an identity \(I\), and an inverse for every element. It is not commutative: \(T_1T_2 \ne T_2T_1\) (the left/right distinction of Lesson 5.1, and the difference between "turn then move" and "move then turn" in FIG 4). Lesson 5.4 takes up the definition of a group.
平面三连杆的正运动学Forward kinematics of the planar arm
读最后一列就得到末端位置,左上角的 \(2\times2\) 块给出末端朝向 \(\theta = q_1 + q_2 + q_3\)(平面里的角度直接相加)。三维关节用的是同样的思路,5.10 节会把它改写成指数积公式。
The last column gives the tip position and the upper-left \(2\times2\) block gives the tip orientation \(\theta = q_1 + q_2 + q_3\) (planar angles simply add). The same idea carries to 3D joints, and Lesson 5.10 rewrites it as the product of exponentials.
5机器人中的它:手眼标定误差In robotics: hand–eye calibration error
相机装在机械臂的手上(eye-in-hand)。相机看到杯子,给出 \(\mathbf p^C\);机器人要把杯子变到底座系才能规划抓取:
A camera is mounted on the robot's hand (eye-in-hand). It sees the cup and reports \(\mathbf p^C\); the robot must express the cup in the base frame to plan the grasp:
\(T_{BE}\) 来自关节角和正运动学(FIG 4),非常准;\(T_{EC}\) 是相机相对手的安装位姿,由手眼标定得到,一定有误差。下面让 \(T_{EC}\) 的真值比标定值多转了 \(\varepsilon\)。注意这个小角度误差会被距离放大:相机离杯子越远,估计出来的杯子位置偏得越多。
\(T_{BE}\) comes from the joint angles and forward kinematics (FIG 4) and is very accurate; \(T_{EC}\) is the camera's mounting pose relative to the hand, obtained by hand–eye calibration, and is never perfect. Below, the true \(T_{EC}\) is rotated by \(\varepsilon\) more than the calibrated one. A small angle error is amplified by distance: the farther the camera is from the cup, the more the estimated cup position is off.
- 把标定误差 \(\varepsilon\) 调到 0:估计和真值重合,红线消失。Set the calibration error \(\varepsilon\) to 0: the estimate coincides with the truth and the red line vanishes.
- 设 \(\varepsilon = 5°\),把杯子拖到离相机 1.2 m 以外,让偏差超过 10 cm。偏差 ≈ 距离 × \(\varepsilon\)(弧度)。Set \(\varepsilon = 5°\) and drag the cup more than 1.2 m from the camera so the error exceeds 10 cm. Error ≈ range × \(\varepsilon\) (in radians).
机械臂控制器内部把每个连杆的位姿存成 4×4 矩阵(或旋转 + 平移的对),正运动学就是一连串乘法。相机的投影矩阵 \(P = K[R\,|\,\mathbf t]\) 里的 \([R\,|\,\mathbf t]\) 就是 \(T_{CW}\) 去掉最后一行。点云配准(ICP)输出的是一个 4×4 的 \(T\)。SLAM 的位姿图每条边都是一个相对位姿 \(T_{ij}\)。数值上,连乘几千次后 \(R\) 会慢慢漂离旋转矩阵,需要定期重新正交化(1.10 节)。
Robot arm controllers store each link's pose as a 4×4 matrix (or a rotation + translation pair), and forward kinematics is a string of multiplications. In a camera projection matrix \(P = K[R\,|\,\mathbf t]\), the \([R\,|\,\mathbf t]\) is \(T_{CW}\) without its last row. Point-cloud registration (ICP) returns a 4×4 \(T\). In SLAM pose graphs every edge is a relative pose \(T_{ij}\). Numerically, after thousands of products \(R\) slowly drifts off the rotation matrices and must be re-orthonormalised periodically (Lesson 1.10).
6常见误区Common pitfalls
只有左上角的 \(R\) 满足 \(R^{-1} = R\T\)。整个 \(T\) 的逆是 \(\begin{bmatrix}R\T & -R\T\mathbf t\\ \mathbf 0\T & 1\end{bmatrix}\),而 \(T\T = \begin{bmatrix}R\T & \mathbf 0\\ \mathbf t\T & 1\end{bmatrix}\) 完全是另一个东西。如果平移为零,两者碰巧一样,所以这个 bug 在原点附近测试时不会暴露。
Only the upper-left \(R\) satisfies \(R^{-1} = R\T\). The inverse of the whole \(T\) is \(\begin{bmatrix}R\T & -R\T\mathbf t\\ \mathbf 0\T & 1\end{bmatrix}\), while \(T\T = \begin{bmatrix}R\T & \mathbf 0\\ \mathbf t\T & 1\end{bmatrix}\) is something else entirely. With zero translation the two happen to agree, so the bug stays hidden when you test near the origin.
法向量、速度、力的方向、坐标轴方向都是方向,只应被旋转,不应被平移:用 \(R\mathbf d\),或者用 \(w = 0\) 的齐次坐标。把它们当点 \((\mathbf d, 1)\) 变换,就会凭空加上 \(\mathbf t\)。反过来,把点当方向变换,位置就不会被平移到正确的地方。(注意:速度作为 twist 的一部分时,变换规则更复杂,见 5.8 节的伴随。)
Normals, velocities, force directions and axis directions are directions: they should be rotated, not translated. Use \(R\mathbf d\), or homogeneous coordinates with \(w = 0\). Transforming them as points \((\mathbf d, 1)\) adds a spurious \(\mathbf t\); transforming points as directions leaves the position untranslated. (Caveat: when a velocity is part of a twist the rule is more involved, see the adjoint in Lesson 5.8.)
两个 \(T\) 相加得到的 4×4 矩阵不是位姿,\((T_1 + T_2)/2\) 的左上角不是旋转矩阵(5.4 节会看到它怎样"缩水")。求平均、插值、做优化都不能直接对矩阵元素做加法,需要李群的工具(5.6–5.9 节)。
The sum of two \(T\)'s is not a pose, and the upper-left block of \((T_1 + T_2)/2\) is not a rotation matrix (Lesson 5.4 shows how it "shrinks"). Averaging, interpolating and optimising cannot add matrix entries directly; they need Lie-group tools (Lessons 5.6–5.9).
矩阵乘法在浮点数里会累积误差。把一个位姿连乘上万次(比如积分里程计)之后,左上角不再是严格的旋转矩阵,长度开始缩放、直角开始倾斜。对策是定期把 \(R\) 投影回 \(\SO\)(SVD 或 Gram–Schmidt),或者把旋转存成单位四元数,随时归一化。
Floating-point matrix products accumulate error. After a pose has been multiplied tens of thousands of times (say integrating odometry), the upper-left block is no longer a strict rotation: lengths start to scale and right angles to tilt. The remedy is to project \(R\) back onto \(\SO\) periodically (SVD or Gram–Schmidt), or to store the rotation as a unit quaternion and normalise it as you go.
7小练习Check yourself
8延伸阅读Further reading
- K. Lynch & F. Park, Modern Robotics, Ch. 3.3 — 齐次变换矩阵与 SE(3) 的性质homogeneous transformation matrices and the properties of SE(3)
- R. Hartley & A. Zisserman, Multiple View Geometry in Computer Vision, Ch. 2 — 齐次坐标与射影几何homogeneous coordinates and projective geometry
- R. Murray, Z. Li, S. Sastry, A Mathematical Introduction to Robotic Manipulation, Ch. 2 — 刚体运动的齐次表示the homogeneous representation of rigid motion
- B. Siciliano et al., Robotics: Modelling, Planning and Control, Ch. 2.6 — 齐次变换homogeneous transformations