【发布时间】:2020-10-10 12:15:11
【问题描述】:
我在 MATLAB 中有一个旋转矩阵
PC=[0.4822 0.5070 0.7145
-0.4086 0.8516 -0.3285
0.7750 0.1336 -0.6177];
quat=rotm2quat(PC); %gives me
[0.3937, 0.8641, 0.0319, 0.3119] %which is [w,x,y,z]
python中的相同矩阵
from scipy.spatial.transform import Rotation as R
rot=[[0.4822 , 0.5070 , 0.7145],[-0.4086 , 0.8516 , -0.3285],[ 0.7750 , 0.1336 , -0.6177]]
r=R.from_dcm(rot)
print(r.as_quat()) # gives me following
[ 0.04920064 0.99356301 -0.09745128 -0.0302504 ] # which is [x,y,z,w]
为什么四元数值[x,y,z,w] 在 MATLAB 和 python 之间不匹配。
【问题讨论】:
-
我注意到您的 Matlab PC 不是矩阵,而是向量。这是设计使然吗?
-
我从 PCA 获得了 MATLAB PC(一些数据)。我认为 PCA 返回旋转矩阵。如果我从 eig() 计算特征向量,它会起作用。
-
我知道为什么会出现差异。 rotm2quat(PC) 的转换具有很高的机器精度。 PC 变量中有多少个浮点数,答案取决于它们。但好在quat2rotm(A)没有机器机器精度。
-
@Stefan:这是 MATLAB 语法中的 3x3 矩阵,而不是向量。你可能对 Python 语法感到困惑?
标签: python matlab quaternions