【发布时间】:2020-09-24 18:08:24
【问题描述】:
我将旋转矩阵分解为欧拉角(更具体地说,Tait-Bryan 角按照 x-y-z 的顺序,即首先围绕 x 轴旋转)并返回到旋转矩阵。我使用了 transforms3d python 库 (https://github.com/matthew-brett/transforms3d) 并遵循了本教程 www.gregslabaugh.net/publications/euler.pdf 两者都给出了相同的结果。
问题是重新组合的旋转矩阵与我开始使用的不匹配。
我正在使用的矩阵是由 openCV 中的“decomposeHomographyMat”函数创建的,所以我希望它是一个有效的旋转矩阵。也许这是一个特例? 矩阵是
三个角度是 [-1.8710997 , 0.04623301, -0.03679793]。如果我将它们转换回旋转矩阵,我会得到
其中 R_23 不能是舍入误差。
按照上面的论文,可以通过 asin(-R_31) 计算绕 y 轴 (beta) 的旋转。另一个有效的角度是 pi-asin(-R_31)。 绕 x 轴 (alpha) 的角度可以通过 atan2(R_32,R_33) 计算。我也可以通过 asin(R_32/cos(beta)) 或 acos(R_33/cos(beta)) 获得 alpha。如果我使用后两个方程,如果我使用 beta=pi-arcsin(-R_31),我只会得到与 alpha 相同的结果,这意味着 beta 只有一个有效的解决方案。 atan2(R_32,R_33) 给出的结果与两者不同。
无论如何,我的矩阵似乎有问题,或者我无法弄清楚为什么 disassambly 不起作用。
import numpy as np
def rot2eul(R):
beta = -np.arcsin(R[2,0])
alpha = np.arctan2(R[2,1]/np.cos(beta),R[2,2]/np.cos(beta))
gamma = np.arctan2(R[1,0]/np.cos(beta),R[0,0]/np.cos(beta))
return np.array((alpha, beta, gamma))
def eul2rot(theta) :
R = np.array([[np.cos(theta[1])*np.cos(theta[2]), np.sin(theta[0])*np.sin(theta[1])*np.cos(theta[2]) - np.sin(theta[2])*np.cos(theta[0]), np.sin(theta[1])*np.cos(theta[0])*np.cos(theta[2]) + np.sin(theta[0])*np.sin(theta[2])],
[np.sin(theta[2])*np.cos(theta[1]), np.sin(theta[0])*np.sin(theta[1])*np.sin(theta[2]) + np.cos(theta[0])*np.cos(theta[2]), np.sin(theta[1])*np.sin(theta[2])*np.cos(theta[0]) - np.sin(theta[0])*np.cos(theta[2])],
[-np.sin(theta[1]), np.sin(theta[0])*np.cos(theta[1]), np.cos(theta[0])*np.cos(theta[1])]])
return R
R = np.array([[ 0.9982552 , -0.03323557, -0.04880523],
[-0.03675031, 0.29723396, -0.95409716],
[-0.04621654, -0.95422606, -0.29549393]])
ang = rot2eul(R)
eul2rot(ang)
import transforms3d.euler as eul
ang = eul.mat2euler(R, axes='sxyz')
eul.euler2mat(ang[0], ang[1], ang[2], axes='sxyz')
【问题讨论】: