对Intel T265输出的旋转四元数进行坐标变换

问题描述

  • Intel T265会输出位置和角度(四元数)
  • 在进行坐标变换的时候(例如,将T265的x-y-z变换为x-z-(-y)), 位置很容易进行变换,但是四元数角度的变换非常confusing

解决方案

上述旋转的代码如下

def convert_quaternion(q1):
    """
    Converts a quaternion representing a rotation in the x-y-z coordinate system to a quaternion
    representing the same rotation in the x-z-(-y) coordinate system.

    Args:
    q1: (x, y, z, w) quaternion representing a rotation in the x-y-z coordinate system.

    Returns:
    q2: (x, y, z, w) quaternion representing the same rotation in the x-z-(-y) coordinate system.
    """

    # Define a rotation that swaps the y and z axes and inverts the y axis
    swap_yz = R.from_euler('yxz', [0, 90, 0], degrees=True)

    # Convert q1 to a rotation object
    r1 = R.from_quat(q1)

    # Apply the coordinate system transformation and convert back to a quaternion
    r2 = swap_yz * r1 * swap_yz.inv()
    q2 = r2.as_quat()

    return q2

其中,比较难以理解的是r2 = swap_yz * r1 * swap_yz.inv()

  • 这行代码的含义是:

    • 当要将一个旋转从一个坐标系转换到另一个坐标系时,需要按照以下步骤进行:
      • 将旋转应用于原始坐标系。
      • 将坐标系变换应用于结果。
      • 在这个例子中,已经有了 r1,它是在 x-y-z 坐标系中的一个旋转。现在想要在 x-z-(-y) 坐标系中表示相同的旋转。我们首先将坐标系变换(swap_yz)应用于 r1。这可以通过四元数乘法 swap_yz * r1 来完成。
  • 然而,现在我们得到的旋转是在变换后的坐标系中的。我们需要将其转换回原始坐标系,以便我们可- 以比较两个旋转。这就是为什么我们需要乘以 swap_yz.inv() 的原因。swap_yz.inv() 是 swap_yz 的逆,它表示了从 x-z-(-y) 坐标系回到 x-y-z 坐标系的变换。

  • 因此,r2 = swap_yz * r1 * swap_yz.inv() 这一行的意义是:

    • 将原始旋转 r1 变换到新的坐标系(swap_yz * r1)。
    • 将结果旋转从新的坐标系变换回原始坐标系(乘以 swap_yz.inv())。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

R.X. NLOS

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

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

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

打赏作者

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

抵扣说明:

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

余额充值