python將四元數(shù)變換為旋轉(zhuǎn)矩陣的實例
如下所示:
import numpy as np
from autolab_core import RigidTransform
# 寫上用四元數(shù)表示的orientation和xyz表示的position
orientation = {'y': -0.6971278819736084, 'x': -0.716556549511624, 'z': -0.010016582945017661, 'w': 0.02142651612120239}
position = {'y': -0.26022684372145516, 'x': 0.6453529828252734, 'z': 1.179122068068349}
rotation_quaternion = np.asarray([orientation['w'], orientation['x'], orientation['y'], orientation['z']])
translation = np.asarray([position['x'], position['y'], position['z']])
# 這里用的是UC Berkeley的autolab_core,比較方便吧,當(dāng)然可以自己寫一個fuction來計算,計算公式在https://www.cnblogs.com/flyinggod/p/8144100.html
T_qua2rota = RigidTransform(rotation_quaternion, translation)
print(T_qua2rota)
# 以下是打印的結(jié)果
Tra: [ 0.64535298 -0.26022684 1.17912207]
Rot: [[ 0.02782477 0.99949234 -0.01551915]
[ 0.99863386 -0.02710724 0.0446723 ]
[ 0.04422894 -0.01674094 -0.99888114]]
Qtn: [-0.02142652 0.71655655 0.69712788 0.01001658]
from unassigned to world
自己寫的話
def quaternion_to_rotation_matrix(quat):
q = quat.copy()
n = np.dot(q, q)
if n < np.finfo(q.dtype).eps:
return np.identity(4)
q = q * np.sqrt(2.0 / n)
q = np.outer(q, q)
rot_matrix = np.array(
[[1.0 - q[2, 2] - q[3, 3], q[1, 2] + q[3, 0], q[1, 3] - q[2, 0], 0.0],
[q[1, 2] - q[3, 0], 1.0 - q[1, 1] - q[3, 3], q[2, 3] + q[1, 0], 0.0],
[q[1, 3] + q[2, 0], q[2, 3] - q[1, 0], 1.0 - q[1, 1] - q[2, 2], 0.0],
[0.0, 0.0, 0.0, 1.0]],
dtype=q.dtype)
return rot_matrix
描述有兩種方式,即XYZABC和XYZ+quaternion:
https://doc.rc-visard.com/latest/de/pose_formats.html?highlight=format
以上這篇python將四元數(shù)變換為旋轉(zhuǎn)矩陣的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python利用xlwt/openpyxl/xlutils實現(xiàn)寫入Excel數(shù)據(jù)
這篇文章主要為大家詳細(xì)介紹了Python如何利用xlwt/openpyxl/xlutils這些第三方庫實現(xiàn)寫入Excel數(shù)據(jù)功能,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-11-11
python調(diào)用cmd命令時遇到的路徑空格問題和中文亂碼的解決
這篇文章主要介紹了python調(diào)用cmd命令時遇到的路徑空格問題和中文亂碼的解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-02-02
Pytorch使用VGG16模型進(jìn)行預(yù)測貓狗二分類實戰(zhàn)
VGG16是Visual Geometry Group的縮寫,它的名字來源于提出該網(wǎng)絡(luò)的實驗室,本文我們將使用PyTorch來實現(xiàn)VGG16網(wǎng)絡(luò),用于貓狗預(yù)測的二分類任務(wù),我們將對VGG16的網(wǎng)絡(luò)結(jié)構(gòu)進(jìn)行適當(dāng)?shù)男薷?以適應(yīng)我們的任務(wù),需要的朋友可以參考下2023-08-08
Python BeautifulSoup [解決方法] TypeError: list indices must be
這篇文章主要介紹了Python BeautifulSoup [解決方法] TypeError: list indices must be integers or slices, not str,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
Python微服務(wù)開發(fā)之使用FastAPI構(gòu)建高效API
微服務(wù)架構(gòu)在現(xiàn)代軟件開發(fā)中日益普及,它將復(fù)雜的應(yīng)用程序拆分成多個可獨立部署的小型服務(wù)。本文將介紹如何使用 Python 的 FastAPI 庫快速構(gòu)建和部署微服務(wù),感興趣的可以了解一下2023-05-05
django 連接數(shù)據(jù)庫 sqlite的例子
今天小編就為大家分享一篇django 連接數(shù)據(jù)庫 sqlite的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-08-08

