叉积The Cross Product
叉积把两个三维向量变成第三个向量:它垂直于两者,长度等于两者围成的平行四边形的面积,方向由右手定则决定。力矩、旋转物体上一点的速度、曲面的法向量,背后都是它。把它写成一个斜对称矩阵 \(\skew{\mathbf a}\),还能通向李群。 The cross product turns two 3D vectors into a third vector: perpendicular to both, as long as the area of the parallelogram they span, pointing the way the right-hand rule says. Torque, the velocity of a point on a spinning body and the normal of a surface are all cross products. Written as a skew-symmetric matrix \(\skew{\mathbf a}\), it is also the doorway to Lie groups.
1为什么机器人需要它Why robots need this
机械臂手里拿着一块砖,肩关节要出多大的力来撑住它?这取决于砖有多重,也取决于砖离关节有多远、往哪个方向压。同样 10 牛的力,顺着手臂的方向推,关节纹丝不动;垂直于手臂推,关节被拧得最狠。"一个力对关节有多大的拧劲",就是叉积算出来的:\(\boldsymbol\tau = \mathbf r \times \mathbf F\)。
同一个运算在机器人里反复出现:
- 力矩:\(\boldsymbol\tau = \mathbf r\times\mathbf F\),一个力拧关节的力度。
- 旋转物体上一点的速度:转台、轮子、旋转的夹爪上,离轴心 \(\mathbf r\) 处的点速度为 \(\mathbf v = \boldsymbol\omega\times\mathbf r\)。
- 曲面的法向量:点云里取相邻三点,用叉积得到它们所在平面的法向,这就是抓取时的接近方向。
- 左转还是右转:二维路径规划里,判断拐角、求凸包、判断障碍物在直线哪一侧,用的都是叉积的符号。
更往后,叉积的矩阵形式 \(\skew{\boldsymbol\omega}\) 是旋转的"导数",5.5 和 5.6 节的李代数、指数映射都建立在它上面。
A robot arm holds a brick. How hard must the shoulder joint work to keep it up? It depends on the weight, but also on how far the brick is from the joint and in which direction it pushes. A force of 10 N pushing along the arm leaves the joint unmoved; pushing across the arm twists it the hardest. "How much a force twists a joint" is computed by a cross product: \(\boldsymbol\tau = \mathbf r \times \mathbf F\).
The same operation keeps coming back in robotics:
- Torque: \(\boldsymbol\tau = \mathbf r\times\mathbf F\), how hard a force twists a joint.
- Velocity of a point on a spinning body: on a turntable, a wheel or a rotating gripper, the point at \(\mathbf r\) from the axis moves with \(\mathbf v = \boldsymbol\omega\times\mathbf r\).
- Surface normals: take three neighbouring points of a point cloud, and a cross product gives the normal of the plane through them: the approach direction for a grasp.
- Left turn or right turn: in 2D path planning, detecting corners, building convex hulls and deciding which side of a line an obstacle is on all use the sign of a cross product.
Further on, the matrix form \(\skew{\boldsymbol\omega}\) of the cross product is the "derivative" of rotation: the Lie algebra and the exponential map of Lessons 5.5 and 5.6 are built on it.
2直觉:一支垂直的箭头,长度是面积Intuition: a perpendicular arrow whose length is an area
在平面里,两个向量围出一个平行四边形,面积是一个数(1.5 节的行列式)。到了三维,这个平行四边形可以朝任何方向"躺着":只说面积还不够,还得说它躺在哪个平面里。叉积把两件事打包成一个向量:
- 长度是平行四边形的面积,\(\lVert\mathbf a\times\mathbf b\rVert = \lVert\mathbf a\rVert\lVert\mathbf b\rVert\sin\theta\);
- 方向垂直于这个平面,也就是同时垂直于 \(\mathbf a\) 和 \(\mathbf b\)。垂直方向有两个(朝上或朝下),由右手定则选:四指从 \(\mathbf a\) 弯向 \(\mathbf b\),拇指指向 \(\mathbf a\times\mathbf b\)。
如果 \(\mathbf a\)、\(\mathbf b\) 平行,平行四边形压成一条线,面积为零,叉积就是零向量。下面固定 a,让 b 在水平面里转一圈,看 a × b 怎么变。
In the plane, two vectors span a parallelogram, and its area is one number (the determinant of Lesson 1.5). In 3D that parallelogram can lie in any orientation: the area alone is not enough, you also need to say which plane it lies in. The cross product packs both facts into one vector:
- its length is the parallelogram's area, \(\lVert\mathbf a\times\mathbf b\rVert = \lVert\mathbf a\rVert\lVert\mathbf b\rVert\sin\theta\);
- its direction is perpendicular to that plane, i.e. to both \(\mathbf a\) and \(\mathbf b\). There are two perpendicular directions (up or down), and the right-hand rule picks one: curl your fingers from \(\mathbf a\) toward \(\mathbf b\), and your thumb points along \(\mathbf a\times\mathbf b\).
If \(\mathbf a\) and \(\mathbf b\) are parallel, the parallelogram collapses to a line, its area is zero, and the cross product is the zero vector. Below, a is fixed and b sweeps once around the horizontal plane. Watch a × b.
叉积 = 面积 + 朝向,装进一个向量里。长度告诉你"围出了多少面积",方向告诉你"这块面积躺在哪个平面里、哪一面朝外"。
Cross product = area + orientation, packed into one vector. The length says how much area the two vectors enclose; the direction says which plane that area lies in and which side faces out.
3动手玩:三维叉积实验室Play: the 3D cross-product lab
用下面六个滑块摆放 a 和 b:每个向量由方位角(绕 z 轴转)、仰角(离开水平面)和长度决定。右边是实时读数,下方是逐分量的计算。也可以点一个预设,或者显示琥珀色虚线的 b × a。
Place a and b with the six sliders: each vector is set by an azimuth (turning about the z-axis), an elevation (tilting out of the horizontal plane) and a length. The readouts are live, and the component-by-component computation is underneath. You can also pick a preset, or show the dashed amber b × a.
- 只用滑块(不用预设),让 a × b 笔直朝上(+z)。提示:a、b 应该躺在哪个平面里?谁在谁的逆时针一侧?Using the sliders only (no presets), make a × b point straight up (+z). Hint: which plane should a and b lie in, and who must be counter-clockwise of whom?
- 让 a、b 都不是零向量,但 a × b = 0。这时平行四边形变成了什么?Keep both a and b non-zero but make a × b = 0. What has the parallelogram become?
- 让两个向量都不短于 1.2,并使 \(\lVert\mathbf a\times\mathbf b\rVert\) 达到上限 \(\lVert\mathbf a\rVert\lVert\mathbf b\rVert\)(读数两行相等)。夹角应该是多少?With both vectors at least 1.2 long, make \(\lVert\mathbf a\times\mathbf b\rVert\) reach its ceiling \(\lVert\mathbf a\rVert\lVert\mathbf b\rVert\) (the two readout lines agree). What must the angle be?
- 点预设 x × y = z,然后只改 b(不碰 a 的滑块),让 a × b 翻成朝下。Press the preset x × y = z, then change only b (do not touch a's sliders) so that a × b flips to point down.
4第二个视角:二维里的叉积是一个有符号的数Second view: in 2D the cross product is one signed number
把 \(\mathbf a\)、\(\mathbf b\) 都放进 xy 平面(\(z=0\))。它们围出的平行四边形躺在这个平面里,叉积必然沿着 z 轴,只剩一个分量要算:
Put both \(\mathbf a\) and \(\mathbf b\) in the xy-plane (\(z=0\)). The parallelogram they span lies in this plane, so the cross product must point along the z-axis, and only one component is left to compute:
这正是 1.5 节的行列式:面积的正负号里藏着方向信息。结果为正,说明 \(\mathbf b\) 在 \(\mathbf a\) 的左边(从 \(\mathbf a\) 逆时针转不到 180° 就能到 \(\mathbf b\));为负,\(\mathbf b\) 在右边;为零,两者共线。拖动下图的两个箭头尖。
This is exactly the determinant of Lesson 1.5: the sign of the area carries orientation. A positive value means \(\mathbf b\) is on the left of \(\mathbf a\) (you reach \(\mathbf b\) by turning counter-clockwise from \(\mathbf a\) by less than 180°); a negative value means b is on the right; zero means they are collinear. Drag the two arrow tips below.
- 让 b 在 a 的左边,面积大于 1。Put b on the left of a with an area above 1.
- 让 b 在 a 的右边,面积小于 −1。Put b on the right of a with an area below −1.
- 让两个向量都不短于 1,并且共线(面积为 0)。Make the two vectors both at least 1 long and collinear (area 0).
- 让叉积恰好等于 2(精度 0.05)。有很多种摆法,试试用最短的向量。Make the cross product exactly 2 (within 0.05). Many placements work; try it with the shortest vectors you can.
小游戏:左转还是右转Mini-game: left turn or right turn
一台机器人沿着路径点走。在每个拐角处,设进来的方向是 \(\mathbf u = p_i - p_{i-1}\),出去的方向是 \(\mathbf v = p_{i+1}-p_i\),则 \(\mathbf u\times\mathbf v>0\) 是左转,\(<0\) 是右转。不用算角度,不用 \(\arctan\),一次乘减就够了。
"搭路径"模式下拖动路径点,实时看每个拐角;"抢答"模式下看一眼就判断。
A robot follows a path through waypoints. At each corner let the incoming direction be \(\mathbf u = p_i - p_{i-1}\) and the outgoing one \(\mathbf v = p_{i+1}-p_i\). Then \(\mathbf u\times\mathbf v>0\) is a left turn and \(<0\) a right turn. No angles and no \(\arctan\): one multiply-and-subtract is enough.
In "Build" mode drag the waypoints and watch every corner live; in "Quiz" mode make the call at a glance.
- 在"搭路径"模式下,把路径改成恰好两个左转、一个右转(三个拐角,不能有"几乎直行"的)。In "Build" mode, reshape the path to have exactly two left turns and one right turn (three corners, none of them "nearly straight").
- 在"抢答"模式下连续答对 5 题。In "Quiz" mode, answer 5 in a row correctly.
同一个符号判断用在很多地方:凸包算法(Graham 扫描、Andrew 单调链)每加一个点都问"是不是左转";多边形顶点按逆时针还是顺时针排列,看各边叉积之和(鞋带公式)的正负;障碍物在规划线段的哪一侧,用 \((\mathbf b-\mathbf a)\times(\mathbf p-\mathbf a)\) 的符号;轨迹上的急转弯检测也是它。它只用乘法和减法,没有三角函数,快而且稳。
The same sign test is everywhere: convex hull algorithms (Graham scan, Andrew's monotone chain) ask "is this a left turn?" for every point added; whether a polygon's vertices run counter-clockwise or clockwise follows from the sign of the sum of edge cross products (the shoelace formula); which side of a planned segment an obstacle is on is the sign of \((\mathbf b-\mathbf a)\times(\mathbf p-\mathbf a)\); sharp-corner detection on a trajectory is the same thing. It uses only multiplications and subtractions, no trigonometry: fast and robust.
5第三个视角:叉积是一个矩阵Third view: the cross product is a matrix
固定 \(\mathbf a\),看 \(\mathbf b\mapsto\mathbf a\times\mathbf b\)。这个映射对 \(\mathbf b\) 是线性的:\(\mathbf a\times(s\mathbf b+t\mathbf c) = s\,\mathbf a\times\mathbf b + t\,\mathbf a\times\mathbf c\)。1.3 节说过,线性映射都是矩阵。它的矩阵由 \(\mathbf a\) 的三个分量排成,叫做 \(\mathbf a\) 的叉积矩阵(hat 矩阵):
Fix \(\mathbf a\) and look at \(\mathbf b\mapsto\mathbf a\times\mathbf b\). This map is linear in \(\mathbf b\): \(\mathbf a\times(s\mathbf b+t\mathbf c) = s\,\mathbf a\times\mathbf b + t\,\mathbf a\times\mathbf c\). By Lesson 1.3, every linear map is a matrix. Its matrix is built from the three components of \(\mathbf a\) and is called the cross-product matrix (or hat matrix) of \(\mathbf a\):
用下面的图验证:改 \(\mathbf a\) 和 \(\mathbf b\)(左右拖动数字,或直接输入),看矩阵乘出来的结果是不是琥珀色的 \(\mathbf a\times\mathbf b\)。淡琥珀色的圆盘是单位球经过 \(\skew{\mathbf a}\) 后的像:球被压扁成一个垂直于 \(\mathbf a\) 的圆盘,半径 \(\lVert\mathbf a\rVert\)。矩阵的秩是 2,沿 \(\mathbf a\) 的方向被完全抹掉。
Check it in the figure below: change \(\mathbf a\) and \(\mathbf b\) (scrub the numbers sideways or type them) and see that the matrix product is the amber \(\mathbf a\times\mathbf b\). The pale amber disc is the image of the unit sphere under \(\skew{\mathbf a}\): the sphere is flattened into a disc perpendicular to \(\mathbf a\), of radius \(\lVert\mathbf a\rVert\). The matrix has rank 2, and the direction of \(\mathbf a\) is wiped out completely.
- 把 a 设成 \((0,0,1)\)。矩阵的左上角 2×2 是哪个熟悉的矩阵?(见下面的提示框。)Set a to \((0,0,1)\). Which familiar matrix is the top-left 2×2 block? (See the box below.)
- 选"归一化 â"和"3 次幂",确认 \(\skew{\hat{\mathbf a}}^3 = -\skew{\hat{\mathbf a}}\)(最大差值为 0)。Choose "normalised â" and "power 3" and confirm \(\skew{\hat{\mathbf a}}^3 = -\skew{\hat{\mathbf a}}\) (maximum difference 0).
取 \(\mathbf a=\hat{\mathbf k}=(0,0,1)\):\(\skew{\hat{\mathbf k}} = \begin{bmatrix}0&-1&0\\1&0&0\\0&0&0\end{bmatrix}\)。左上角的 2×2 就是 1.3 节的"逆时针 90° 旋转",而 z 分量被抹掉。也就是说,\(\hat{\mathbf k}\times\mathbf b\) 把 \(\mathbf b\) 投到 xy 平面再逆时针转 90°。一般的 \(\mathbf a\) 做的是同样的事:把 \(\mathbf b\) 投到垂直于 \(\mathbf a\) 的平面,转 90°,再乘上 \(\lVert\mathbf a\rVert\)。
Take \(\mathbf a=\hat{\mathbf k}=(0,0,1)\): \(\skew{\hat{\mathbf k}} = \begin{bmatrix}0&-1&0\\1&0&0\\0&0&0\end{bmatrix}\). The top-left 2×2 block is the "90° counter-clockwise rotation" of Lesson 1.3, and the z-component is wiped out. So \(\hat{\mathbf k}\times\mathbf b\) projects \(\mathbf b\) onto the xy-plane and turns it 90° counter-clockwise. A general \(\mathbf a\) does the same thing: project \(\mathbf b\) onto the plane perpendicular to \(\mathbf a\), turn it 90°, and scale by \(\lVert\mathbf a\rVert\).
6再看数学The math
提示:把鼠标悬停在公式中带底色的符号上,FIG 2 中对应的元素会被高亮。Tip: hover the highlighted symbols in the formulas; the matching element in FIG 2 lights up.
分量公式与记忆窍门The component formula and a memory trick
每个分量是"另外两个下标"的交叉相乘再相减,下标按 1→2→3→1 循环。更好记的是一个"形式上的行列式",第一行放的不是数而是基向量:
Each component is a cross-multiplication of the "other two indices", with the indices running cyclically 1→2→3→1. Easier to remember is a "formal determinant" whose first row holds basis vectors instead of numbers:
例:\(\mathbf a=(1,0,2)\),\(\mathbf b=(0,1,0)\),则 \(\mathbf a\times\mathbf b = (0\cdot0-2\cdot1,\; 2\cdot0-1\cdot0,\; 1\cdot1-0\cdot0) = (-2,0,1)\)。检验:与 \(\mathbf a\) 的点积是 \(-2+0+2=0\),与 \(\mathbf b\) 的点积是 0,确实同时垂直于两者。
Example: \(\mathbf a=(1,0,2)\), \(\mathbf b=(0,1,0)\) give \(\mathbf a\times\mathbf b = (0\cdot0-2\cdot1,\; 2\cdot0-1\cdot0,\; 1\cdot1-0\cdot0) = (-2,0,1)\). Check: its dot product with \(\mathbf a\) is \(-2+0+2=0\) and with \(\mathbf b\) it is 0, so it is perpendicular to both.
几何意义:长度与方向Geometry: length and direction
其中 \(\hl{theta}{\theta}\in[0,\pi]\) 是 \(\mathbf a\)、\(\mathbf b\) 的夹角。理由:以 \(\lVert\mathbf a\rVert\) 为底,平行四边形的高是 \(\lVert\mathbf b\rVert\sin\theta\),面积 = 底 × 高。把它和点积(1.7 节)放在一起看:
Here \(\hl{theta}{\theta}\in[0,\pi]\) is the angle between \(\mathbf a\) and \(\mathbf b\). Reason: with base \(\lVert\mathbf a\rVert\), the parallelogram's height is \(\lVert\mathbf b\rVert\sin\theta\), and area = base × height. Put it next to the dot product (Lesson 1.7):
点积量"有多同向"(cos 部分),叉积量"有多垂直"(sin 部分)。最后一个等式叫拉格朗日恒等式,把分量展开就能验证;它对应 \(\cos^2\theta+\sin^2\theta=1\)。
The dot product measures "how aligned" (the cos part), the cross product "how perpendicular" (the sin part). The last identity is Lagrange's; expand it in components to check it. It is \(\cos^2\theta+\sin^2\theta=1\) in disguise.
代数性质Algebraic properties
| 性质Property | 公式Formula | 含义Meaning |
|---|---|---|
| 反交换Anti-commutative | \(\mathbf b\times\mathbf a = -\,\mathbf a\times\mathbf b\) | 交换顺序,方向翻转,长度不变swap the order and the direction flips, the length does not |
| 自叉为零Self-product | \(\mathbf a\times\mathbf a = \mathbf 0\) | 平行四边形没有面积the parallelogram has no area |
| 平行判据Parallel test | \(\mathbf a\times\mathbf b=\mathbf 0 \iff \mathbf a\parallel\mathbf b\) | (其中一个为零向量也算)(a zero vector counts as parallel) |
| 双线性Bilinear | \(\mathbf a\times(s\mathbf b+t\mathbf c)=s\,\mathbf a\times\mathbf b+t\,\mathbf a\times\mathbf c\) | 对每个位置都线性,所以才有矩阵 \(\skew{\mathbf a}\)linear in each slot, which is why the matrix \(\skew{\mathbf a}\) exists |
| 基向量循环Basis cycle | \(\ihat\times\jhat=\khat,\ \jhat\times\khat=\ihat,\ \khat\times\ihat=\jhat\) | 右手系的定义性质the defining property of a right-handed frame |
| 不满足结合律Not associative | \((\mathbf a\times\mathbf b)\times\mathbf c\ne\mathbf a\times(\mathbf b\times\mathbf c)\) | 括号不能乱动,见下brackets matter, see below |
非结合的反例:\(\ihat\times(\ihat\times\jhat) = \ihat\times\khat = -\jhat\),但 \((\ihat\times\ihat)\times\jhat = \mathbf 0\times\jhat=\mathbf 0\)。要化简嵌套的叉积,用 BAC-CAB 公式:\(\mathbf a\times(\mathbf b\times\mathbf c) = \mathbf b\,(\mathbf a\cdot\mathbf c) - \mathbf c\,(\mathbf a\cdot\mathbf b)\)。
A counterexample to associativity: \(\ihat\times(\ihat\times\jhat) = \ihat\times\khat = -\jhat\), but \((\ihat\times\ihat)\times\jhat = \mathbf 0\times\jhat=\mathbf 0\). To simplify nested cross products use the BAC-CAB rule: \(\mathbf a\times(\mathbf b\times\mathbf c) = \mathbf b\,(\mathbf a\cdot\mathbf c) - \mathbf c\,(\mathbf a\cdot\mathbf b)\).
三重积:体积The triple product: volume
其中 \(V_{\mathbf a,\mathbf b,\mathbf c}\) 是 \(\mathbf a,\mathbf b,\mathbf c\) 张成的平行六面体的体积,三重积是带符号的体积。\(\mathbf b\times\mathbf c\) 的长度是底面积,方向垂直于底面;再和 \(\mathbf a\) 点积,就是 \(\mathbf a\) 在垂直方向的分量(高)乘底面积,即体积。正负号反映 \((\mathbf a,\mathbf b,\mathbf c)\) 是不是右手系,这就是 1.5 节说的三维行列式。例:\(\mathbf a=(1,0,0)\),\(\mathbf b=(1,2,0)\),\(\mathbf c=(1,1,3)\),则 \(\mathbf b\times\mathbf c=(6,-3,-1)\),\(\mathbf a\cdot(\mathbf b\times\mathbf c)=6\);矩阵是上三角的,行列式 \(1\cdot2\cdot3=6\),一致。
Here \(V_{\mathbf a,\mathbf b,\mathbf c}\) is the volume of the parallelepiped spanned by \(\mathbf a,\mathbf b,\mathbf c\): the triple product is a signed volume. The length of \(\mathbf b\times\mathbf c\) is the base area and its direction is perpendicular to the base; dotting with \(\mathbf a\) picks the component of \(\mathbf a\) along that perpendicular (the height) times the base area: the volume. The sign says whether \((\mathbf a,\mathbf b,\mathbf c)\) is right-handed, which is the 3D determinant of Lesson 1.5. Example: \(\mathbf a=(1,0,0)\), \(\mathbf b=(1,2,0)\), \(\mathbf c=(1,1,3)\) give \(\mathbf b\times\mathbf c=(6,-3,-1)\) and \(\mathbf a\cdot(\mathbf b\times\mathbf c)=6\); the matrix is upper triangular with determinant \(1\cdot2\cdot3=6\), the same.
hat 矩阵的恒等式Identities of the hat matrix
第二条(斜对称)读矩阵就能看出:对角线是 0,关于对角线对称位置的两个数互为相反数。第三条是 \(\mathbf a\times\mathbf a=\mathbf 0\)。因为 \(\skew{\mathbf a}\) 把 \(\mathbf a\) 变成零,它不可逆,秩为 2,零空间是 \(\mathbf a\) 所在的直线(1.6 节)。第四条由 BAC-CAB 得到:\(\skew{\mathbf a}^2\mathbf b=\mathbf a\times(\mathbf a\times\mathbf b)=\mathbf a(\mathbf a\cdot\mathbf b)-\mathbf b\lVert\mathbf a\rVert^2\)。第五条再乘一次 \(\skew{\mathbf a}\),利用 \(\skew{\mathbf a}\mathbf a=\mathbf 0\):\(\skew{\mathbf a}^3=\skew{\mathbf a}\mathbf a\mathbf a\T-\lVert\mathbf a\rVert^2\skew{\mathbf a}=-\lVert\mathbf a\rVert^2\skew{\mathbf a}\)。
对单位向量 \(\hat{\mathbf u}\),\(K=\skew{\hat{\mathbf u}}\) 满足 \(K^3=-K\)。于是 \(K\) 的高次幂只在 \(K\) 和 \(K^2\) 之间来回,指数级数 \(e^{\theta K}\) 能合并成 \(I+\sin\theta\,K+(1-\cos\theta)K^2\):这就是 5.6 节的罗德里格斯公式。
The second one (skew-symmetry) can be read off the matrix: the diagonal is 0 and entries mirrored across the diagonal are negatives of each other. The third is \(\mathbf a\times\mathbf a=\mathbf 0\). Because \(\skew{\mathbf a}\) turns \(\mathbf a\) into zero, it is not invertible: its rank is 2 and its null space is the line through \(\mathbf a\) (Lesson 1.6). The fourth follows from BAC-CAB: \(\skew{\mathbf a}^2\mathbf b=\mathbf a\times(\mathbf a\times\mathbf b)=\mathbf a(\mathbf a\cdot\mathbf b)-\mathbf b\lVert\mathbf a\rVert^2\). The fifth multiplies by \(\skew{\mathbf a}\) once more and uses \(\skew{\mathbf a}\mathbf a=\mathbf 0\): \(\skew{\mathbf a}^3=\skew{\mathbf a}\mathbf a\mathbf a\T-\lVert\mathbf a\rVert^2\skew{\mathbf a}=-\lVert\mathbf a\rVert^2\skew{\mathbf a}\).
For a unit vector \(\hat{\mathbf u}\), \(K=\skew{\hat{\mathbf u}}\) satisfies \(K^3=-K\). Higher powers of \(K\) then just alternate between \(K\) and \(K^2\), and the exponential series \(e^{\theta K}\) collapses into \(I+\sin\theta\,K+(1-\cos\theta)K^2\): Rodrigues' formula of Lesson 5.6.
右手定则依赖右手系The right-hand rule needs a right-handed frame
分量公式只是算术,在哪个坐标系里算数字都一样。"拇指方向"则是几何陈述,只有当 \((x,y,z)\) 构成右手系(\(\ihat\times\jhat=\khat\),本课程的约定)时才成立。在左手系里,同样的算术给出的箭头会按左手定则取向,也就是整体翻到另一边。
The component formula is only arithmetic, and gives the same numbers in any coordinates. "Thumb direction" is a geometric statement that holds only when \((x,y,z)\) is a right-handed frame (\(\ihat\times\jhat=\khat\), this course's convention). In a left-handed frame the same arithmetic yields an arrow oriented by the left-hand rule: everything flips to the other side.
7机器人中的它:力矩、转动的速度、法向量In robotics: torque, spinning velocity, surface normals
力矩:\(\boldsymbol\tau=\mathbf r\times\mathbf F\)Torque: \(\boldsymbol\tau=\mathbf r\times\mathbf F\)
关节在原点,连杆伸到作用点 \(\mathbf r\),那里有一个力 \(\mathbf F\)。关节感受到的拧劲是 \(\boldsymbol\tau=\mathbf r\times\mathbf F\),它沿着关节轴。在平面里它退化成一个数 \(\tau=r_xF_y-r_yF_x\):正号表示逆时针拧。大小还可以写成 \(\tau=\lVert\mathbf F\rVert\cdot d\),\(d\) 是关节到力的作用线的垂直距离(力臂)。只有垂直于连杆的那部分力才拧关节。
拖动连杆末端(青色点)和力的箭头尖(紫色)。切换到"转动"模式,可以看同一个叉积的另一种用法。
The joint sits at the origin, the link reaches out to the point of application \(\mathbf r\), and a force \(\mathbf F\) acts there. The twist the joint feels is \(\boldsymbol\tau=\mathbf r\times\mathbf F\), directed along the joint axis. In a plane it collapses to one number, \(\tau=r_xF_y-r_yF_x\), positive for a counter-clockwise twist. Its size can also be written \(\tau=\lVert\mathbf F\rVert\cdot d\), where \(d\) is the perpendicular distance from the joint to the line of action of the force (the lever arm). Only the part of the force across the link twists the joint.
Drag the end of the link (cyan dot) and the tip of the force arrow (purple). Switch to "Spinning" mode for another use of the same cross product.
- 在"力矩"模式下,用力推(不小于 3 N),却产生零力矩。力应该沿着什么方向?In "Torque" mode, push hard (at least 3 N) yet produce zero torque. Along which direction must the force point?
- 在"转动"模式下,让所选点的速度笔直朝上。点应该在转轴的哪一侧?把 ω 改成负数,答案怎么变?In "Spinning" mode, make the chosen point's velocity point straight up. On which side of the axis must the point be? How does the answer change if ω is negative?
转台以 30 转/分钟转动,\(\omega=30\cdot2\pi/60=\pi\approx3.14\) rad/s,方向沿转轴。距轴心 0.2 m 的点速度大小 \(\lVert\boldsymbol\omega\rVert\lVert\mathbf r\rVert\sin 90^\circ\approx0.63\) m/s,方向垂直于半径,沿切线。轮子、旋转的夹爪、机械臂连杆上任一点的速度都是这样算的。如果 \(\boldsymbol\omega\) 和 \(\mathbf r\) 平行(点正好在转轴上),叉积为零,点不动。写成矩阵就是 \(\mathbf v=\skew{\boldsymbol\omega}\mathbf r\),这个 \(\skew{\boldsymbol\omega}\) 就是 5.5 节要讲的角速度的 hat。
A turntable spins at 30 rpm, so \(\omega=30\cdot2\pi/60=\pi\approx3.14\) rad/s along the spin axis. A point 0.2 m from the axis moves at \(\lVert\boldsymbol\omega\rVert\lVert\mathbf r\rVert\sin 90^\circ\approx0.63\) m/s, perpendicular to the radius, along the tangent. The velocity of any point on a wheel, a rotating gripper or an arm link is computed this way. If \(\boldsymbol\omega\) and \(\mathbf r\) are parallel (the point is on the axis), the cross product is zero and the point stays put. In matrix form, \(\mathbf v=\skew{\boldsymbol\omega}\mathbf r\), and this \(\skew{\boldsymbol\omega}\) is the hat of the angular velocity that Lesson 5.5 builds on.
三点求法向量A normal from three points
点云里取相邻三点 \(p_1,p_2,p_3\),两条边的叉积垂直于它们所在的平面:
Take three neighbouring points \(p_1,p_2,p_3\) of a point cloud; the cross product of two edges is perpendicular to the plane through them:
未归一化的 \(\mathbf N\) 顺手给出三角形的面积 \(A_\triangle\)(平行四边形的一半)。下面给三个点加一点测量噪声,看噪声怎么影响法向量。深色的 琥珀色箭头 是无噪声的法向量,青色小点是 36 次加噪后的单位法向量的尖端。
The unnormalised \(\mathbf N\) gives the triangle's area \(A_\triangle\) for free (half the parallelogram). Below, a little measurement noise is added to the three points to see how it affects the normal. The amber arrow is the noise-free normal; the small cyan dots are the tips of the unit normals from 36 noisy trials.
- 把三角形压得足够扁,使法向量的平均误差超过 15°。Squash the triangle until the average normal error exceeds 15°.
- 不动任何点,只点"交换 2 ↔ 3",让法向量朝下。Without moving any point, press "swap 2 ↔ 3" so that the normal points down.
点云库一般取一个点的 20 个左右近邻,用 PCA(1.12 节)拟合平面,取最小奇异方向作法向量:它用了所有点,比三点叉积稳得多。叉积仍然用在网格里:给每个三角面算法向量,顶点法向量取周围面的加权平均(面积就是权重,未归一化的 \(\mathbf N\) 本来就带着)。法向量的符号需要统一:常见做法是和朝向传感器的向量点乘,为负就翻转。
Point-cloud libraries usually take about 20 neighbours of a point, fit a plane with PCA (Lesson 1.12) and use the smallest singular direction as the normal: it uses all the points and is far more robust than a three-point cross product. The cross product is still used on meshes: compute each triangle's normal, and set a vertex normal as the average over the surrounding faces (the area is the weight, and the unnormalised \(\mathbf N\) already carries it). Normals also need a consistent sign: the usual trick is to dot them with the vector toward the sensor and flip when the result is negative.
8常见误区Common pitfalls
\(\mathbf b\times\mathbf a=-\,\mathbf a\times\mathbf b\)。顺序写反,结果整个翻到另一侧。网格里三角形的顶点顺序(绕行方向)决定法向量朝外还是朝里:法向量指进物体内部,通常就是顶点顺序反了。力矩 \(\mathbf r\times\mathbf F\) 也一样,写成 \(\mathbf F\times\mathbf r\) 会得到相反的转向。
\(\mathbf b\times\mathbf a=-\,\mathbf a\times\mathbf b\). Write the order backwards and the whole result flips to the other side. The vertex order (winding) of a mesh triangle decides whether the normal points out of the object or into it: a normal pointing into the object usually means the vertex order is reversed. Torque is the same: writing \(\mathbf F\times\mathbf r\) instead of \(\mathbf r\times\mathbf F\) gives the opposite turning direction.
叉积的"垂直于平面的方向"只有在三维才唯一。二维里的"叉积" \(a_1b_2-a_2b_1\) 是一个数,是三维叉积 z 分量的简写。把它当向量去加、去归一化,是常见的类型错误。
"The direction perpendicular to the plane" is unique only in 3D. The 2D "cross product" \(a_1b_2-a_2b_1\) is a number, shorthand for the z-component of the 3D cross product. Adding it to vectors or normalising it as if it were a vector is a common type error.
\(\lVert\mathbf a\times\mathbf b\rVert=\lVert\mathbf a\rVert\lVert\mathbf b\rVert\sin\theta\),不是 1。要单位法向量,必须再除以长度,并且防止除以零。近乎共线的三点,\(\sin\theta\) 很小,长度被压缩,方向几乎由噪声决定(FIG 7)。这种三角形(细长的"针")不该拿来估计法向量。
\(\lVert\mathbf a\times\mathbf b\rVert=\lVert\mathbf a\rVert\lVert\mathbf b\rVert\sin\theta\), not 1. For a unit normal you must divide by the length, and guard against division by zero. For nearly collinear points \(\sin\theta\) is tiny, the length is squeezed, and the direction is almost pure noise (FIG 7). Such needle-like triangles should not be used to estimate normals.
本课程的所有坐标系都是右手系。但 Unity、DirectX 等引擎默认左手系:用同样的公式,叉积指向反过来。接数据时先确认两边的手性,不一致就要换算,否则法向量、旋转轴、力矩的符号会全部反号。
Every frame in this course is right-handed. Engines such as Unity and DirectX default to left-handed frames: the same formula gives a cross product pointing the other way. Check the handedness on both sides when moving data between systems and convert if they differ, or the signs of normals, rotation axes and torques will all flip.
\((\mathbf a\times\mathbf b)\times\mathbf c\) 与 \(\mathbf a\times(\mathbf b\times\mathbf c)\) 一般不相等(见"再看数学"里的反例)。连续叉乘(例如 \(\boldsymbol\omega\times(\boldsymbol\omega\times\mathbf r)\) 向心加速度)要保留括号,化简用 BAC-CAB。
\((\mathbf a\times\mathbf b)\times\mathbf c\) and \(\mathbf a\times(\mathbf b\times\mathbf c)\) are generally different (see the counterexample in "The math"). Keep the brackets in repeated cross products (for example the centripetal term \(\boldsymbol\omega\times(\boldsymbol\omega\times\mathbf r)\)) and simplify with BAC-CAB.
9小练习Check yourself
10延伸阅读Further reading
- 3Blue1Brown, Essence of Linear Algebra — 第 10 章"叉积"与第 11 章"从线性变换看叉积"Ch. 10 "Cross products" and Ch. 11 "Cross products in the light of linear transformations"
- G. Strang, Introduction to Linear Algebra, §5.3 — 叉积、面积与体积The cross product, areas and volumes
- K. Lynch & F. Park, Modern Robotics, §3.2.3 — 角速度与斜对称矩阵Angular velocities and the skew-symmetric matrix
- J. Solà, J. Deray & D. Atchuthan, "A micro Lie theory for state estimation in robotics", 2018 — hat 矩阵如何通向李代数how the hat matrix leads to the Lie algebra