旋转矩阵
四足机器人控制算法学习笔记
参考宇树科技《四足机器人控制算法——建模、控制与实践》
刚体运动学
二维平面旋转矩阵
任意 ν \nu ν可以用一对标准正交基 ω ^ 1 \hat{\omega}_1 ω^1, ω ^ 2 \hat{\omega}_2 ω^2(单位向量)表示
ν \nu ν=a ω ^ 1 \hat{\omega}_1 ω^1+b ω ^ 2 \hat{\omega}_2 ω^2
同时,二维平面内坐标系不唯一,标准坐标基也不唯一
如图,三角件旋转了 θ \theta θ角度
可以定义两个坐标系{s}和{b}:其中{s}坐标系相对世界固定不动,{b}相对三角件固定不动
{s},{b}分别对应两个标准正交基:
{s}: x ^ s \hat{x}_s x^s, y ^ s \hat{y}_s y^s
{b}: x ^ b \hat{x}_b x^b, y ^ b \hat{y}_b y^b
点P在这两个坐标系中的坐标:
{s}:( x s x_s xs , y s y_s ys )
{b}:( x b x_b xb , y b y_b yb )
因为点P相对{b}坐标系不动所以坐标始终为( x b x_b xb , y b y_b yb )
如何在已知( x b x_b xb , y b y_b yb )和 θ \theta θ 的情况下,计算点P在{s}坐标系中的坐标( x s x_s xs , y s y_s ys )呢?
可以先分别使用在这两个坐标系下的标准正交基描述向量 O P ⃗ \vec{OP} OP
O P ⃗ \vec{OP} OP= x s x_s xs ⋅ \cdot ⋅ x ^ s \hat{x}_s x^s + y s y_s ys ⋅ \cdot ⋅ y ^ s \hat{y}_s y^s = x b x_b xb ⋅ \cdot ⋅ x ^ b \hat{x}_b x^b+ y b y_b yb ⋅ \cdot ⋅ y ^ b \hat{y}_b y^b
转换成向量点乘的形式:
O P ⃗ \vec{OP} OP=[ x ^ s \hat{x}_s x^s y ^ s \hat{y}_s y^s ] ⋅ \cdot ⋅ [ x s y s ] \begin{bmatrix} x_s \\ y_s \end{bmatrix} [xsys] =[ x ^ b \hat{x}_b x^b y ^ b \hat{y}_b y^b ] ⋅ \cdot ⋅ [ x b y b ] \begin{bmatrix} x_b \\ y_b \end{bmatrix} [xbyb]
对于坐标系{s} 因为[ x ^ s \hat{x}_s x^s y ^ s \hat{y}_s y^s ]为单位矩阵
所以 O P ⃗ \vec{OP} OP= [ x s y s ] \begin{bmatrix} x_s \\ y_s \end{bmatrix} [xsys] =[ x ^ b \hat{x}_b x^b y ^ b \hat{y}_b y^b ] ⋅ \cdot ⋅ [ x b y b ] \begin{bmatrix} x_b \\ y_b \end{bmatrix} [xbyb] = R s b {{R}_s}_b Rsb ⋅ \cdot ⋅ [ x b y b ] \begin{bmatrix} x_b \\ y_b \end{bmatrix} [xbyb]
其中令[ x ^ b \hat{x}_b x^b y ^ b \hat{y}_b y^b ]为 R s b {{R}_s}_b Rsb就是旋转矩阵
由此可见,通过左乘 R s b {{R}_s}_b Rsb ,实现了{b}中坐标到{s}坐标的变换
只需计算旋转矩阵 R s b {{R}_s}_b Rsb 便可计算出点P在{s}中的坐标
R s b {{R}_s}_b Rsb =[ x ^ b \hat{x}_b x^b y ^ b \hat{y}_b y^b ]
其中{b}中标准坐标基在{s}中表示为 x ^ b \hat{x}_b x^b = [ cos θ sin θ ] \begin{bmatrix} \cos\theta \\ \sin\theta \end{bmatrix} [cosθsinθ] y ^ b \hat{y}_b y^b = [ − s i n θ cos θ ] \begin{bmatrix} -sin\theta \\ \cos\theta \end{bmatrix} [−sinθcosθ]
所以 R s b {{R}_s}_b Rsb = [ cos θ − s i n θ sin θ c o s θ ] \begin{bmatrix} \cos\theta&-sin\theta \\ \sin\theta&cos\theta \end{bmatrix} [cosθsinθ−sinθcosθ]
最终可以得出== O P ⃗ \vec{OP} OP = R s b {{R}_s}_b Rsb ⋅ \cdot ⋅ [ x b y b ] \begin{bmatrix} x_b \\ y_b \end{bmatrix} [xbyb] = [ cos θ − s i n θ sin θ c o s θ ] \begin{bmatrix} \cos\theta&-sin\theta \\ \sin\theta&cos\theta \end{bmatrix} [cosθsinθ−sinθcosθ] ⋅ \cdot ⋅ [ x b y b ] \begin{bmatrix} x_b \\ y_b \end{bmatrix} [xbyb]==
由此可见,旋转矩阵其实就是坐标变换
三维空间旋转矩阵
同理可推广至三维空间:
二维: R s b {{R}_s}_b Rsb =[ x ^ b \hat{x}_b x^b y ^ b \hat{y}_b y^b ]
三维: R s b {{R}_s}_b Rsb =[ x ^ b \hat{x}_b x^b y ^ b \hat{y}_b y^b z ^ b \hat{z}_b z^b]
要求计算点P在{s}坐标系中的坐标( x s x_s xs , y s y_s ys, z s z_s zs ),就是求旋转矩阵 R s b {{R}_s}_b Rsb
以右手系为例,旋转正方向满足右手定则
以关于x轴旋转为例:
x ^ ′ \hat{x}' x^′ = [ 1 0 0 ] \begin{bmatrix} 1 \\0 \\0 \end{bmatrix} 100 y ^ ’ \hat{y}’ y^’= [ 0 cos θ s i n θ ] \begin{bmatrix} 0 \\\cos\theta \\sin\theta \end{bmatrix} 0cosθsinθ z ^ ’ \hat{z}’ z^’= [ 1 − s i n θ c o s θ ] \begin{bmatrix} 1 \\-sin\theta \\cos\theta \end{bmatrix} 1−sinθcosθ
R x {R_x} Rx ( θ \theta θ ) =[ x ′ ^ \hat{x'} x′^ y ^ ′ \hat{y}' y^′ z ^ ′ \hat{z}' z^′]= [ 1 0 0 0 cos θ − s i n θ 0 sin θ c o s θ ] \begin{bmatrix} 1&0&0 \\0&\cos\theta&-sin\theta \\ 0&\sin\theta&cos\theta \end{bmatrix} 1000cosθsinθ0−sinθcosθ
同理可得:
R y {R_y} Ry ( θ \theta θ ) = [ s i n θ 0 s i n θ 0 1 0 − c o s θ 0 c o s θ ] \begin{bmatrix} sin\theta&0&sin\theta \\0&1&0 \\ -cos\theta&0&cos\theta \end{bmatrix} sinθ0−cosθ010sinθ0cosθ R z {R_z} Rz ( θ \theta θ ) = [ c o s θ − s i n θ 0 s i n θ c o s θ 0 0 0 1 ] \begin{bmatrix} cos\theta&-sin\theta&0 \\sin\theta&cos\theta&0 \\ 0&0&1 \end{bmatrix} cosθsinθ0−sinθcosθ0001
三维空间中旋转矩阵的性质
-
正交性
旋转矩阵的每个列向量都是一组标准正交基,因此 R s b {R_s}_b Rsb 是一个正交矩阵
-
行列式
在右手系下,三维正交矩阵行列式恒等于1
矩阵行列式的几何意义:矩阵行列式是三维空间中立方体体积的缩放比
三维正交矩阵行列式恒等于1 =>旋转矩阵不会缩放物体
-
可逆性
存在逆矩阵且旋转矩阵的逆矩阵等于转置矩阵
-
封闭性
旋转矩阵 ⋅ \cdot ⋅ 旋转矩阵=旋转矩阵
遵循下标消去原则:
旋转矩阵相乘: R s a {R_s}_a Rsa ⋅ \cdot ⋅ R a b {R_a}_b Rab = R s b {R_s}_b Rsb
矩阵与坐标向量相乘: R s b {R_s}_b Rsb ⋅ \cdot ⋅ p b p_b pb= p s p_s ps
-
满足结合律但不满足交换律
( R a b {R_a}_b Rab ⋅ \cdot ⋅ R b c {R_b}_c Rbc ) ⋅ \cdot ⋅ R c d {R_c}_d Rcd = R a b {R_a}_b Rab ⋅ \cdot ⋅ ( R b c {R_b}_c Rbc ⋅ \cdot ⋅ R c d {R_c}_d Rcd )= R a d {R_a}_d Rad