python将四元数变换为旋转矩阵

import numpy as np
from autolab_core import RigidTransform

# 写上用四元数表示的orientation和xyz表示的position
orientation = {'y': -0.6971278819736084, 'x': -0.716556549511624, 'z': -0.010016582945017661, 'w': 0.02142651612120239}
position = {'y': -0.26022684372145516, 'x': 0.6453529828252734, 'z': 1.179122068068349}

rotation_quaternion = np.asarray([orientation['w'], orientation['x'], orientation['y'], orientation['z']])
translation = np.asarray([position['x'], position['y'], position['z']])
# 这里用的是UC Berkeley的autolab_core,比较方便吧,当然可以自己写一个fuction来计算,计算公式在https://www.cnblogs.com/flyinggod/p/8144100.html
T_qua2rota = RigidTransform(rotation_quaternion, translation)

print(T_qua2rota)
 
# 以下是打印的结果
Tra: [ 0.64535298 -0.26022684  1.17912207]
     Rot: [[ 0.02782477  0.99949234 -0.01551915]
     [ 0.99863386 -0.02710724  0.0446723 ]
     [ 0.04422894 -0.01674094 -0.99888114]]
     Qtn: [-0.02142652  0.71655655  0.69712788  0.01001658]
     from unassigned to world

自己写的话

def quaternion_to_rotation_matrix(quat):
    q = quat.copy()
    n = np.dot(q, q)
    if n < np.finfo(q.dtype).eps:
        return np.identity(4)
    q = q * np.sqrt(2.0 / n)
    q = np.outer(q, q)
    rot_matrix = np.array(
        [[1.0 - q[2, 2] - q[3, 3], q[1, 2] + q[3, 0], q[1, 3] - q[2, 0], 0.0],
         [q[1, 2] - q[3, 0], 1.0 - q[1, 1] - q[3, 3], q[2, 3] + q[1, 0], 0.0],
         [q[1, 3] + q[2, 0], q[2, 3] - q[1, 0], 1.0 - q[1, 1] - q[2, 2], 0.0],
         [0.0, 0.0, 0.0, 1.0]],
        dtype=q.dtype)
    return rot_matrix

描述有两种方式,即XYZABC和XYZ+quaternion:
https://doc.rc-visard.com/latest/de/pose_formats.html?highlight=format

  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
根据引用\[1\]中给出的结果,abb欧拉角转为旋转矩阵的结果为: 0.2765 0.4914 0.8259 0.9076 -0.4159 -0.0564 0.3158 0.7652 -0.5610 根据引用\[2\]中提到的内容,不同的软件或库在将同一个四元数转换为旋转矩阵时,得到的旋转矩阵可能互为逆矩阵。所以,如果使用abb欧拉角转换为旋转矩阵,得到的结果可能与其他软件或库得到的结果不同。 如果使用pyquaternion包进行转换,根据引用\[3\]中给出的代码和结果,当输入矩阵不转置时,abb欧拉角转为四元数的结果为: \[0.5442 -0.5538 -0.4391 0.4521\] 当输入矩阵转置时,abb欧拉角转为四元数的结果为: \[0.5442 0.5538 0.4391 -0.4521\] 所以,根据不同的转换方法和软件/库的实现,abb欧拉角转为旋转矩阵的结果可能会有所不同。 #### 引用[.reference_title] - *1* [ABB机器人欧拉角与四元数的相互转化以及旋转矩阵的求法](https://blog.csdn.net/weixin_41496173/article/details/127098526)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [matlab和python里实现旋转矩阵四元数变换](https://blog.csdn.net/qq_31442381/article/details/105536978)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值