四元数与角轴、旋转矩阵、so(3)、SO(3) 的关系

四元数定义

q = [ s , υ ] T , s = q 0 ∈ R , υ = [ q 1 , q 2 , q 3 ] T ∈ R 3 \left.q=\left[\begin{matrix}{s,\upsilon}\\\end{matrix}\right.\right]^{\mathrm{T}},s=q_{0}\in\mathbb{R},\upsilon=\left[\begin{matrix}{q_{1}},q_{2},q_{3}\\\end{matrix}\right]^{\mathrm{T}}\in\mathbb{R}^{3} q=[s,υ]T,s=q0R,υ=[

### 对偶四元数变换矩阵关系 在计算机图形学和机器人学领域,对偶四元数提供了一种高效且无奇异性的方法来表示刚体运动,而变换矩阵则是另一种常用的表示方式。两者都可以用来描述物体的位置和姿态变化。 #### 描述能力对比 对偶四元数可以同时编码旋转和平移信息,这使得它特别适合于处理复杂的三维空间变换[^1]。相比之下,标准的四元数仅能表达旋转部分的信息;为了完整地定义一个刚体变换,则需额外引入平移向量。然而,通过采用7个参数(即4个实部加3个虚部),对偶四元数能够在单一结构内实现这一点,从而减少了计算复杂度并提高了数值稳定性。 对于变换矩阵而言,通常使用齐次坐标下的\(4\times4\)方阵形式来进行位置和方向的同时表述。尽管这种方法直观易懂,并且易于其他线性代数操作相结合,但在某些情况下可能会遇到所谓的“万向锁”问题——当两个重合时发生的自由度丢失现象。由于对偶四元数不存在这样的局限性,因此成为解决此类难题的理想选择之一[^2]。 #### 转换方法 ##### 从变换矩阵到对偶四元数 给定一个\(4\times4\)的标准SE(3)群中的变换矩阵\(\mathbf{T}\),其中包含了旋转矩阵\(\mathbf{R}\in SO(3)\)以及平移列向量\(\mathbf{t}=[tx,ty,tz]^T\): \[ \mathbf{T}= \begin{bmatrix} R_{11}&R_{12}&R_{13}& t_x\\ R_{21}&R_{22}&R_{23}& t_y \\ R_{31}&R_{32}&R_{33}& t_z \\ 0 & 0& 0& 1 \end{bmatrix}, \] 可以通过以下步骤将其转化为对应的对偶四元数\(\hat{\mathbf{q}}=\mathbf{q}_r+\epsilon\mathbf{q}_d,\quad (\epsilon^2=0)\): - 首先提取出旋转分量\(\mathbf{R}\), 并按照常规的方式转换成单位四元数\(\mathbf{q}_r=(w,x,y,z)^T\); - 接着利用公式\(\mathbf{q}_d = (0,-\frac{1}{2}(Rx+t))\) 计算得到平移分量\(\mathbf{q}_d\) ,这里 \(x=[tx, ty, tz]\). 最终形成的对偶四元数就是所求的结果。 ```python import numpy as np def matrix_to_dual_quaternion(T): """ Convert a transformation matrix to dual quaternion. Parameters: T : array_like A 4x4 homogeneous transform matrix Returns: tuple of two arrays representing the real and dual parts of the quaternion respectively """ # Extract rotation sub-matrix from T R = T[:3,:3] # Compute regular quaternion corresponding to this rotation angle_axis = cv2.Rodrigues(R)[0].flatten() theta = np.linalg.norm(angle_axis) if abs(theta)<np.finfo(float).eps*3: qr = [1., 0., 0., 0.] else: axis = angle_axis / theta s = math.sin(theta/2.) c = math.cos(theta/2.) qr = [c,s * axis[0],s * axis[1],s * axis[2]] # Calculate translation part using formula q_d=-0.5*(cross(q_r,v)+v) v = T[:-1,-1:] cross_product_matrix = lambda vec: [[0 ,-vec[2][0], vec[1][0]], [vec[2][0], 0 , -vec[0][0]], [-vec[1][0], vec[0][0], 0 ]] C = np.array(cross_product_matrix([qr[1]*2*s/c, qr[2]*2*s/c, qr[3]*2*s/c])) qd = (-0.5)*(C.dot(v)+v) return qr,qd.flatten().tolist() ``` ##### 从对偶四元数到变换矩阵 相反的过程也相对简单明了。假设有一个已知的对偶四元数\(\hat{\mathbf{q}}=\mathbf{q}_r+\epsilon\mathbf{q}_d\),那么重建相应的\(4×4\)变换矩阵可通过如下方式进行: - 将纯旋转成分\(\mathbf{q}_r\)转回至\(3×3\)正交矩阵\(\mathbf{R}\); - 使用先前提到的方法由\(\mathbf{q}_d\)恢复出平移矢量\(\mathbf{t}\); 最后组合起来形成完整的变换矩阵\(\mathbf{T}\)。 ```python from scipy.spatial.transform import Rotation as Rot def dual_quaternion_to_matrix(dual_q): """ Converts a dual quaternion into its equivalent SE(3) homogenous transformation matrix Args: dual_q(tuple): Tuple containing lists or ndarrays with length four each for both quaternions Returns: ndarray: The resulting 4 by 4 Homogeneous Transformation Matrix """ qr,dq = map(np.asarray,dual_q) r = Rot.from_quat(qr[[1,2,3,0]]).as_matrix() # Note that SciPy expects w last not first! t = dq[1:] * 2.0 - np.cross(qr[1:],dq[1:]) H = np.eye(4) H[:3,:3]=r;H[:3,3]=t; return H ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

<lumen>

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值