SciPy旋转矩阵来自/作为欧拉角

ppcbkaq5  于 2022-11-23  发布在  其他
关注(0)|答案(1)|浏览(170)

我正在处理欧拉角和SciPy对它们的实现。我很难理解SciPy如何从欧拉初始化旋转矩阵,或者它如何将矩阵表示为欧拉,或者两者都有。通过阅读文档,我会假设一个调用
from_euler("ZYX", (yaw, pitch, roll))
等效于三个矩阵的乘法,每个矩阵从一个轴计算得出,但一个简单的测试会使此假设无效:

from scipy.spatial.transform import Rotation as R

def r1(roll, pitch, yaw):
    r = R.from_euler("ZYX", (yaw, pitch, roll), degrees=True)
    yaw, pitch, roll = r.as_euler("ZYX", degrees=True)
    print(f"r:{roll:5.1f} p:{pitch:5.1f} y:{yaw:5.1f}")

def r2(roll, pitch, yaw):
    r = R.from_euler("ZYX", (0, 0, roll), degrees=True) * \
        R.from_euler("ZYX", (0, pitch, 0), degrees=True) * \
        R.from_euler("ZYX", (yaw, 0, 0), degrees=True)
    yaw, pitch, roll = r.as_euler("ZYX", degrees=True)
    print(f"r:{roll:5.1f} p:{pitch:5.1f} y:{yaw:5.1f}")

r1(35, 25, 115)  # as expected: "r:  35.0 p: 25.0 y: 115.0"
r2(35, 25, 115)  # surprising:  "r:   5.5 p:-41.8 y: 120.9"

我将非常感谢任何指向文档的指针,这些文档可以进一步详细说明SciPy是做什么的,或者,对于其他人来说,我所缺少的关于旋转矩阵的显而易见的东西。

gmol1639

gmol16391#

也许可以试试:

from scipy.spatial.transform import Rotation as R

def r1(roll, pitch, yaw):
    r = R.from_euler("ZYX", (yaw, pitch, roll), degrees=True)
    yaw, pitch, roll = r.as_euler("ZYX", degrees=True)
    print(f"r:{roll:5.1f} p:{pitch:5.1f} y:{yaw:5.1f}")

def r2(roll, pitch, yaw):
    r = R.from_euler("ZYX", (0, 0, roll), degrees=True) * \
        R.from_euler("ZYX", (0, pitch, 0), degrees=True) * \
        R.from_euler("ZYX", (yaw, 0, 0), degrees=True)
    yaw, pitch, roll = r.as_euler("ZYX", degrees=True)
    print(f"r:{roll:5.1f} p:{pitch:5.1f} y:{yaw:5.1f}")

# solution
def r3(roll, pitch, yaw):
    r = R.from_euler("ZYX", (yaw, 0, 0), degrees=True) * \
        R.from_euler("ZYX", (0, pitch, 0), degrees=True) * \
        R.from_euler("ZYX", (0, 0, roll), degrees=True)
    yaw, pitch, roll = r.as_euler("ZYX", degrees=True)
    print(f"r:{roll:5.1f} p:{pitch:5.1f} y:{yaw:5.1f}")

r1(35, 25, 115)  # as expected: "r:  35.0 p: 25.0 y: 115.0"
r2(35, 25, 115)  # surprising:  "r:   5.5 p:-41.8 y: 120.9"
r3(35, 25, 115)  # as expected: "r:  35.0 p: 25.0 y: 115.0"

相关问题