[英]MATLAB and python gives different answer for quaternion
我在 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 之间不匹配。
PC 不是有效的方向余弦(即旋转)矩阵。 行列式应该接近1,但实际上接近-1。 将此 PC 提供给任何需要方向余弦矩阵的例程都不会产生正确的结果。 您需要检查如何生成此 PC 矩阵并修复它。 我什至无法重现你的四元数。 例如,
>> PC=[0.4822 0.5070 0.7145
-0.4086 0.8516 -0.3285
0.7750 0.1336 -0.6177];
>> det(PC)
ans =
-1.0001 <-- bad
>> quat=rotm2quat(PC)
quat =
0.9427 0.2430 -0.1641 -0.1590
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.