MATLAB和python对四元数给出不同的答案

问题描述

我在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,z,w]

为什么四元数值[x,w]在MATLAB和python之间不匹配。

解决方法

PC不是有效的方向余弦(即旋转)矩阵。行列式应接近1,但实际上接近-1。将此PC馈入任何期望方向余弦矩阵的例程将不会产生正确的结果。您需要检查如何生成此PC矩阵并进行修复。我什至无法复制您的四元数。例如,

df1 <- structure(list(tree = c("C1T1","C1T1","C1T2","C1T2"),cookie = c("A","B","C","A","C"),age = c(113L,108L,97L,133L,110L,100L)),class = "data.frame",row.names = c(NA,-6L))