1. 程式人生 > 其它 >python_四元數q轉旋轉矩陣R(已驗證)

python_四元數q轉旋轉矩陣R(已驗證)

技術標籤:python

方法1

使用公式:https://doc.rc-visard.com/latest/de/pose_formats.html?highlight=format

方法2

使用庫scipy中的方法 Rm = R.from_quat(Rq)

from scipy.spatial.transform import Rotation as R

Rq=[-0.35, 1.23e-06, 4.18e-08, 0.39]
Rm = R.from_quat(Rq)
rotation_matrix = Rm.as_matrix()
print('rotation:\n',rotation_matrix)

#結果:
rotation:
 [[ 1.00000000e+00 -3.25420248e-06  3.38725419e-06]
 [-3.01673707e-06  1.07793154e-01  9.94173343e-01]
 [-3.60036417e-06 -9.94173343e-01  1.07793154e-01]]

備註: SLAM十四講 第一版中公式(3.35)形式是對的,但R的下標和位置有誤, 在第二版中未再提及該公式